Hello! I need help to write a C++ program that will calculate the total and aver
ID: 3680587 • Letter: H
Question
Hello! I need help to write a C++ program that will calculate the total and average revenue of a company and test the following three functions:getData, calculateanddisplayutilizes several functions that.
Function 1
Write the void FUNCTION getData that asks the user to enter the revenue values of firstQ, secondQ, thirdQ, and forthQ. All variables are of type double. Then the function will pass these values back to main program as parameters. Make sure to identify, if any, call by reference variables.
Function 2
Write the FUNCTION calculatethat receives the four revenue values firstQ, secondQ, thirdQ, forthQ through the parameter list, calculates both the total value of revenue (by summing the four revenue values) and calculates the average revenue (by dividing the total revenue by 4.0). The function will then pass (send) the total back to main through the parameter list and returns the average to main. Make sure to identify, if any, call by reference variables.
Function 3
Write the void FUNCTIONdisplaythat receives the four revenue values, the total and average through the parameter list from main and displays the information to screen. Make sure to identify, if any, call by reference variables.
Explanation / Answer
#include<bits/stdc++.h>
using namespace std;
//Call by Reference for firstQ,secondQ,thirdQ,fourthQ
void getData(float &firstQ,float &secondQ,float &thirdQ,float &fourthQ)
{
cout<<"Enter the data for all the revenue";
cin>>firstQ>>secondQ>>thirdQ>>fourthQ;
}
//Call by refernce for Total
float calculate(float firstQ,float secondQ,float thirdQ,float fourthQ,float &total)
{
total=firstQ+secondQ+thirdQ+fourthQ;//Calculating Total
float average=total/4.0;//Calculation of average
return average;//Returning average to main function
}
//Displaying all the data
void display(float firstQ,float secondQ,float thirdQ,float fourthQ,float total,float avg)
{
cout<<"Revenue for firstQ : "<<firstQ<<endl;
cout<<"Revenue for secondQ : "<<secondQ<<endl;
cout<<"Revenue for thirdQ : "<<thirdQ<<endl;
cout<<"Revenue for fourthQ : "<<fourthQ<<endl;
cout<<"Total :"<<total<<endl;
cout<<"Average: "<<avg<<endl;
}
int main()
{
float firstQ,secondQ,thirdQ,fourthQ,total;
getData(firstQ,secondQ,thirdQ,fourthQ);//getData get four revenues
float avg=calculate(firstQ,secondQ,thirdQ,fourthQ,total);//Calculate total and return average
display(firstQ,secondQ,thirdQ,fourthQ,total,avg);//To display data
}
if you have any doubts please comment
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.