c++中定义一个学生类,成员变量包括学号和四门课的成绩,要求计算:(1)每个学生的

#include <iostream>
#include <string>
using namespace std;
class Student
{
private:
string SName;
string SNo;
string SScore[10];
public :
void init();
void print();
};
void Student::init()
{
cout<<"请输入学生姓名:";
cin>>this->SName;
cout<<"学号:";
cin>>this->SNo;
cout<<"各科成绩:";
for(int i=0;i<5;i++)
{
cin>>this->SScore[i];
}
}
void Student::print()
{
cout<<"学生信息:姓名:"<<SName<<"\t学号:"<<SNo<<"\t各科成绩";
for(int i=0;i<5;i++)
{
cout<<SScore[i]<<"\t";
}
cout<<endl;
}
int main()
{
Student s;
s.init();
s.print();

return 0;
},我编的只能够输入一个学生的信息,怎么输入多个学生信息,并求出最高分,输出最高分学生的姓名和学号!求高手帮忙啊

#include <iostream>
#include <string>
using namespace std;

class Student {
private:
enum { SIZE = 5 };
string SName;
string SNo;
double Score[SIZE];
public:
Student(){}
Student(string name, string no, double sc[]);
void Show() const;
double GetAverage() const { return Score[SIZE - 1]; }
double GetOptimumScore() const;
};

Student::Student(string name, string no, double sc[]) {
SName = name;
SNo = no;
Score[SIZE - 1] = 0.0;
for(int i = 0; i < SIZE - 1; ++i) {
Score[i] = sc[i];
Score[SIZE - 1] += sc[i];
}
Score[SIZE - 1] = Score[SIZE - 1]/(SIZE - 1);
}

void Student::Show() const {
cout << SName << "\t";
cout << SNo << "\t";
cout.precision();
cout.showpoint;
for(int i = 0; i < SIZE; ++i) cout << Score[i] << "\t";
cout << endl;
}

double Student::GetOptimumScore() const {
double max = 0.0;
for(int i = 0; i < SIZE - 1; ++i)
if(Score[i] > max) max = Score[i];
return max;
}

int main() {
Student s[5];
string name,no;
double score[5];
for(int i = 0; i < 5; ++i) {
cout << "学生" << i + 1 << "信息\n";
cout << "姓名 : ";
cin >> name;
cout << "学号 : " ;
cin >> no;
cout << "高等数学 : ";
cin >> score[0];
cout << "英语 : ";
cin >> score[1];
cout << "C编程 : ";
cin >> score[2];
cout << "电脑硬件 : ";
cin >> score[3];
cout << endl;
s[i] = Student(name,no,score);
}
cout << "姓名\t学号\t高数\t英语\t编程\t硬件\t\n";
for(int i = 0; i < 48; ++i) cout << "*";
cout << endl;
for(int i = 0; i < 5; ++i) s[i].Show();
cout << endl;
return 0;
}追问

error C2374: 'i' : redefinition; multiple initialization
see declaration of 'i'
e redefinition; multiple initialization
see declaration of 'i'
fatal error C1004: unexpected end of file found,帮忙解决一下吧
,谢谢

追答

int main() {
int i;
Student s[5];
string name,no;
double score[5];
for(i = 0; i > name;
cout > no;
cout > score[0];
cout > score[1];
cout > score[2];
cout > score[3];
cout << endl;
s[i] = Student(name,no,score);
}
cout << "姓名\t学号\t高数\t英语\t编程\t硬件\t\n";
for(i = 0; i < 48; ++i) cout << "*";
cout << endl;
for(i = 0; i < 5; ++i) s[i].Show();
cout << endl;
return 0;
}

追问

你可以再帮忙改一下吗?功能实现(1)输出总分最高的学生的姓名和总分数(2)输出每门课单科分最高的学生的学号和分数。(这里假设有5个学生,每个学生的学号和成绩从键盘输入).关键位置注释一下,我好好学习一下,谢谢

追答

int main() {
int i,k;
Student s[5];
string name,no;
double score[5],max;
for(i = 0; i > name;
cout > no;
cout > score[0];
cout > score[1];
cout > score[2];
cout > score[3];
cout max) {
max = s[i].GetAverage();
k = i;
}
}
cout << endl;
cout << "总分最高的是:\n";
s[k].Show();
return 0;
}

追问

error LNK2001: unresolved external symbol _WinMain@16
Debug/cxc.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
这问题咋解决啊?还有是单科最高的咋求啊,也需要输出每科最高分啊、你帮帮忙,非常感谢

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-05-26
最高分
void cGPA:: Highest(cGPA *obj, int sem,int stud)
{
float temp;
temp=obj[0].gpa[0];

for (int j=0;j<stud;j++)
{
for (int i=0;i<sem;i++)
{
if (obj[j].gpa[i]>=temp)
{
obj[j].highest=obj[j].gpa[i];
}
}
}

}追问

帮忙写到程序里可以吗?我不知道写哪好啊?谢谢了

第2个回答  推荐于2017-07-25
在main函数中定义多个Student对象或Student数组;
例如:Student students[3];
for(int i = 0; i < 3; i++)
{
students[i].init();//input the students infomation
//students[i].printf();
}
maxSum = temp;
cout << " the higthest score is "<< maxSum<<endl;
在定义一个数据成员sum[.求总分
再输入数据的成员函数init()中加上
for(int i = 0;i< 10;i++)
{
sum= sscore[i]
}
再加上一个函数找最值的
int find ()
{
int temp
for (int i = 0; i < 10 ; i ++)
{
if (students[i].sum<students[i+1]. sum)
{ temp = students[i+1].sum;
}
}
return temp;
}
具体函数加在哪,你应该知道了吧追问

你帮忙完整的写一遍把?我不太会。。。谢谢

追答

#include

using namespace std;

#include
#include
using namespace std;
//int find (Student);
class Student
{
private:
string SName;
string SNo;
int SScore[10];
int sum;
public :
void init();
void print();
};
void Student::init()
{
cout>this->SName;
cout>this->SNo;
cout>this->SScore[i];
}
for(int i = 0;i< 10;i++)
{
sum = SScore[i] + sum;
}

}
void Student::print()
{
cout<<"学生信息:姓名:"<<SName<<"\t学号:"<<SNo<<"\t各科成绩";
for(int i=0;i<5;i++)
{
cout<<SScore[i]<<"\t";
}
cout<<endl;
}
int find (Student);
int main()
{
//Student s;
// s.init();
//s.print();
int maxSum;
Student students[3];
for(int i = 0; i < 3; i++)
{
students[i].init();//input the students infomation
//students[i].printf();
}
maxSum = find (students[]);

cout << " the higthest score is "<< maxSum<<endl;

return 0;
}
int find (students)
{
int temp;
for (int i = 0; i < 10 ; i ++)
{
if (students[i].sum<students[i+1].sum)
{ temp = students[i+1].sum;
}
}
return temp;
}
还有编译错误,你自己改改吧,问题不大了,我得睡觉了,你要改不了,明天再说,我也是学生哦,学软件的,C++结课了,忘得差不多了!嘻嘻嘻

追问

你在帮我解决一下?可以不?谢谢、、、、、、要求总分最高的和每科最高分都要输出来啊,你帮帮我看看把,顺便关键位置注释一下,我好好学习学习。

第3个回答  2012-05-28
在主函数中定义数组s[5],然后在主函数中在for函数内调用输入输出函数,你试试应该可以的。
相似回答