Write a C++
Program Plan:
An inline function circleArea() is defines to calculate the area of circle.
Variable radiusValue is used to save the value of radius entered by user.
Program Description: Purpose of the program is to define an inline function circleArea() to calculate the area of circle. The formula used to calculate area of circle is =II×r2.
Explanation of Solution
Program: Following is C++ Program that prompt user to enter radius of circle calculates area of circle by calling inline function circleArea.
//include necessary header files #include <iostream> usingnamespace std; /*The inline function circleArea is defined which takes input argument radius and calculates the area of circle */ inlinedoublecircleArea( constdouble radius ) { // formula for Radius = pi * ( radius ^ 2 ) return (3.14) * radius * radius; } //start of main method intmain() { // Declare variables to store the value of radius doubleradiusValue; // Prompt user to enter the value of radius cout<<"\nEnter the radius of your circle: "; // read the value of radius from user cin>>radiusValue; // calculate the area of circle and finally display the result cout<<"Area of circle with radius "<<radiusValue<< " is "<<circleArea( radiusValue ) <<endl; }//end of main
Explanation:
The given C++ program calculates the area of circle using inline function.
- Import the essential header and initialize the main() function.
- Define inline function circleArea with radius as argument.
- Declare variable radiusValue for radius of the circle.
- Formula used to calculate the area of circle is =?×r2.
- Prompt user to enter the radius of circle.
- Calculate and finally display the output.
Sample Output:
Want to see more full solutions like this?
Chapter 15 Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
Starting Out with Python (3rd Edition)
C Programming Language
Absolute Java (6th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- C++ Toll roads have different fees at different times of the day and on weekends. Write a function CalcToll() that has three arguments: the current hour of time (int), whether the time is morning (bool), and whether the day is a weekend (bool). The function returns the correct toll fee (double), based on the chart below. Weekday Tolls Before 7:00 am ($1.15) 7:00 am to 9:59 am ($2.95) 10:00 am to 2:59 pm ($1.90) 3:00 pm to 7:59 pm ($3.95) Starting 8:00 pm ($1.40) Weekend Tolls Before 7:00 am ($1.05) 7:00 am to 7:59 pm ($2.15) Starting 8:00 pm ($1.10) Ex: The function calls below, with the given arguments, will return the following toll fees: CalcToll(8, true, false) returns 2.95CalcToll(1, false, false) returns 1.90CalcToll(3, false, true) returns 2.15CalcToll(5, true, true) returns 1.05 Your program should include the function main( ), which asks for and validates the proper user inputs to be passed to the CalcToll( ) function. The function main() also displays the toll fees based…arrow_forwardWrite a c++ program: Write a function named convertToLowestTerms that inputs two integer parameters by reference named numerator and denominator. The function should treat these variables as a fraction and reduce them to lowest terms. For example, if numerator is 20 and denominator is 60, then the function should change the variables to 1 and 3, respectively. This will require finding the greatest common divisor for the numerator and denominator then dividing both variables by that number. If the denominator is zero, the function should return false, otherwise the function should return true. Write a driver program that uses convertToLowestTerms to reduce and output several fractions.arrow_forwardwrite a c++ code in which : Q2: Write a function that, when you call it, displays a message telling how many times it has been called: “I have been called 3 times", for instance. Write a main() program that calls this function at least 10 times. HInt: use a global variable to store the countarrow_forward
- IN C programming Write a function that will take an integer as an argument and return the factorial of the integer. Then write another function that will take two integers as arguments and then return the ratio of the factorials of the first argument with the second one. You need to make two calls to the first function inside the second function to find the factorials of the numbers.arrow_forwardIn C++ Even if a problem does not directly tell you to use a function, you should aim to do so regardless. 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?arrow_forwardC++ is to be usedarrow_forward
- The function doit(a,b,c,d) is a function that multiplies the smallest of its integers arguments by 2. If more than one arguments are equal and are the smallest, they are multiplied by 2. For example given a=5,b=3,c=7,d=9, doit (a,b,c,d) changes b to 6. Write the code of the function doit and test it.arrow_forwardC++ Programming problem: Write a program, using a void function, that takes as input an integer and outputs two times the number if it is even; otherwise it outputs five times the number. Then, using a void function, write a program that takes as input two integer values, say n and m. The function returns the sum and average of all the numbers between n and m (inclusive).arrow_forwardUSE C++programming languagearrow_forward
- number 3 and 4 pls in c++arrow_forwardWrite a C++ function void rect (int& ar, int& per, int len, int wid)that computes the area ar and perimeter per of a rectangle with length len and width wid.Test it inside the main program that inputs the length and width of a rectangle and outputsits area and perimeter. Output the value in the main program, not in the procedure.arrow_forwardIn this lab, you complete a partially written C++ program that includes two functions that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a function that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another function that computes the product of all the whole numbers up to and including the entered number. The source code file provided for this lab includes the necessary variable declarations and the input statement. Comments are included in the file to help you write the remainder of the program. #include <iostream> #include <string> void sums(int); void products(int); using namespace std; int main() { double number; cout << "Enter a positive integer or 0 to quit: "; cin >> number; while(number != 0) { // Call sums function…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education