C++ for Engineers and Scientists
C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
Question
Book Icon
Chapter 6, Problem 1PP

(a)

Program Plan Intro

To write a function that calculate the area of a circle. It call another function to get the radius of the circle. The circumference of the circle is given.

(a)

Expert Solution
Check Mark

Explanation of Solution

The name of the function is area().

This function has one parameters.

The parameter will accept afloating number to get the circumference (c) of a circle.

It call another function named radius () to get the radius (r) of the circle.

This function has one parameters.

The parameter will accept a floating number to get the circumference (c) of a circle.

The formula to calculate the radius of the circle is c / 2π.

The formula to calculate the area of the circle is πr2.

The function definition is:

float radius (float circumference)
{
//variable declaration
float r;

//calculate radius of the circle
    r = c / (2 * PI);

//return radius
return r;
}

//function to calculate area
void area (float c)
{
//variable declaration
float a, r;

//get the radius of the circle by calling the function
    r = radius(c);

//calculate area of the circle
    a = PI * pow (r, 2);

//display radius of the circle
cout<<"The radius of the circle is: "<< r <<endl;


//display area of the circle
cout<<"The area of the circle is: "<< a;
}

(b)

Program Plan Intro

Program Plan: 

  1. c,r,andavariables are used in the program.
  2. area () function is include in the program to calculate and display the area of the circle.
  3. radius () function is include in the program tocalculate and return the radius of the circle.

Program Description: The main purpose of the program is to prompt the user to enter the circumference of a circle to calculate the radius and the area of that circle. Include the function named area() in the main program. Call the function from the main () function with the value of the circumference of a circle.

(b)

Expert Solution
Check Mark

Explanation of Solution

Program:

//including essential header file
#include <iostream>
#include <cmath>

//define the value of PI (p)
#define PI 3.14

//using standard namespace
usingnamespace std;

//function to calculate radius
float radius (float circumference)
{
//variable declaration
float r;

//calculate radius of the circle
    r = circumference / (2 * PI);

//return radius
return r;
}

//function to calculate area
void area (float c)
{
//variable declaration
float a, r;

//get the radius of the circle by calling the function
    r = radius(c);

//calculate area of the circle
    a = PI * pow (r, 2);

//display radius of the circle
cout<<"The radius of the circle is: "<< r <<endl;

//display area of the circle
cout<<"The area of the circle is: "<< a;
}


//main function
intmain()
{
//variable declaration
float c;

//prompt the user to enter the circumference of the circle
cout<<"Enter the circumference of the circle: ";

//get the circumference from the user
cin>> c;

//call the function
    area (c);

return 0;
}

Explanation: In the above code, themain() function is to prompt the user to enter the circumference of a circle. The user-entered circumference is stored in the variable named c. Then the main()function call a function named area()with the value of the circumference to calculate and display the radius and area of the circle. The function named area()has one parameter named c. The parameter named c stores the circumference of a circle passed by the main () function. The function namedarea()called another function to get the radius of the circle. Call the function named radius () with the circumference of a circle. The function named radius ()Calculate the radius of the circle by the given formula and return the radius of the circle.The function namedarea() calculates the area of the circle by the given formula and display the radius and area of the circle.

Sample Output:

C++ for Engineers and Scientists, Chapter 6, Problem 1PP

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
(25 min) The following table shows the foreign exchange rates for a few currencies. Foreign Currency RM USD (D) 1 Dollar 4.16 GBP (P) 1 Pound 5.68 KRW (W) 1000 Won 3.51 JPY (Y) 100 Yen 3.69 Develop a complete C++ program that will prompt the user to enter the currency preferred and the amount required. The program should include a function with the following prototype: double CurrencyBuy(char, double): The first parameter in the function prototype is for the type of currency where the characters D, P, W and Y represent Dollar, Pound, Won and Yen respectively. The second parameter is the amount to be bought. This function CurrencyBuy should return, to the calling function, the payment to be paid in RM. A sample of the output is given as follows. Foreign Exchange Currency Country Code USD (D) GВР (Р) KRW (W) JPY (Y) Enter the country code: D Enter the amount to be bought: 300 Payment due is RM 1248.
(6 marks) 3. Using functions, develop a full C++ structured program that asks the user for his choics:1 or 2. If the choice is 1, then your program will convert the entered Fahrenh (F°) temperature to Celsius (C°). If the choice is 2, then your program will convert th entered Celsius (C°) temperature to Fahrenheit (F°). use the following functions: - getTemp: read the temperature from the user - getChoice: read the user choice: 1 or 2 NOTE: only 1 or 2 are allowed, if not, then give an error message warning for three times, then exit the whole program with a message if the problem persists. - convertToF: converts Celsius to Fahrenheit Fo= (9/5) * C° + 32 - convertToC: converts Fahrenheit to Celsius C°= (5/9) * (F° - 32)
(Wattan Corporation) is an Internet service provider that charges customers a flat rate of $7.99 for up to 10 hours of connection time. Additional hours or partial hours are charged at $1.99 each.Write a function charges that computes the total charge for a customer based on the number of hours of connection time used in a month. The function should also calculate the average cost per hour of the time used (rounded to the nearest 0.01), so use two output parameters to send back these results.You should write a second functionround_money that takes a real number as an input argument and returns as the function value the number rounded to two decimal places. Write a main function that takes data from an input file usage.txt and produces an output file charges.txt. The data file format is as follows:Line 1: current month and year as two integersOther lines: customer number (a five-digit number) and number of hours usedHere is a sample data file and the corresponding output file:Data file…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education