Question

In: Computer Science

// Add the following functions: // 1. 'getRadius' asks the user to enter the radius of...

// Add the following functions:

// 1. 'getRadius' asks the user to enter the radius of a circle
// and returns the given value. (should return a double)

// 2. 'calcArea' takes the radius and returns the area of a circle.

// 3. 'printResults' void type function that should print the results to
// console.

// Your function needs to have a local variable called 'PI' which holds the
// value '3.14159'.

// The function call is provided, you just need to implement the
// function prototype and function definition.

#include <iostream>
using namespace std;

// TODO - write the prototypes here

int main()
{
double radius,
area;

// TODO - call 'getRadius' function and assign the
// returned value to radius.


area = calcArea(radius);

// TODO - move the following cout to the 'printResults' function
// and call that function here instead.

cout << "The area of your circle is " << area << " units squared."
<< endl;

return 0;
}

// TODO - write the functions here

Solutions

Expert Solution

Code:

#include <bits/stdc++.h>
using namespace std;

double getRadius()
{   double radius;
    cout<<"Enter the radius: ";
    cin>>radius;
    return radius;
}
double calcArea(double radius)
{
    double PI=3.14159;
    return PI*radius*radius;

}
void printResults(double area)
{
    cout<<"The area of your circle is "<<area<<" units squared."<<endl;
}

int main() {
double radius,area;
radius= getRadius();
area = calcArea(radius);
printResults(area);
return 0;
}

Output:


Related Solutions

Question 1. The following code asks the user to enter the password and check it with...
Question 1. The following code asks the user to enter the password and check it with the pre-defined password that stored in the system. If the entered password is correct, it will authenticate the user to log-in into the account, otherwise reject! Analyze the following code, how it works? Do you think this code is safe? Justify? Try to overwrite this code and report the outputs? Define any vulnerabilities in this code if exist? What we can do to make...
Write a program that does the following in order: 1. Asks the user to enter a...
Write a program that does the following in order: 1. Asks the user to enter a name 2. Asks the user to enter a number “gross income” 3. Asks the user to enter a number “state tax rate” 4. Calculates the “Federal Tax”, “FICA tax” and “State tax” 5. Calculates the “estimated tax” and round the value to 2 decimal places 6. Prints values for “name”, “gross income” and “estimated tax” The program should contain three additional variables to store...
Write a C program that does the following: 1) Asks the user to enter an integer...
Write a C program that does the following: 1) Asks the user to enter an integer N 2) Asks the user to enter three words with at least N letters and at most 20 letters 3) Prints the first N letters from the first word 4) Prints the last N letters from the second word 5) Prints all letters in the odd position in the third word Output: Please enter an integer N: 3 Please enter a word with at...
Using Python Write a program that does the following in order: 1.     Asks the user to enter...
Using Python Write a program that does the following in order: 1.     Asks the user to enter a name 2.     Asks the user to enter a number “gross income” 3.     Asks the user to enter a number “state tax rate” 4.     Calculates the “Federal Tax”, “FICA tax” and “State tax” 5.     Calculates the “estimated tax” and round the value to 2 decimal places 6.     Prints values for “name”, “gross income” and “estimated tax” The program should contain three additional variables to store the Federal tax, FICA...
Q1) Create a program that do the following: 1. Asks the user to enter n marks...
Q1) Create a program that do the following: 1. Asks the user to enter n marks for n students, read the marks and the names and store them in a double linked list. 2. Write a method to find the largest mark and print the name of the student having that mark 3. Write a method to print the content of the list (name, mark) 4. Write a method to search the list for a given mark and prints the...
Write a C++ program that asks the user to enter the monthly costs for the following...
Write a C++ program that asks the user to enter the monthly costs for the following expenses incurred from operating your automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and a projected total annual cost of these expenses. Label each cost. The labels should be left aligned and have a column width of 30 characters. The cost should be aligned right and displayed with two decimal places...
Write a program that asks the user to enter the monthly costs for the following expenses...
Write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: Loan payment Insurance Gas Oil Tires Maintenance Write a function that takes these six items as arguments and computes the total cost of these expenses. Write a main program that asks the user for these six items and calls your function. Print total monthly cost and the total annual cost for these expenses.
Write a program that asks the user to enter the monthly costs for the following expenses...
Write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. Using the following test data: 310.34 104.95 78.34 12.34 8.12 45.00 Your output should look like this: Enter the monthly loan payment amount: Enter the monthly cost of insurance:...
Write a Python program that asks the user to enter the monthly costs for the following...
Write a Python program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: Loan payment Insurance Gas Oil Tires Maintenance Write a function that takes these six items as arguments and computes the total cost of these expenses. Write a main program that asks the user for these six items and calls your function. Print total monthly cost and the total annual cost for these expenses. Your function should...
Write a program that asks the user to enter a number. Display the following pattern by...
Write a program that asks the user to enter a number. Display the following pattern by writing lines of asterisks. The first line will have one asterisk, the next two, and so on, with each line having one more asterisk than the previous line, up to the number entered by the user.For example, if the user enters 5, the output would be: * *   * *   *   * *   *   *   * *   *   *   *   * short codes please
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT