Question
YOU CAN IGNORE THIS QUESTION, APOLOGIZE'S TO ALL For C++ I'm trying to become more comfortable with using functions in C++. I've tried doing a
YOU CAN IGNORE THIS QUESTION, APOLOGIZE'S TO ALL
For C++
I'm trying to become more comfortable with using functions in C++. I've tried doing a bit of research on my own on this particular subject and I chose to try and create a program that uses one Function to enter two fractions, then take these fractions in a second function to add them together, then in a third function divide them. Then from there in a fourth function display the fraction in simplified form. To simplify this function would be called within the display function. I understand mathmatically how to add, divide, and simplify fractions, but I cannot seem to figure out how to convert what I know into C++ code. If at all possible I would greatly appreciate aid. Below is the code outlined that I already have. I would like to keep the code using just functions, not classes or structs. Thanks in advance.
#include
using namespace std;
//Function Prototypes void greetings(); void goodbyes(); int menuOptions(int & menu); void enterFractions(int numerator, int denominator); void displayFractions(); void addFractions(); void divideFractions(); void simplifyFractions();
int main() { int menu; int numeratorOne, numeratorTwo, denominatorOne, denominatorTwo;
greetings();
do { menu = menuOptions(menu);
switch(menu) { case 1: { inputFractions(numeratorOne, denominatorOne); inputFractions(numeratorTwo, denominatorTwo);
break; } case 2: { addFractions();
break; } case 3: { divideFractions();
break; } case 4: { simplifyFractions();
break; } case 5: { cout<<"Fraction program complete."< cout<<" "<
break; } } } while (!menu == 5); return 0; }
//Function Definitions
void greetings()
{
cout<<"Welcome to the Moe fraction solver!"<
cout<<" "<
return;
}
void goodbyes()
{
cout<<"Congrats! You used the program, have a good day."<
cout<<" "<
return;
}
int menuOptions(int & menu)
{
cout<<"Choose one of the following menu options: "<
cout<<" "<
cout<<"Enter 1 to input fractions."<
cout<<"Enter 2 to add fractions."<
cout<<"Enter 3 to divide fractions."<
cout<<"Enter 4 to display the simplified fractions."<
cout<<"Enter 5 to quit."<
cout<<" "<
return menu;
}
void enterFractions(int numerator, int denominator)
{
int numerator;
int denominator;
cout<<"Enter the numerator: "<
cin>>numerator;
cout<<"Enter the denominator: "<
cout<<" "<
return;
}
void displayFractions()
{
simplifyFractions(newNum, newDenom);
cout<<"The simplified fraction solution is: "<
cout<
return;
}
void addFractions()
{
int newDenom, newNum;
newDenom = denominatorOne * denominatorTwo;
newNum = (numeratorOne * denominatorTwo) + (numeratorTwo * denominatorOne);
return;
}
void divideFractions()
{
int newNum;
int newDenom;
newNum = numeratorOne * denominatorTwo;
newDenom = denominatorOne * numeratorTwo;
return;
}
void simplifyFractions()
{
return;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started