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)
- Write a function that displays a solid square of“*” whose side is specified in integer parameter side in C languagearrow_forwardwrite a c++ program in which function drawLine(int x, int y) in the above code. this function should return length of lines in main i.e subtracting y from x.arrow_forwardWrite a program in python with a function hello(firstname, lastname), which, for example, if called with hello('James', 'Don'), would print two lines: Hello James Don Hello Don, James Use the function in a program where you ask the user for first and last name and then call the function.arrow_forward
- Write a program in c++ to print the circumference and area of a circle of radius entered by user by defining your own function.arrow_forwardWrite a program in C that will find the maximum number from 3 float type numbers. You have to use the function getMax which will take 3 pointer variables and return the maximum number.arrow_forwardWrite a program in Python, C++, or C that gets an integer from the user, prints out that value, then passes that value to a function, that doubles the number and returns back out the doubled number back to the main function and prints out that value to the screen.arrow_forward
- Write a C++ function that accepts a double typed number and return back the fractional part of the number. For example, if the number is 789.123, the number 0.123 should be returned.arrow_forwardWrite a function fune/2 which has two arguments and returns true, if the two arguments are equal, and false, otherwise. For example, fune (2, two)==false.arrow_forwardWrite a function that receives marks received by a student in 3 subjects and returns the average and percentage of these marks. Call this function from main( ) and print the results in main( ). In c languagearrow_forward
- • Write a function for a double function that will accept either two or three parameters of type double. • If it only receives two parameters, then it will return the average of the two numbers. • If it receives three parameters, then it will return the average of the largest number and the smallest number. • Write a complete C++ program to show the use of this function.arrow_forwardWrite a python program that uses a user-defined function that accepts name and gender (as M for Male, F for Female) and prefixes Mr/Ms on the basis of the gender.arrow_forwardIn c++, write a function that takes a nonnegative integer and returns the sum of its digits. For example, 23 its sum is 5, 524 its sum is 11.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