Create a new workspace in the folder cpp2<lastname> named - lesson4<lastname>
project/file names : functions4<lastname>
variable declarations
int num1, num2 ;
Four functions, one for each operation.
Sample output
Enter first number : 43 Enter second number : 23
What operation would you like to do? 1. addition 2. subtraction 3. multiplication 4. division
Your choice : 4 43/23=1.86957 Press any key to continue
H K N O P Sh Sm W L Not Listed
Last Name :
Email :
Select one of the following that describes when and why you are filling out this form: This assignment is in on time. This assignment is in on time, being resubmitted due to a failed submission (I have a copy of the original submission). This assignment is a corrected submission for half the missed credit. This assignment is one day late and will lose 15%. This assignment is more than one day late (half credit at best). This assignment is late because of an EXCUSED absence. This assignment is being resubmitted at the request of the teacher.
Complete the code below to generate the sample output above.
When the program is executed, after entering the two numbers the screen is cleared. That is done by doing a system call. system("cls) is defined in the stdlib.h header file.
When a choice is selected, the screen is cleared.
Complete the program by filling in the boxes.
#include<iostream.h> #include<stdlib.h>//System call - cls
int sum2Integers(int, int); int difference2Integers(int, int); int product2Integers(int, int); double divide2Integers(int, int);
void main() { int num1, num2, choice ;
cout<<"Enter first number : "; cin >> num1 ; cout <<"Enter second number : "; cin >> num2 ; system("cls");//clears the screen
cout <<"\nWhat operation would you like to do?"<<endl; cout <<"1. addition" << endl; cout <<"2. subtraction" << endl; cout <<"Your choice : " ; cin >> choice ; system("cls");
if(choice == 1) cout << num1 <<"+"<<num2 <<"="<< sum2Integers(num1, num2) << endl; if(choice == 2) if(choice == 3) cout << num1 <<"*"<<num2 <<"="<< product2Integers(num1, num2) << endl;
if( ) cout << num1 <<"/"<<num2 <<"="<< divide2Integers(num1, num2) << endl; }
int sum2Integers(int a, int b) { }
int difference2Integers(int a, int b) { }
int product2Integers(int a, int b) { }
double divide2Integers(int a, int b) { }
Updated: Wednesday, August 26, 2009 8:01 AM