This needs to be completed in C++ and be able to run in Visual Studio (I have 20
ID: 669093 • Letter: T
Question
This needs to be completed in C++ and be able to run in Visual Studio (I have 2012). The actual problem is below this paragraph. Can use loops, strings, arrays, and classes. PLEASE read through the entire problem to make sure that everything is included in the solution. I have asked this question multiple times and gotten an answer that was not close to correct, then received no response when I asked for clarification on something. PLEASE ask any questions before answering if you are unsure about ANYTHING. The program needs to allow the user to enter five Fraction objects, each consisting of a whole number, numerator, and denominator. 0 cannot be entered for the denominator of any fraction, and the program cannot continue until a non-zero denominator is entered. After everything has been entered, the program needs to display the user-entered fraction(s) as entered and converted to proper form (see below for example). Lastly, it needs to display the sum of all fractions (fractional form is fine) and arithmetic average of all the fractions:
You are developing a Fraction structure for Teacher’s Pet Software. The structure contains
three public data fields for whole number, numerator, and denominator. Using the
same structure, write a main()function that declares an array of five Fraction objects.
Prompt the user for values for each field of each Fraction. Do not allow the user to enter
a value of 0 for the denominator of any Fraction; for each Fraction, continue to prompt
the user for a denominator value until a non-zero value is entered. After all the objects
have been entered:
» Display the whole number, numerator, and denominator for each of the five Fraction
objects as entered.
» Next, display the five Fraction objects all converted to proper form—that is, if the user
entered a value such as 2 6/4, now display it as 3 1/2.
» Next, display the sum of all the Fractions and the arithmetic average of all the
Fractions.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
struct s
{
int fraction;
int numerator;
int denominator;
};
void main()
{
int i;
struct s b[5];
clrscr();
for(i=0;i<5;i++)
{
cout<<" Enter Fraction:";
cin>>b[i].fraction;
cout<<" Enter numerator:";
cin>>b[i].numerator;
cout<<" Enter denominator:";
cin>>b[i].denominator;
}
printf(" Entered details are:-");
for(i=0;i<5;i++)
{
cout<<" Fraction"<<b[i].fraction;
cout<<" Numerator"<<b[i].numerator;
cout<<" Denominator"<<b[i].denominator;
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.