| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 544 人关注过本帖
标题:VC出错。错在那啊,不懂,我新学啊
只看楼主 加入收藏
小子好学
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-5-16
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:6 
VC出错。错在那啊,不懂,我新学啊
#include <iostream>
#include<string>
using namespace std;
class teacher
{public:
    teacher(string nam,int a,string t)
{name=nam;
age=a;
title=t;}
void display()
{cout<<"name:"<<name<<endl;
cout<<"age:"<<age<<endl;
cout<<"title:"<<title<<endl;
}
protected:
    string name;
    int age;
    string title;
};
class student
{public:
student(char nam[],char s,float sco)
{strcpy(namel,nam);
 sex=s;
 score=sco;}
void display()
{cout<<"name:"<<namel<<endl;
 cout<<"sex:"<<sex<<endl;
 cout<<"score:"<<score<<endl;
}
protected:
    string namel;
    char sex;
    float score;
};
class graduate:public teacher,public student
{public:
graduate(string nam,int a,char s,string t,float sco,float w):
teacher(nam,a,t),student(nam,s,sco),wage(w){}
void show()
{cout<<"name:"<<namel<<endl;
 cout<<"age:"<<age<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"score:"<<score<<endl;
cout<<"title:"<<title<<endl;
cout<<"wager:"<<wager<<endl;
}
private:
    float wage;
};
int main()
{graduate gradl("wang",24,'f',"assistant",1234.5,123.5);
gradl.show();
return 0;
}
2010-09-20 23:20
xiaozenbin
Rank: 1
等 级:新手上路
帖 子:9
专家分:3
注 册:2009-1-2
收藏
得分:3 
teacher(string name,int age,string title)
{name="nam";
age="a";
title="t";}
错得较多,举个例子:所有的赋值应该这样,应该多看看书应可以啦,
2010-09-21 02:18
myth_feng
Rank: 2
等 级:论坛游民
威 望:1
帖 子:25
专家分:59
注 册:2010-8-11
收藏
得分:3 
#pragma argsused
#include <iostream>
#include<string>
using namespace std;
class teacher
{public:
    teacher(char* nam,int a,char t)
{
strcpy(name,nam);
age=a;
title=t;
}
void display()
{cout<<"name:"<<name<<endl;
cout<<"age:"<<age<<endl;
cout<<"title:"<<title<<endl;
}
protected:
    char* name;
    int age;
    string title;
};
class student
{public:
student(char nam[],char s,float sco)
{

sex=s;
score=sco;}
void display()
{cout<<"name:"<<namel<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"score:"<<score<<endl;
}
protected:
    string namel;
    char sex;
    float score;
};
class graduate:public teacher,public student
{public:
graduate(char* nam,int a,char s,char* t,float sco,float w):
teacher(nam,a,s),student(nam,s,sco),wage(w){}
void show()
{cout<<"name:"<<namel<<endl;
cout<<"age:"<<age<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"score:"<<score<<endl;
cout<<"title:"<<title<<endl;
cout<<"wager:"<<wage<<endl;
}
private:
    float wage;
};
int main()
{
graduate gradl("wang",24,'f',"assistant",1234.5,123.5);
gradl.show();
getchar();
return 0;
}


//大体是这样  有点乱 自己再看看改改
2010-09-21 12:23
m21wo
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:4
帖 子:440
专家分:1905
注 册:2010-9-23
收藏
得分:3 
ok 啦!!!
#include <iostream>
#include<string>
using namespace std;
class teacher
{
public:
    teacher(string nam,int a,string t)
    {
        name=nam;
        age=a;
        title=t;
    }
    void display()
    {
        cout<<"name:"<<name<<endl;
        cout<<"age:"<<age<<endl;
        cout<<"title:"<<title<<endl;
    }
protected:
    string name;
    int age;
    string title;
};
class student
{
public:
    student(string nam,char s,float sco)
    {
        namel=nam;
        sex=s;
        score=sco;
    }
    void display()
    {
        cout<<"name:"<<namel<<endl;
        cout<<"sex:"<<sex<<endl;
        cout<<"score:"<<score<<endl;
    }
protected:
    string namel;
    char sex;
    float score;
};
class graduate:public teacher,public student
{
public:
    graduate(string nam,int a,string t,char s,float sco,float w):
      teacher(nam,a,t),student(nam,s,sco),wage(w){}
      void show()
      {
          cout<<"name:"<<namel<<endl;
          cout<<"age:"<<age<<endl;
          cout<<"sex:"<<sex<<endl;
          cout<<"score:"<<score<<endl;
          cout<<"title:"<<title<<endl;
          cout<<"wager:"<<wage<<endl;
      }
private:
    float wage;
};
int main()
{
    graduate gradl("wang",24,"assistant",'f',1234.5,123.5);
    gradl.show();
    return 0;
}

If You Want Something, Go Get It, Period.
2010-09-24 22:48
聋眼睛瞎耳朵
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:29
专家分:123
注 册:2010-9-24
收藏
得分:3 
顶四楼!!!你程序就student类的构造函数有问题,还有个问题就是show()输出时把数据成员的标识符打错了!!!其他地方都是对的!!
2010-09-25 14:21
jaywayjayway
Rank: 1
等 级:新手上路
帖 子:4
专家分:3
注 册:2010-9-18
收藏
得分:3 
图片附件: 游客没有浏览图片的权限,请 登录注册

这是个什么意思?
2010-09-25 17:17
kazoma610
Rank: 2
等 级:论坛游民
帖 子:4
专家分:16
注 册:2010-9-25
收藏
得分:3 
多继承!!
2010-09-25 18:14
快速回复:VC出错。错在那啊,不懂,我新学啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018349 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved