include <iostream>#include <cstring>using namespace std;class Date{ int year; int month; int day;public: int Getyear() { return year; } int Getmonth() { return month; } int Getday() { return day; } void Setyear() { }};class Product{ char *name; double price; Date deptime; char *factory; bool easy_break; Date valtime; char *color; double num;public: Product(char *n); Product(char *n,double p=0); Product(char *n,double p,Date d); void SetProduct(char *n,double p,Date d,char *f,bool e,Date v,char *c,int number); void output ();};void Product::output (){ cout<<name<<" "<<price<<endl; cout<<deptime.Getyear()<<"-"<<deptime.Getmonth()<<"-"<<deptime.Getday()<<endl; cout<<factory<<" "<<easy_break<<endl; cout<<valtime.Getyear()<<"-"<<valtime.Getmonth()<<"-"<<valtime.Getday()<<endl;}Product::Product(char *n){ name=new char[strlen(n)+1]; strcpy(name,n); cout<<"Constrcting One...."<<endl;}Product::Product(char *n,double p){ name=n; price=p; cout<<"Constrcting Two...."<<endl;}Product::Product(char *n,double p,Date d){ name=n; price=p; Date deptime(d); cout<<"Constrcting Three...."<<endl;}void Product::SetProduct(char *n,double p,Date d,char *f,bool e,Date v,char *c,int number){ name=n; price=p; Date deptime(d); // factory=f; easy_break=e; Date valtime(v); color=c; num=number;}int main(){ char s[10]; cin>>s; Product p1("car"); Product p2("glass",3.00); Product p3("pen",5.00,2009,3,14); p1.SetProduct("car",100000.0,2009,3,14,"nanjing",0,2010,10,14,"red",1.5); p1.output(); p2.output(); p3.output(); return 0;}
慕容森
DIEA
相关分类