#include<iostream.h>
#include<string.h>
class product
{
private:
int code,qty;
char name[20];
float up;
public:
void input();
void output();
float amount();
product();
product(int c,char n[],int q,float u);
};
product::product(){code=1;strcpy(name,"coca");qty=2;up=3;}
product::product(int c,char n[],int q,float u)
{
code=c;
strcpy(name,n);
qty=q;
up=u;
}
void product::input()
{
cout<<"input code: ";
cin>>code;
cout<<"input name: ";
cin.seekg(0);
cin.get(name,20);
cout<<"input qty: ";
cin>>qty;
cout<<"input unit price: ";
cin>>up;
}
void product::output()
{
cout<<"code="<<code<<"\t"<<"name="<<name<<"\t"<<"qty="<<qty<<"\t"<<"up="<<up<<"\t"<<"amount="<<amount();
}
float product::amount()
{
return up*qty;
}
void main()
{
product pro,pr;
pr.output();
product p[3]={product(1,"soyang",2,1200),product(2,"Hak",3,200),product(3,"Me",7,1500)};
for (int i=0;i<3;i++)
p[i].output();
cout<<endl;
pro.input();
pro.output();
}
Blogger Comment
Facebook Comment