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

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...
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 program that: 1) asks the user to enter grades, a negative number is the...
write a program that: 1) asks the user to enter grades, a negative number is the signal to stop entering. (while loop) - add each grade to a list (do not add the negative number to the list) after the while loop to enter grades is finished: 2) use a for loop on the list to calculate the average of all numbers in the list 3) use a for loop on the list to find the largest number in the...
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Question : Write a C program that asks the user to enter an integer between 1...
Question : Write a C program that asks the user to enter an integer between 1 and 7 that represents a weekday number (1 = Sunday, 2 = Monday , …… , 6 = Friday , 7 = Saturday) and it prints the day (i.e., Sunday, Monday, …… , Friday or Saturday). The program continuously asks the user to enter a weekday number till the user responds by ‘N’. and give me an output please use printf and scanf #include...
1) Write Java application that asks the user to enter the cost of each apple and...
1) Write Java application that asks the user to enter the cost of each apple and number of apples bought. Application obtains the values from the user and prints the total cost of apples. 2) Write a java application that computes the cost of 135 apples, where the cost of each apple is $0.30. 3)Write a java application that prepares the Stationery List. Various entries in the table must be obtained from the user. Display the Stationary list in the...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
In Python write a program that asks the user to enter the monthly costs for the...
In Python 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. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT