- UID
 - 32468
 
 注册时间2007-6-1
阅读权限10
最后登录1970-1-1
周游历练 
  
 
 
 
该用户从未签到  
 | 
 
 
- #include <iOStream>//主要说明一下函数重载及拷贝函数
 
 - using namespace std; 
 
  
- class test 
 
 - { 
 
 - protected: 
 
 -         char name[20]; 
 
 -         char address[30]; 
 
 -         float zf;
 
 - public: 
 
 - //        test(){}//这是一个无参数的构造函数
 
 -         test(char *name,char *address) //第一个构造函数用来输入:姓名,地址
 
 -         { //函数重载只有在参数不同或类型不同的情况下
 
 -                 strcpy(test::address,address); 
 
 -                 strcpy(test::name,name); 
 
 -         } 
 
 - //下面这个函数可以改一下。改为:
 
 - /*         float test0(float shuxue,float yuwen,float yingyu)//来输入:数学,语文,英语并算总分。
 
 -         {
 
 -                 zf=0;
 
 -                 zf=shuxue+yuwen+yingyu;
 
 -                 return zf;
 
 -         }
 
 - 这样可把main函数里写成
 
 - test a;
 
 - float x;
 
 - x=a.test0(shuxue0,yuwen0,yingyu0);
 
 - cout<<a<<endl;
 
 - //a.test0=12345;这样写是错的。
 
 - */
 
  
-          test(float shuxue,float yuwen,float yingyu)//来输入:数学,语文,英语并算总分。
 
 -         {
 
 -                 zf=0;
 
 -                 zf=shuxue+yuwen+yingyu;
 
 -         //        return zf;
 
 -         }
 
 - /*        test(test &temp0) //拷贝函数,系统自动提供,也可以不写。
 
 -         { 
 
 -                 strcpy(test::address,temp0.address); 
 
 -                 strcpy(test::name,temp0.name);
 
 -         } */
 
 -         ~test() //这里是空析构,有没有都一样
 
 -         { 
 
 -                          
 
 -         } 
 
 -         void show() 
 
 -         { 
 
 -         cout<<"名称:"<<name
 
 -                 <<"地址:"<<address
 
 -                 <<"总分:"<<zf<<endl;
 
 -         } 
 
 - }; 
 
  
 
 
- void main() 
 
 - { 
 
 -         cout<<"请输入学生资料:"<<endl;
 
 -         //cin>>getin.name>>getin.address;这样写是不对的,因为这两个变量是保护的。
 
 -         char name0[20]="noinput",address0[30]="noinput";
 
 -         float shuxue0=0,yuwen0=0,yingyu0=0;
 
 -         cout<<"姓名:";cin>>name0;
 
 -         cout<<"地址:";cin>>address0;
 
 -         cout<<"数学:";cin>>shuxue0;
 
 -         cout<<"语文:";cin>>yuwen0;
 
 -         cout<<"英语:";cin>>yingyu0;
 
  
-         test getin0(name0,address0);
 
 -         test getin1(shuxue0,yuwen0,yingyu0);
 
 -         getin0.show(); //大家可以看看这两个show的区别。
 
 -         getin1.show();
 
 - }
 
  复制代码 |   
 
 
 
 |