| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 416 人关注过本帖
标题:[求助]题目的改错
只看楼主 加入收藏
parr1985
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-6-19
收藏
 问题点数:0 回复次数:1 
[求助]题目的改错

有谁能帮我改一下错吗? 谢了!!!

#include<iostream.h>
#include<string.h>
class student{
int No;
char name;
float en,ch,ma;
public:
void setvalue1(int a) {No=a;}
void setvalue2(char b[20]) {name=b[20];}
void setvalue3(float c,float d,float e) {en=c;ch=d;ma=e;}
void ave() {float ave=en+ch+ma/3;}
void display() {cout<<No <<name <<en <<ch <<ma <<ave<<endl;}
}

void main()
{
int a;
char b[20];
float c,d,e;
student obj1;
student obj2;
cout<<"Enter No:"<<endl;
cin>>a;
cout<<"Enter name:"<<endl;
cin.getline(b,20);
cout<<"Enter English score:"<<endl;
cin>>c;
cout<<"Enter Chinese score:"<<endl;
cin>>d;
cout<<"Enter math score:"<<endl;
cin>>e;
obj1.setvalue1(a);
obj1.setvalue2(b);
obj1.setvalue3(c,d,e);
obj1.ave();
obj1.display();
cout<<"Enter No:"<<endl;
cin>>a;
cout<<"Enter name:"<<endl;
cin.getline(b,20);
cout<<"Enter English score:"<<endl;
cin>>c;
cout<<"Enter Chinese score:"<<endl;
cin>>d;
cout<<"Enter math score:"<<endl;
cin>>e;
obj2.setvalue1(a);
obj2.setvalue2(b);
obj2.setvalue3(c,d,e);
obj2.ave();
obj2.display();
}

能用构造法修改这题吗?怎么做啊?

搜索更多相关主题的帖子: display include public 
2006-10-14 10:05
雨夜微醺
Rank: 1
等 级:新手上路
威 望:1
帖 子:147
专家分:0
注 册:2006-9-25
收藏
得分:0 

#include<iostream.h>
#include<string.h>
class student{
int No;
char name;
float en,ch,ma;
public:
void setvalue1(int a) {No=a;}
void setvalue2(char b[20]) {name=b[20];}
void setvalue3(float c,float d,float e) {en=c;ch=d;ma=e;}
//ave不是类的数据成员,display() 不会知道。
void display() {cout<<No <<name <<en <<ch <<ma <<en+ch+ma/3<<endl;}
};//兄弟你丢了。

void main()
{
int a;
char b[20];
float c,d,e;
student obj1;
student obj2;
cout<<"Enter No:"<<endl;
cin>>a;
cout<<"Enter name:"<<endl;
cin.getline(b,20);
cout<<"Enter English score:"<<endl;
cin>>c;
cout<<"Enter Chinese score:"<<endl;
cin>>d;
cout<<"Enter math score:"<<endl;
cin>>e;
obj1.setvalue1(a);
obj1.setvalue2(b);
obj1.setvalue3(c,d,e);
obj1.ave();
obj1.display();
cout<<"Enter No:"<<endl;
cin>>a;
cout<<"Enter name:"<<endl;
cin.getline(b,20);
cout<<"Enter English score:"<<endl;
cin>>c;
cout<<"Enter Chinese score:"<<endl;
cin>>d;
cout<<"Enter math score:"<<endl;
cin>>e;
obj2.setvalue1(a);
obj2.setvalue2(b);
obj2.setvalue3(c,d,e);
obj2.ave();
obj2.display();
}


我若想到你就有种莫名的开心 我一见到你就有种莫名的悸动
2006-10-14 18:07
快速回复:[求助]题目的改错
数据加载中...
 
   



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

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