USING C++ Write the complete code and perform 3 traces. Pick good test data. 16
ID: 3683959 • Letter: U
Question
USING C++
Write the complete code and perform 3 traces. Pick good test data.
16 Design an algorithm that will prompt for, receive, and total a collection of payroll amounts entered from the user until a sentinel amount of 999 is entered. After the sentinel has been entered, display the total payroll amount to the screen.
17. Design an algorithm that will read a series of integers from the user. The first integer is special, as it indicates how many integers will follow. Your algorithm is to calculate and print the sum and average of the integers, excluding the first integer and display these values to the screen.
18. Design an algorithm that will prompt for and receive the measurement for the diameter of a circle and calculate and display the area and circumference of the circle. Your program is to continue processing until the sentinel of 9999 is entered.
Explanation / Answer
#include <iostream>
using namespace std;
void calculateSumAvg()
{
int total=0,n,no[10];
cout<<"Enter integrs: ";
cin>>n;
for(int i=0;i<n;i++)
{
cin>>no[i];
total+=no[i];
}
cout<<"Ttal:"<<total<<endl;
cout<<"Avg:"<<total/(n)<<endl;
}
void calculatePayroll()
{
int total=0,n,flag=0;
cout<<"Enter payroll amount: "<<endl;
while(flag==0)
{
cin>>n;
if(n!=9999)
total+=n;
else
flag=1;
}
cout<<"Ttal:"<<total<<endl;
}
void calculateAreaPerimeterCircle()
{
int n,flag=0;
while(flag==0)
{
cout<<"Enter radius of circle: ";
cin>>n;
if(n!=9999)
{
cout<<"Area of circle: "<< (22*n*n)/7<<endl;
cout<<"Circumference of circle: "<<(2*22*n)/7<<endl;
}
else
flag=1;
}
}
int main()
{
calculateSumAvg();
calculatePayroll();
calculateAreaPerimeterCircle();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.