0% found this document useful (0 votes)
3 views

_Abdul_Moiz_Computer_Programming_Assignment#2

This document outlines an assignment for a Computer Programming course at Bahria University, Lahore Campus, focusing on creating a program to add or subtract two fractions. Students are instructed to solve the assignment independently and submit it by the deadline of October 30, 2023. The assignment includes specific coding requirements and a sample output format.

Uploaded by

chaudarysaad6009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

_Abdul_Moiz_Computer_Programming_Assignment#2

This document outlines an assignment for a Computer Programming course at Bahria University, Lahore Campus, focusing on creating a program to add or subtract two fractions. Students are instructed to solve the assignment independently and submit it by the deadline of October 30, 2023. The assignment includes specific coding requirements and a sample output format.

Uploaded by

chaudarysaad6009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Bahria University, Lahore Campus

Department of Computer Science


Assignment 02

Course: Computer Programming Date: _______________


Course Code: CSC-113 Max Marks: 10
Faculty’s Name: Mr. Muhammad Sauood Deadline: 30th October 2023(11: 59 PM)

Name: Abdu Moiz Enroll No: 03-134232-002_ Section: BS-CS 1(A)

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**

Question 1 Marks: 5+10 = 15


If you have two fractions, a/b and c/d, their sum can be obtained from the formula

For example, 1/4 plus 2/3 is

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>

using namespace std;

int main(){

int a=0,b=0,c=0,d=0;

char i='/';

cout<<"enter first fraction:"<<endl;

cin>>a>>i>>b;

cout<<"enter second fraction:"<<endl;

cin>>c>>i>>d;

int oper=0;

cout<<"press 1 for addition.\n";

cout<<"press 2 for subtraction\n";

cin>>oper;

if(oper==1){

cout<<"**********CALCULATION**********"<<endl;

cout<<a<<" "<<c<<" "<<a<<"*"<<d<<"+"<<b<<"*"<<c<<"


"<<a*d<<"+"<<b*c<<" "<<a*d+b*c<<endl;

cout<<"---"<<" + "<<"---"<<" = "<<"-----------"<<" = "<<"-------"<<"="<<"----"<<endl;

cout<<b<<" "<<d<<" "<<b<<"*"<<d<<" "<<b*d<<"


"<<b*d<<endl<<endl;

cout<<"*******************************"<<endl;

cout<<" "<<a*d+b*c<<endl<<"Answer = --"<<endl<<" "<<b*d;

Page 3 of 6
Enrollment Number: ____________________________

else if(oper==2){

cout<<"**********CALCULATION**********"<<endl;

cout<<a<<" "<<c<<" "<<a<<"*"<<d<<"-"<<b<<"*"<<c<<"


"<<a*d<<"-"<<b*c<<" "<<a*d-b*c<<endl;

cout<<"---"<<" + "<<"---"<<" = "<<"-----------"<<" = "<<"-------"<<"="<<"----"<<endl;

cout<<b<<" "<<d<<" "<<b<<"*"<<d<<" "<<b*d<<"


"<<b*d<<endl<<endl;

cout<<"*******************************"<<endl;

cout<<" "<<a*d-b*c<<endl<<"Answer = --"<<endl<<" "<<b*d;

return 0;

}
Output:

Page 4 of 6
Enrollment Number: ____________________________

Page 5 of 6
Enrollment Number: ____________________________

Page 6 of 6

You might also like