Question

This question is about C++! Honestly, I'm not sure what I am doing right or wrong....

This question is about C++!

Honestly, I'm not sure what I am doing right or wrong. Using just functions, nothing else, I am trying to create a program that uses nothing but functions to take in two fractions, add these fractions, divide these fractions, and then display the simplified fraction all from within a menu. I would very much appreciate any leads, aid, or description on what I've done right and wrong. Thanks!

#include <iostream>

using namespace std;

//Description: Function to greet user

//Pre: None

//Post: Displays the greeting to the program

void greetings();

//Description: Function to bid farewell to user

//Pre: None

//Post: Displays the sign off message for the program

void goodbyes();

//Description: Function to choose the menu options

//Pre: None

//Post: The selection given in the function is sent to the

// switch case for the menu

int menuOptions(int & menu);

//Description: Function to enter fractions

//Pre: None

//Post: Entering of the fractions to be used throughout the program

void enterFractions(int & numerator, int & denominator);

//Description: Function to display fractions

//Pre: Needs either the sum or the divison of the two fractions

//Post: Takes in the new fraction and displays

void displayFractions(int & newNum, int & newDenom);

//Description: Function to enter add the fractions

//Pre: Needs the input of the fractions

//Post: Creates the sum of the two fractions

void addFractions(int & numeratorOne, int & numeratorTwo,

int & denominatorOne, int & denominatorTwo, int & newNum, int & newDenom);

//Description: Function to divide the fractions

//Pre: Needs the input of the fractions

//Post: Creates the divison of the two fractions

void divideFractions(int & numeratorOne, int & numeratorTwo,

int & denominatorOne, int & denominatorTwo, int & newNum, int & newDenom);

//Description: Function to simplify the fractions

//Pre: Needs the un-simplified solution from addition or divison

//Post: Outputs the simplified fraction for the display function

void simplifyFractions(int & newNum, int & newDenom);

//Main Function, structure of the function calls and switch case

int main()

{

int menu;

int numeratorOne, numeratorTwo, denominatorOne, denominatorTwo;

int newNum, newDenom;

greetings();

do

{

menu = menuOptions(menu);

switch(menu)

{

case 1:

{

inputFractions(numeratorOne, denominatorOne);

inputFractions(numeratorTwo, denominatorTwo);

break;

}

case 2:

{

addFractions(numeratorOne, numeratorTwo, denominatorOne,

denominatorTwo);

break;

}

case 3:

{

divideFractions(numeratorOne, numeratorTwo, denominatorOne,

denominatorTwo);

break;

}

case 4:

{

displayFractions(newNum, newDenom);

break;

}

}

} while (!menu == 5);

return 0;

}

//Function descriptions

void greetings()

{

cout<<"Welcome to the Moe fraction solver!"<<endl;

cout<<" "<<endl;

return;

}

void goodbyes()

{

cout<<"Congrats! You used the program, have a good day."<<endl;

cout<<" "<<endl;

return;

}

int menuOptions(int & menu)

{

cout<<"Choose one of the following menu options: "<<endl;

cout<<" "<<endl;

cout<<"Enter 1 to input fractions."<<endl;

cout<<"Enter 2 to add fractions."<<endl;

cout<<"Enter 3 to divide fractions."<<endl;

cout<<"Enter 4 to display the simplified fractions."<<endl;

cout<<"Enter 5 to quit."<<endl;

cout<<" "<<endl;

return menu;

}

void enterFractions(int & numerator, int & denominator)

{

int numerator;

int denominator;

cout<<"Enter the numerator: "<<endl;

cin>>numerator;

cout<<"Enter the denominator: "<<endl;

cout<<" "<<endl;

return;

}

void displayFractions(int & newNum, int & newDenom)

{

simplifyFractions(newNum, newDenom);

cout<<"The simplified fraction solution is: "<<endl;

cout<<newNum<<"/"<<newDenom<<endl;

return;

}

void addFractions(int & numeratorOne, int & numeratorTwo,

int & denominatorOne, int & denominatorTwo, int & newNum, int & newDenom)

{

newDenom = denominatorOne * denominatorTwo;

newNum = (numeratorOne * denominatorTwo) + (numeratorTwo * denominatorOne);

return;

}

void divideFractions(int & numeratorOne, int & numeratorTwo,

int & denominatorOne, int & denominatorTwo, int & newNum, int & newDenom)

{

newNum = numeratorOne * denominatorTwo;

newDenom = denominatorOne * numeratorTwo;

return;

}

void simplifyFractions(int & newNum, int & newDenom)

{

for(int i = newNum * newDenom; i > 1; i--)

{

if((newNum % i) == 0 && (newDenom % i) == 0)

{

newNum = newNum / i;

newDenom = newDenom / i;

}

}

return;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// i have tried to make code work. if any problem u get, u can ask me. thank you.

//try this code now.

#include <iostream>

using namespace std;

void greetings();


void goodbyes();

int menuOptions();


void enterFractions();

void displayFractions(int & newNum, int & newDenom);

void addFractions(int & numeratorOne, int & numeratorTwo,

int & denominatorOne, int & denominatorTwo);

void divideFractions(int & numeratorOne, int & numeratorTwo,

int & denominatorOne, int & denominatorTwo);

void simplifyFractions(int & newNum, int & newDenom);

int main()

{

int menu;

int numeratorOne, numeratorTwo, denominatorOne, denominatorTwo;

int newNum, newDenom;

greetings();

do

{

menu = menuOptions();

switch(menu)

{

case 1:

{

enterFractions();

enterFractions();

break;

}

case 2:

{

addFractions(numeratorOne, numeratorTwo, denominatorOne,denominatorTwo);

break;

}

case 3:

{

divideFractions(numeratorOne, numeratorTwo, denominatorOne,denominatorTwo);

break;

}

case 4:

{

displayFractions(newNum, newDenom);

break;

}

}

} while (!menu == 5);

return 0;

}


void greetings()

{

cout<<"Welcome to the Moe fraction solver!"<<endl;

cout<<" "<<endl;

return;

}

void goodbyes()

{

cout<<"Congrats! You used the program, have a good day."<<endl;

cout<<" "<<endl;

return;

}

int menuOptions()

{
int s;

cout<<"Choose one of the following menu options: "<<endl;

cout<<" "<<endl;

cout<<"Enter 1 to input fractions."<<endl;

cout<<"Enter 2 to add fractions."<<endl;

cout<<"Enter 3 to divide fractions."<<endl;

cout<<"Enter 4 to display the simplified fractions."<<endl;

cout<<"Enter 5 to quit."<<endl;

cout<<" "<<endl;
cin>>s;
return s;

}

void enterFractions()

{

int numerator;

int denominator;

cout<<"Enter the numerator: "<<endl;

cin>>numerator;

cout<<"Enter the denominator: "<<endl;
cin>>denominator;

cout<<" "<<endl;

return;

}

void displayFractions(int & newNum, int & newDenom)

{

simplifyFractions(newNum, newDenom);

cout<<"The simplified fraction solution is: "<<endl;

cout<<newNum<<"/"<<newDenom<<endl;

return;

}

void addFractions(int & numeratorOne, int & numeratorTwo,int & denominatorOne, int & denominatorTwo)

{

int newDenom = denominatorOne * denominatorTwo;

int newNum = (numeratorOne * denominatorTwo) + (numeratorTwo * denominatorOne);

return;

}

void divideFractions(int & numeratorOne, int & numeratorTwo,int & denominatorOne, int & denominatorTwo)

{

int newNum = numeratorOne * denominatorTwo;

int newDenom = denominatorOne * numeratorTwo;

return;

}

void simplifyFractions(int & newNum, int & newDenom)

{

for(int i = newNum * newDenom; i > 1; i--)

{

if((newNum % i) == 0 && (newDenom % i) == 0)

{

newNum = newNum / i;

newDenom = newDenom / i;

}

}

return;

}

Add a comment
Know the answer?
Add Answer to:
This question is about C++! Honestly, I'm not sure what I am doing right or wrong....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Redo Programming Exercise 7 of Chapter 7 so that your program handles exceptions such as division...

    Redo Programming Exercise 7 of Chapter 7 so that your program handles exceptions such as division by zero and invalid input. Your program should print Denominator must be nonzero and reprompt for a valid denominator when 0 is entered for a denominator. Please specify what should go in the divisionByZero.h file and the changes made to main.cpp Please provide output. Thank you in advance! main.cpp so far #include <iostream> using namespace std; void addFractions(int num1, int num2, int den1, int...

  • C++ Object Oriented assignment Can you please check the program written below if it has appropriately...

    C++ Object Oriented assignment Can you please check the program written below if it has appropriately fulfilled the instructions provided below. Please do the necessary change that this program may need. I am expecting to get a full credit for this assignment so put your effort to correct and help the program have the most efficient algorithm within the scope of the instruction given. INSTRUCTIONS Create a fraction class and add your Name to the name fraction and use this...

  • C++ getline errors I am getting getline is undefined error messages. I would like the variables...

    C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...

  • In C++ Fix any errors you had with HW5(Fraction class). Implement a function(s) to help with...

    In C++ Fix any errors you had with HW5(Fraction class). Implement a function(s) to help with Fraction addition. \**************Homework 5 code*****************************/ #include<iostream> using namespace std; class Fraction { private: int wholeNumber, numerator, denominator;    public: //get methods int getWholeNumber() { return wholeNumber; } int getNumerator() { return numerator; } int getDenominator() { return denominator; } Fraction()// default constructor { int w,n,d; cout<<"\nEnter whole number : "; cin>>w; cout<<"\nEnter numerator : "; cin>>n; cout<<"\nEnter denominator : "; cin>>d; while(d == 0)...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • Hello, I'm looking to modify my fraction program to include constructors and destructors. Here are all...

    Hello, I'm looking to modify my fraction program to include constructors and destructors. Here are all the instructions: Create constructors default two argument three argument copy constructor Create a destructor. The destructor should set whole and numerator to zero and denominator to one. Add cout statements to the constructors and the destructor so you know when it's getting executed. Add system ("pause") to the destructor so you know when it executes. Only positive values allowed If denominator is 0 set...

  • If you have already answered this question, please do not repost your old solutions, you will be thumbs downed. I'm...

    If you have already answered this question, please do not repost your old solutions, you will be thumbs downed. I'm looking for NEW solutions only! Frac.h: // a Fraction object holds one Fraction number, one fraction #ifndef FRAC_H #define FRAC_H #include <iostream> using namespace std; //Creaing a Fraction class class Fraction { public: Fraction(int = 0, int = 1); // Function Declarations which performs operations on Fraction class Fraction add(const Fraction &); Fraction subtract(const Fraction& a); Fraction multiply(const Fraction& a);...

  • SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1...

    SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1 #include<iostream> using namespace std; // add function that add two numbers void add(){    int num1,num2;    cout << "Enter two numbers "<< endl;    cout << "First :";    cin >> num1;    cout << "Second :";    cin >>num2;    int result=num1+num2;    cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result;   ...

  • 13.21 Lab: Rational class This question has been asked here before, but every answer I have...

    13.21 Lab: Rational class This question has been asked here before, but every answer I have tested did not work, and I don't understand why, so I'm not able to understand how to do it correctly. I need to build the Rational.cpp file that will work with the main.cpp and Rational.h files as they are written. Rational Numbers It may come as a bit of a surprise when the C++ floating-point types (float, double), fail to capture a particular value...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT