Thread: Don't understand this

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    79

    Don't understand this

    Code:
    (a) Is/Are there error(s) with the following class definition and/or object creation? If no, provide code to create ONE object. If yes, please provide your explanation for credit.
    
    
    #include <iostream> 
    using namespace std; 
    // For all classes, the negativity of the fraction will apply
     // to the numerator
    class FractionA { 
    public:
    int n;
    int d;
    }; 
    
    int main( void ) {
    
    FractionA frA; // Line 1 : POSSIBLE CODE TO CREATE OBJECT 
    
    return 0;
    }
    What does it mean by "Provide code to create ONE object?"
    Thanks.

  2. #2
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    You've created the object successfully. What else do you need?
    Yes, class will be created without any errors. In main, you've successfully created the object as it'll call compiler default constructor.
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    79
    Yes, but the question asks if there isn't any errors in the provided code (This code was already given) then I should fill in code to create an object. Is there an object already?

  4. #4
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    I think you should read classes first.
    Yes, there is an object in your main(). Try to figure that out. I gave you a clear hint. Not only hint but the exact thing :-)
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    79
    Oh sorry, I didn't realize that... Yes, frA is an object but why is it asking me to create an object if there already is one?

  6. #6
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    So, create one more if you want to and if it's desired by the user. :-)
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  7. #7
    Registered User
    Join Date
    Oct 2010
    Posts
    79
    Yes, I can do that, but the question specifically says "one object". I think this is just a mistake by my instructor. Thanks for your help.

Popular pages Recent additions subscribe to a feed