Write the three separate C++ code that compiles correctly and is in different cp
ID: 3603119 • Letter: W
Question
Write the three separate C++ code that compiles correctly and is in different cpp files. Sorry, only have one question left to post, so I'm hoping to get help in one try.
One, for a function that receives an integer passed to it. The function, named halveNumber)(), should divide the integer by 2, then return the result (which may contain a decimal place).
Two, for a function that prompts the user to enter a character, then stores the user's response in a char variable. The function should return the character entered by the user. (The function will not have any actual arguments passed to it.) Name the function getChar().
Three, for a function that receives four integers. The function should calculate the average of the four integers, then return the result (which may contain a decimal place). Name the function calcAverage().
Explanation / Answer
first for halveNumber()
---------------------------------------------------------------------------
double halveNumber( int n ){
return n/2; // returning half of the number
}
---------------------------------------------------------------------------------
second getChar()
----------------------------------------------------------------------------------
char getChar(){
char c; // char variable to store charecter enter by user
std :: cout << "NEnter any charecter:"; // prompt user
std :: cin >> c; // read c
return c; // return charecter
}
----------------------------------------------------------------------------------------------
third calcAverage()
-----------------------------------------------------------------------------
calcAverage(int a, int b, int c, intd ){
return (a+b+c+d)/4; // calculating average of 4 nums passed
}
---------------------------------------------------------------------------------------------
/* i'm not able upload seperate files so i'm separately writing them. You can make them separately */
/* hope this helps */
/* if any queries please comment */
/* thank you */
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.