class inheritance

In this problem i have to develop a program to make a class account with derived class as current account(cur_acct).I have to store the customer name,a/c number and a/c type in the class account and the other details in current account class.

My query is that my program is not taking the account number and account type as the input from user.

#include<iostream>
using namespace std;
class account
{
int bal;
char customer_name[20],type[20],account_number[20];

public:
void display1()
{
bal=10000;
cout<<"customer name:";
cin>>customer_name[20];
}
void display2()
{
cout<<"\naccount number :";
cin>>account_number[20];
}
void display3()
{
cout<<"\ntype of account";
cin>>type[20];
}
int get_bal()
{
return bal;
}
};
class cur_acct: public account
{
int d,e,f;
public:
void display()
{
cout<<"\ncheque book available.\n";
}
int input_deposit(int x)
{
d=x;
cout<<"deposited amount is:"<<d;
e=get_bal()+d;

}
int display_new(int z)
{
e=z;
cout<<"\nnew balance is:"<<e;
}
void withdraw(int y)
{
f=y;
cout<<"\nwithdrawl amount is:"<<f;

e=e-f;
cout<<"\nnew balance is:"<<e;
}
void check()
{
if(e<1500)
cout<<"\npenalty is 200 rs. per day";
}
void display_new1()
{
cout<<"\nupdated balance after check is:"<<e;
}
};
int main()
{
cur_acct C;
C.display1();
C.display2();
C.display3();
C.display();
C.input_deposit(5000);
C.display_new(15000);
C.withdraw(14000);
C.check();
C.display_new1();
system("pause");
}






Lines 13,18,23: Your cin's are defective. You're trying to input a single character into the 21st character of the array. This is an out of bounds reference. Your arrays contain 20 characters (0-19).

What you want is simply this:
 
cin>>customer_name;  // ditto for type and account_number 


PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Hint: You can edit your previous post, highlight your code and press the <> formatting button.
Thanku sir.It solved my problem :)
Topic archived. No new replies allowed.