I'm learning about C++ and when I was learning about Class, I ran into a problem. I try cout my element before entering the value, but the element already has a value. I can't understand why?
class cusTomer
{
char abc[30];
public:
void input();
void output();
};
void cusTomer::input(){
cout<<"abc: "; fflush(stdin); gets(abc);
}
void cusTomer::output(){
cout<<"abc: "<<abc<<endl;
}
class proDuct
{
char name[30];
public:
void input();
void output();
};
void proDuct::input()
{
cout<<"Name: "; fflush(stdin); gets(name);
}
void proDuct::output()
{
cout<<"Name: "<<name<<endl;
}
class bill
{
char date[30];
proDuct *y;
int n;
public:
void input();
void output();
};
void bill::input()
{
cout<<"Date: "; fflush(stdin); gets(date);
cout<<n<<endl; //16
cout<<"Input n: "; cin>>n;
cout<<n<<endl;
y=new proDuct[n];
for(int i=0;i<n;i++){
y[i].input();
}
}
void bill::output()
{
cout<<"Date: "<<date<<endl;
for(int i=0;i<n;i++){
y[i].output();
}
}