Beruflich Dokumente
Kultur Dokumente
20212223242526272829303132333
43536373839404142434445464748
Jamal Hannun-14194
49505152535455565758596061626
GENG106-Assignment3
36465666768697071727374757677
78798081828384858687888990919
29394959697989910010110210310
41051061071081091101111121131
14115116117118119120121122123
12412512612712812913013113213
31341351361371381391401411421
43144145146147148149150151152
15315415515615715815916016116
21631641651661671681691701711
72173174175176177178179180181
18218318418518618718818919019
11/27/2013
201300283
Qatar University
College of Engineering.
#include <iostream>
using namespace std;
void zero_small(int & num1, int & num2)
{
if (num1 == num2)
cout<< " Error, numbers are equal\n";
else if (num1<num2)
{
cout<<"\nThe 1st integer number is smaller\n";
num1=0;
}
else
{
cout<<"\nThe 2nd integer number is smaller\n";
num2=0;
}
}
//------------------------------------------------------------void main()
{
int num1,num2;
cout<<"Enter the 1st integer number : ";
cin>>num1;
cout<<"Enter the 2nd integer number : ";
cin>>num2;
zero_small(num1,num2);
cout<<" The 1st integer number : "<<num1<<endl;
cout<<" The 2nd integer number : "<<num2<<endl;
system("pause");
}
Qatar University
College of Engineering.
2) [15 points] Write a program that lets the user perform arithmetic operations
on two numbers. Your program must be menu driven, allowing the user to
select the operation (+, -, *, or /) and input the numbers. Furthermore, your
program must consist of following functions:
1. Function showChoice: This function shows the options to the user and
explains how to enter data.
2. Function add: This function accepts two number as arguments and returns
sum.
3. Function subtract: This function accepts two number as arguments and
returns their difference.
4. Function multiply: This function accepts two number as arguments and
returns product.
5. Function divide: This function accepts two number as arguments and
returns quotient.
#include <iostream>
#include <cstdlib>
int num1,num2,choice;
using namespace std;
int take_check_Choice()
{
bool flag;
do
{
flag = 0 ;
cout<<" choice : ";
cin>>choice;
return choice;
}
//-------------------------------------------------------------int showChoice()
{
cout<<" Choose one of the following operations to perform\n";
cout<<"1 : addition
\n";
cout<<"2 : subtraction
\n";
cout<<"3 : multiplication
\n";
cout<<"4 : division
\n";
cout<<"5 : Exit
\n";
//(*)
Qatar University
College of Engineering.
//-------------------------------------------------------------void input_numbers()
{
//user input for num1 and num2
cout<<"\nEnter the 1st number : ";
cin>>num1;
cout<<"Enter the 2nd number : ";
cin>>num2;
}
Qatar University
College of Engineering.
//-------------------------------------------------------------int main()
{
cout<<"Welcome to arithmetic operations calculator\n";
do{
switch (showChoice())
{
case 1 :
cout<<"\n
case 2 :
cout<<"\n
case 3 :
cout<<"\n
case 4 :
cout<<"\n
case 5 :
exit(0);
}
}while(choice != 5);
system("pause");
return 0;
}
<<addition()
<<"\n\n"; break;
<<"\n\n"; break;
<<"\n\n"; break;
<<multiplication()
<<"\n\n"; break;