-
April 24th, 2012, 05:53 PM
#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.
-
April 26th, 2012, 12:19 PM
#2
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.
-
April 26th, 2012, 01:32 PM
#3
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.
-
April 27th, 2012, 10:08 AM
#4
Re: Inheritance & Class Help
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|