Here is my coding, I know its sad, but I am lost.
After reading my code below and the guidelines I just have a few questions:
1. Am I on the right track so far?
2. To get the fractions should I put a cin in the setter functions, if not how should I go about getting the fractions, in main?
3.How should I declare the operators, as I'm not 100% sure?
4.Where should I put the coding to prompt the user to choose multiplication or addition?
5. How would I do the last two steps, the comparing to see if the two fractions are equal?
#include <iostream.h>
#include <stdlib.h>
#include <cstring>
#include <cctype>
class Fraction
{
private:
int numerator;
int denominator;
public:
Fraction ();
Fraction (int numerator, int denominator);
Fraction (Fraction &);
int operator* ();
int operator+ ();
operator double ();
int operator= (Fraction &);
int operator== (Fraction &);
int getNumerator ();
void setNumerator (int numerator);
int getDenominator ();
void setDenominator (int denominator);
};
Fraction::Fraction (int numerator, int denominator) {
setNumerator();
setDenominator();
}
void Fraction::setNumerator(int numeratorArg){
if(numeratorArg > 0){
numerator = numeratorArg;
}
}
int Fraction::getNumerator(){
return numerator;
}
void Fraction::setDenominator(int denominatorArg){
if(denominatorArg > 0){
denominator = denominatorArg;
}
}
int Fraction::getDenominator(){
return denominator;
}
using namespace std;
int main(int argc, char *argv[])
{
system("PAUSE");
return EXIT_SUCCESS;
}
Name the class "Fraction". Create three constructors for the class. The first constructor (the default constructor) will assign 1 for the numerator and 1 for the denominator. Create an overloaded constructor that takes two integer arguments. This argument will allow the class user to specify the numerator and the denominator. Finally, you must create a copy constructor.
The class must have a private data members for the numerator and the denominator. You may add as many other private variables as necessary to implement the remainder of the assignment. You should not have any public variables unless they are constants. Do not allow the numerator to be less than one. Do not allow the denominator to be less than one.
The class must also have the following functions. These functions should all be public.
operator* - Return a new Fraction object that is the product of two existing Fraction objects.
operator+ - Return a new Fraction object that is the sum of two existing Fraction objects.
operator double - Return the value of the Fraction object as a double. Divide the numerator by the denominator to get this result.
operator= - Assign the value of one Fraction object to another Fraction object.
operator== - Compare the values of each data member in one object to the respective value of the data members in a second object. The objects are equal if the respective data elements are equal. Return true if the objects are equal. Return false if they are not equal.
getNumerator - Return the class numerator.
getDenominator - Return the class denominator.
setNumerator - Receive one integer argument and update the class numerator.
setDenominator - Receive one integer argument and update the class denominator if the argument isn't zero. Default to one if the argument is zero.
You do not need a destructor for this class.
Do not use any inline functions.
You may not use any global variables except symbolic constants.
Try to modularize your code through the use of functions. Your program must have a minimum of 3 functions (not including main) but may have more. This does not include the functions that are members of the Fraction class. One function must accept a pointer to a Fraction object and this function must use the pointer to update the object.
The application (client) code should prompt the user to enter the numerator and denominator for the first Fraction object. Prompt the user to enter the numerator and denominator for the second Fraction object. Prompt the user to enter + or * to indicate if they want the fractions added or multiplied. Perform the desired operation based on the user input and print the result. Print the result using the get functions to retrieve the class data. You do not need to reduce the fraction. That is a result of 3/6 doesn't have to be reduced to 1/2.
After completing the previous step, ask the user if he/she wants to continue. Repeat the previous step if the user enters Y or y. Stop the application if the user enters anything else.
At the end of the program (just before quitting), create another copy of the Fraction object using the copy constructor. Then call the overloaded == operator to determine if the two objects are equal. Print an appropriate message indicating whether the objects are equal or not. Print the original Fraction object and the new Fraction object using the operator double function. Print the double value to three decimal positions.
At the end of the program (just before quitting), operator= function to assign one of your existing Fraction objects to the new Fraction object created in the previous step. Call the overloaded == operator to determine if the two objects are equal. Print an appropriate message indicating whether the objects are equal or not. Then use a class set function to change one of the Fraction objects. Compare the objects again and print an appropriate message indicating whether the objects are equal or not.
I know this seems like a lot, but i'm not asking for you to code it for me, but any examples, templates, or optionally if your really nice some code would be deeply appreciated
And by the way for your help if you really want I am quite good at English and would be willing to proofread a paper or anything else english related or help you with any math homework up to Calculus 1.