CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012
    Posts
    1

    Inheritance & Class Help

    I have been assigned a project that deals with Inheritance and classes. I am having trouble calling between classes. I am very ignorant in the area of inheritance I'm not anywhere close to a mediocre programmer. Any help is very much appreciated.

    I have deleted the details of the functions under the check and save classes to save anyone from having to filter through the massive annoying lines of useless code

    There are 4 lines of code under class account that are throwing me errors.
    Code:
    class account
    {
    	private:
    		string cust_name;
    		char account_type;
    		
    	public:
    		void get_cust_name()
    		{
    			cout << "\n\nEnter Customer Name : ";
    			cin >> cust_name;
    		}
    		void main_menu()
    		{
    			//Displays Main menu
    		}
    		void new_account()
    		{
    			char ch;
    			cout << "\n\nWhat type of account would you like to add (c for checking, s for savings)";
    			cin >> ch;
    			if(ch == 'c' || ch == 'C')
    			{
    // Error line		check.new_chk_account();
    			}
    			if(ch == 's' || ch == 'S')
    			{
    // Error line		save.new_sav_account();
    			}
    			main_menu();
    		}
    		void display_all()
    		{
    // Error line	cout << "Checking Account Information:\n"; //<< check.chk_balance << endl;
    // Error line	cout << "Savings Account Information:\n"; //<< save.sav_balance << endl; 
    			main_menu();
    		}
    };
    
    
    class check : public account
    {
    	private:
    		int chk_account_num;
    		double chk_acc_bal;
    
    	public:
    		//Checking account functions
    		void chk_acc()
    		{
    			//Displays checking account menu
    		}
    		void chk_deposit()
    		{
    		}
    		void chk_withdraw()
    		{
    		}
    		void chk_transfer()
    		{
    		}
    		void chk_balance()
    		{
    		}
    		void month_fee()
    		{
    		}
    		void new_chk_account()
    		{
    		}
    };
    
    class save : public account
    {
    	private: 
    		int sav_account_num;
    		double sav_acc_bal;
    		
    	public:
    		//Savings account functions
    		void sav_acc()
    		{
    			//Savings account menu
    		} 
    		void sav_deposit()
    		{
    		}	
    		void sav_withdraw()
    		{
    		}	
    		void sav_transfer()
    		{
    		}
    		void sav_balance()
    		{
    		}
    		void intrest()
    		{
    		}
    		void min_req()
    		{
    		}	
    		void new_sav_account()
    		{
    		}
    		
    };
    I was thinking of using pointers, but this entire code might be useless and having to scrap this would be a suprise.
    Last edited by Cimperiali; April 25th, 2012 at 11:18 PM.

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Inheritance & Class Help

    You have to create an object of the class. The class itself isn't accessible, it's just a blueprint of what it takes to make an object of that type.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Inheritance & Class Help

    You're missing the point of inheritance too. Functions like deposit should be declared virtual in your base class then overridden in your derived classes if the base class isn't sufficient. You shouldn't have chk_deposit and sav_deposit. A user of your class should be able to make a deposit or withdrawal knowing only that they're working with an account, without having to know what type.

    Your menu function shouldn't be a class member.

    New_Account shouldn't prompt the user for a class type inside the account class. That decision should be made outside the class in whatever classes or functions use your Account class.

    Really, you need to rethink your design. It misses the point completely.

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Inheritance & Class Help

    [ Moved thread ]
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured