C++的一道题目,但是我的代码显示有问题,求大佬解答。

设计一个学生类Student,成员变量包括ID(学号),Name(姓名),Age(年龄),AverageScore(平均分),成员函数包括StudentBonus()(学生奖学金),show_information()(显示学生的全部信息,包括学号、姓名、年龄、平均分、奖学金),本例中奖学金计算方法
平均分不超过80分(含80分)的,奖学金为0,即没有奖学金;
平均分在81---90之间的,奖学金计算公式为(平均分-80)*50;
平均分在91---100之间的,奖学金计算公式为(平均分-80)*100;
在主函数中,声明2个对象并利用show_information()函数显示个人全部信息。
代码
#include<iostream>
#include<string>
using namespace std;
class Student
{
private:
int ID; //学号
string Name; //姓名
int Age; //年龄
double AverageScore; //平均分
public:
Student(int _id,string _name,int _age,double _average_score); //构造函数
int get_ID(); //返回学号
string get_Name(); //返回姓名
int get_Age(); //返回年龄
double StudentBonus(); //计算学生奖学金
void show_information();//显示学生全部信息
};
Student::Student(int _id,string _name,int _age,double _average_score) //构造函数
{
ID=_id;
Age=_age;
Name=_name;
AverageScore=_average_score;
}

int Student::get_ID()//返回学号
{
return ID;
}
int Student::get_Age()//返回年龄
{
return Age;
}
string Student::get_Name()//返回姓名
{
return Name;
}
double Student::StudentBonus()//计算学生奖学金
{
if(AverageScore<=80)
return 0.0;
else if(AverageScore>80&&AverageScore<=90)
return (AverageScore-80)*50;
else
return (AverageScore-80)*100;
}
void Student::show_information()//显示学生全部信息
{
cout<<"ID:"<<ID<<endl;
cout<<"Name:"<<Name<<endl;
cout<<"Age:"<<Age<<endl;
cout<<"AverageScore:"<<AverageScore<<endl;
cout<<"StudentBonus:"<<StudentBonus()<<endl;

}
int main()
{

Student student1(10001,"张三",20,85); //声明对象
Student student2(10002,"李四",21,95); //声明对象
student1.show_information();
student2.show_information();
return 0;
}
1>c:\users\admin\documents\visual studio 2010\projects\student\student\stdafx.cpp(7): fatal error C1075: 与左侧的 大括号“{”(位于“c:\users\admin\documents\visual studio 2010\projects\student\student\stdafx.cpp(6)”)匹配之前遇到文件结束

你的程序没有问题,只是你的工程使用了预编译头功能,需要在程序最开头加上这行代码:

#include <stdafx.h>

这样就可以了。记住,是最开头,程序的最开头!

温馨提示:答案为网友推荐,仅供参考
相似回答