_Abdul_Moiz_Computer_Programming_Assignment#2
_Abdul_Moiz_Computer_Programming_Assignment#2
Instructions:
1) Understanding of question is a part of the assignment.
2) Solve the assignment with full honesty. Leave the question if not clear to you, or you are not able to
solve it, we will discuss it in the class for better understanding.
3) Try to think of a solution of your own. If you will keep on searching solutions on Google, it will not
make your problem-solving ability strong. This assignment is to sharp your mind a bit or making you
able to solve/think of a solution for any problem.
4) Copied assignments (from each other) will be awarded with ZERO.
5) Assignment is to be submitted both in soft form on LMS and in hard form (Print outs) till the deadline
mentioned above.
**Provide solution of each task and screenshot of output (full screen screenshot) at the end of that task**
Write a program that encourages the user to enter two fractions, and then displays a menu
with two choices (1) Press 1 for their sum and (2) Press 2 for their subtraction in fractional
form. (You don’t need to reduce it to lowest terms.) The interaction with the user might look
like this:
Enter first fraction: 1 / 2
Enter second fraction: 2 / 5
Press 1 for SUM
Press 2 for SUBTRACTION
Enter your choice: 1
Sum = 9 / 10
Enrollment Number: ____________________________
You can take advantage of the fact that the extraction operator (>>) can be chained to read in
more than one quantity at once:
e.g. cin >> a >> dummychar >> b;
Display the Complete calculations and Output using manipulator functions as follows:
Page 2 of 6
Enrollment Number: ____________________________
Hint: Use if/else, cout/cin statements and arithmetic operators only
Code:
#include<iostream>
int main(){
int a=0,b=0,c=0,d=0;
char i='/';
cin>>a>>i>>b;
cin>>c>>i>>d;
int oper=0;
cin>>oper;
if(oper==1){
cout<<"**********CALCULATION**********"<<endl;
cout<<"*******************************"<<endl;
Page 3 of 6
Enrollment Number: ____________________________
else if(oper==2){
cout<<"**********CALCULATION**********"<<endl;
cout<<"*******************************"<<endl;
return 0;
}
Output:
Page 4 of 6
Enrollment Number: ____________________________
Page 5 of 6
Enrollment Number: ____________________________
Page 6 of 6