Thread: Creating a class

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    24

    Creating a class

    So I'm new to this whole class thing. My prof gave me a main function and asked us to derive class defenitions and stuff. Main is as follows:

    Code:
    int main( void ) //do not change or modify this function
    {
    	DynamicFraction frA; //line 1
    	frA.print();
    
    	DynamicFraction frB( 4 ); //line 3
    	frB.print();
    
    	DynamicFraction frC( 3, -4); //line 5
    	frC.print();
    
    	DynamicFraction frD( frB ); //line 7
    	frD.print(); //line 8
    
    	frA = frB + frC; //line 9
    	frA.print(); //line 10
    
    	frA = frB - frD; //line 11
    	frA.print();
    
    	frB.print();
    	frC.print();
    	frD.print();
    
    	if ( frA > frC ) //line 16
    	{
    		cout << "frA is greater than frC" <<endl;
    	}
    	else if ( frA == frC ) //line 17
    	{
    		cout << "frA is equal to frC" << endl;
    	}
    	else
    	{
    		cout << "frA is less than frC" << endl;
    	}
    
    	cout << endl; //line 38
    	return 0; //line 39
    }
    I tried my best to create a class that satisfies all that but I keep getting loads and loads of errors. Help/tip/etc would be much appreciated

  2. #2
    Registered User
    Join Date
    Sep 2007
    Location
    Arizona
    Posts
    164
    post the code you have for the class so we can comment on where you have missed the mark.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    24
    All we have is this:

    Code:
    class DynamicFraction
    {
    public:
    //Filling in Constructors and Destructors; Proper getters and setters; Required utilities and operator functions
    
    private:
    int* ptrNum;
    int* ptrDenom;
    };
    Not helpful, I know. But that's all I have and we're expected to fill it in =(
    I don't even know how to get started. Pathetic, really.

  4. #4
    Registered User
    Join Date
    Sep 2007
    Location
    Arizona
    Posts
    164
    Based on:
    DynamicFraction frB( 4 );
    DynamicFraction frC( 3, -4);
    You have two constructors, besides the default constructor, right?
    So start there.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You're just supposed to fill in the missing parts in the class, right?
    This one's a toughie, since it uses constructors, a function and operator overloading.
    There. You can try to read a little on those three things and see how well you can do it.
    Then check back if you run into trouble.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  3. Creating threads from a class
    By Niara in forum C++ Programming
    Replies: 2
    Last Post: 06-02-2006, 03:52 PM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  5. Creating a string class
    By incognito in forum C++ Programming
    Replies: 2
    Last Post: 01-19-2002, 05:40 PM