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_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_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 function that returns a decimal number from an octal number. The function header is as follows: int octal2Dec(const int& octalNumber) For example, octalNumber 345 is 229 (3 * 82 + 4 * 81 + 5 * 80 = 229). So, octal2Dec("345") returns 229. Write a test program that prompts the user to enter an octal number and displays its decimal equivalent value.arrow_forwardin c++pls i am doing it on replitarrow_forward
- Write a C++ program that calculates the base of a polygon (ie., b). The main function asks the user to input the value of the height (1.e, h), and area (1.e., A) of the polygon. Then the main function calls another function to calculate the base of the polygon (Name this function as a base_polygon). Finally, the main function displays the base of the polygon. Recall that :b = 25 hs barrow_forwardQuestion 2: Write a program that defines a function, RoundToThousands(number), to round a number x to the thousands position. For each value read (by the user), your program should print the original value and the number rounded to the nearest thousands. Hints 1- In the C Programming Language, the floor function returns the largest integer that is smaller than equal x (i.e.: rounds down the nearest integer). Example The floor of 1.600000 is i.000000 2- In order to round a number to the nearest tenth, look at the next place value to the right (the hundredths). If it's 4 or less, just remove all the digits to the right. If it's 5 or greater, add 1 to the digit in the tenths place, and then remove all the digits to the right. Еxample The round to the nearest tenth of 46.145325 is 46.100000 The round to the nearest tenth of 78.768014 is 78.800000 3- To round a number to the nearest hundredth, look at the next place value to the right (the thousandths). Same deal: If it's 4 or lcss, just…arrow_forwardCan you write in C++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