In the main function, define five variables of type int, named: first, second, third, fourth, and total. Also in the main function, define three variables of type double named: decimalOne, decimalTwo and decimalTotal
Write one function named getData which asks the user for the data and puts it in first, second, third, fourth, decimalOne, and decimalTwo. (You may copy your getData from problem I1 and make additions to manage fourth, decimalOne, and decimalTwo.) Write a function named computeTotal which can take two, or three int arguments and returns an int. Write another function, also named computeTotal which takes four int arguments and returns an int. Write another function, also named computeTotal which takes two double arguments and returns a double. Write a function named printAll which takes three arguments of type int. Write a function named printAll which takes four arguments of type int.
// I will ask the rest of the question in the comment
#include <iostream>
using namespace std;
//Write one function named getData which asks the user for the data and puts
//it in first, second, third, fourth, decimalOne, and decimalTwo.
void getData(int& first,int& second,int& third,int& fourth,double& decimalOne,double& decimalTwo){
cout<<"Enter first: ";
cin>>first;
cout<<"Enter fourth: ";
cin>>second;
cout<<"Enter third: ";
cin>>third;
cout<<"Enter fourth: ";
cin>>fourth;
cout<<"Enter decimalOne: ";
cin>>decimalOne;
cout<<"Enter decimalTwo: ";
cin>>decimalTwo;
}
//Write a function named computeTotal which can take two, or three int arguments and returns an int.
int computeTotal(int first,int second){
return first+second;
}
int computeTotal(int first,int second,int third){
return first+second+third;
}
//omputeTotal which takes four int arguments and returns an int.
int computeTotal(int first,int second,int third,int fourth){
return first+second+third+fourth;
}
//computeTotal which takes two double arguments and returns a double.
double computeTotal(double decimalOne,double decimalTwo){
return decimalOne+decimalTwo;
}
// a function named printAll which takes three arguments of type int.
void printAll(int first,int second,int third){
cout<<"first: "<<first<<"\n";
cout<<"second: "<<second<<"\n";
cout<<"third: "<<third<<"\n";
}
//Write a function named printAll which takes four arguments of type int.
void printAll(int first,int second,int third,int fourth){
cout<<"first: "<<first<<"\n";
cout<<"second: "<<second<<"\n";
cout<<"third: "<<third<<"\n";
cout<<"fourth: "<<fourth<<"\n";
}
int main() {
//define five variables of type int, named: first, second, third, fourth, and total.
int first, second, third, fourth, total;
//Also in the main function, define three variables of type double named: decimalOne, decimalTwo and decimalTotal
double decimalOne, decimalTwo,decimalTotal;
getData(first,second,third,fourth,decimalOne,decimalTwo);
cout<<"Total two int arguments: "<<computeTotal(first,second)<<"\n";
cout<<"Total three int arguments: "<<computeTotal(first,second,third)<<"\n";
cout<<"Total four int arguments: "<<computeTotal(first,second,third,fourth)<<"\n";
cout<<"Total two double arguments: "<<computeTotal(decimalOne,decimalTwo)<<"\n";
printAll(first,second,third);
printAll(first,second,third,fourth);
system("pause");
return 0;
}
Comments
Leave a comment