Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3630588 • Letter: I

Question

If you have two fractions, a/b and c/d, their sum can be obtained from the formula:
a c a * d + b * c
--- + --- = -------------------
b d b * d
For example, 1/4 plus 2/3 is:
1 2 1 * 3 + 4 * 2 3+8 11
--- + --- = ------------------- = ------- = -----
4 3 4 * 3 12 12
Write a program that prompts the user to enter two fractions and then display their sum in fractional form. The interaction with the user may look like this:
Enter first fraction: 1/2
Enter second fraction: 2/5
sum = 9/10
You can take the advantage of the fact that the extraction operator (>>) can be chained to read in more than one quantity at once, for example:
int a, b;
char ch;
cin >> a>> ch >>b

Explanation / Answer

#include<iostream>

using std::cin;

using std::cout;

int main()

{  

int a,b,c,d;  

char ch;  

cout<<"Enter the first fraction ";  

cin>>a>>ch>>b;  

cout<<" ";  

cout<<a<<" / "<<b<<" ";  

cout<<"Enter the second fraction ";

cin>>c>>ch>>d;  

cout<<" ";  

cout<<c<<" / "<<d<<" ";  

cout<<" The Result = :"<<((a*d)+(c*b))<<"/"<<(b*d);

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote