hi I NEED HELP

This is a discussion on hi I NEED HELP within the Windows Programming forums, part of the Platform Specific Boards category; HELP WITH THIS PROGRAM PLEASE Create a class Rational using the UML diagram below. Rational Numerator: int Denominator: int Rational ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    5

    hi I NEED HELP

    HELP WITH THIS PROGRAM PLEASE

    • Create a class Rational using the UML diagram below.


    Rational
    Numerator: int
    Denominator: int
    Rational ( )
    Rational (int, int)
    ~Rational ()
    Int: getnumerator ()
    Int: getdenominator ()
    Setnumerator (int)
    Setdenominator (int )


    • Implement the following function as a friend function of the rational class
      • Print Rational (Rational & )



    • Create a main function that instantiates 2 objects (object 1, object2) using the primary constructor and 1 object (object3) using the default constructor.
    • Perform the following operations on the objects created:
      • Set the numerator of object3 to 34
      • Set the denominator of object2 to 89
      • Set the numerator of object1 to 5
    • Confirm that the operations were successful by displaying the result of the following functions Object1.getnumerator
      • Object2.getdenominator
      • Object3.getnumerator

    Call the Print Rational function to display each rational.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,673
    Read this link before proceeding further.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    5
    THANKS, I DO HAVE PIECES OF CODES, HERE
    Code:
    //HEADER FILE
    #include<iostream>
    using namespace std;
    
    
    class rational
    {
        //friend print rational(rational & m);
    
    public: 
    
        rational();
        rational(int,int);
        ~rational();
        int getnumerator(void);
        int getdenominator(void);
        void setnumerator(int);
        void setdenominator(int);
    
        
    private:
        int denominator;
        int numerator;
    
    };
    
    
    rational::rational()
    {
        numerator=0;
        denominator=0;
    }
    
    rational::rational(int num,int dem)
    {
        numerator=num;
        denominator=dem;
    }
    
    rational::~rational()
    {
        cout<<"we are in the destructor function"<<endl;
    }
    
    
    
    int rational::getnumerator(void)
    {
        return numerator;
    }
    int rational::getdenominator(void)
    {
        return denominator;
    }
    
    
    void rational::setnumerator(int new_numerator)
    {
        numerator=new_numerator;
    }
    
    void rational::setdenominator(int new_denominator)
    {
        denominator=new_denominator;
    }
    
    
    
    // .CPP FILE MAIN 
    
    #include<iostream>
    using namespace std;
    #include"rat.h"
    
    int main()
    {
    
    
    
    
    rational object3,object2,object1;
    
    object3.setnumerator(54);
    object2.setdenominator(89);
    object1.setnumerator(5);
    
    cout<<object1.getnumerator<<endl;
    cout<<object2.getdenominator<<endl;
    cout<<object3.getnumerator<<endl;
    
    
    
    
    
        return 0;
    }
    
    
    
    
    THANKS GRUMPY.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    5
    i keep on getting a one for output for all objects

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    5
    do i of to have these?
    Code:
    rational add(rational r)
    {
    rational l;
    int a = l.getnum();
    int b = l.getden();
    int c = r.getnum();
    int d = r.getden();
    rational result = ((a * d + b * c) / (b * d));
    return result;
    }
    for it to work?

    am reading some books and am not understanding how rational works really. sad!

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    5
    ........

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,854
    cout<<object1.getnumerator<<endl;

    Compare with

    cout<<object1.getnumerator()<<endl;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21