#include
#include
#define MAX_STUDENT 40
struct CStudent
{
private:
char m_name[20];
int m_age;
char m_sex[10];
double m_math;
double m_english;
double m_chinese;
public:
CStudent()
{
}
CStudent(char* name, int age, char* sex )
{
strcpy(m_name,name);
m_age = age;
strcpy(m_sex,sex);
}
void SetName(char* name )
{
strcpy(m_name,name);
}
void SetAge(int age)
{
m_age = age;
}
void SetSex(char* sex)
{
strcpy(m_sex,sex);
}
void ShowName()
{
cout << m_name << endl;
}
void ShowAge()
{
cout << m_age << endl;
}
void ShowSex()
{
cout << m_sex << endl;
}
void SetEnglish(double english)
{
m_english = english;
}
void SetMath(double math)
{
m_math = math;
}
void SetChinese(double chinese)
{
m_chinese = chinese;
}
double GetMathScore()
{
double dblScore;
if (m_math < 60) {
dblScore = 0;
}
else if (m_math >=60 && m_math < 70) {
dblScore = 1;
}
else if (m_math >=70 && m_math < 80) {
dblScore = 2;
}
else if (m_math >=80 && m_math < 90) {
dblScore = 3;
}
else if (m_math >=90 && m_math < 100) {
dblScore = 4;
}
else if (100 == m_math) {
dblScore = 5;
}
return dblScore;
}
double GetChineseScore()
{
double dblScore;
if (m_chinese < 60) {
dblScore = 0;
}
else if (m_chinese >=60 && m_chinese < 70) {
dblScore = 1;
}
else if (m_chinese >=70 && m_chinese < 80) {
dblScore = 2;
}
else if (m_chinese >=80 && m_chinese < 90) {
dblScore = 3;
}
else if (m_chinese >=90 && m_chinese < 100) {
dblScore = 4;
}
else if (100 == m_chinese) {
dblScore = 5;
}
return dblScore;
}
double GetEnglishScore()
{
double dblScore;
if (m_english < 60) {
dblScore = 0;
}
else if (m_english>=60 && m_english < 70) {
dblScore = 1;
}
else if (m_english >=70 && m_english < 80) {
dblScore = 2;
}
else if (m_english >=80 && m_english < 90) {
dblScore = 3;
}
else if (m_english >=90 && m_english < 100) {
dblScore = 4;
}
else if (100 == m_english) {
dblScore = 5;
}
return dblScore;
}
};
void main()
{
CStudent student[MAX_STUDENT];
int index = 0;
char c = 'y';
char name[20];
char sex[10];
double english,math,chinese;
int age;
while (c == 'y' || c == 'Y') {
cout << "输入学生姓名:" << endl;
cin >> name;
student[index].SetName(name);
cout << "输入学生年龄:" << endl;
cin >> age;
student[index].SetAge(age);
cout << "输入学生性别:" << endl;
cin >> sex;
student[index].SetSex(sex);
cout << "输入英语成绩:" << endl;
cin >> english;
student[index].SetEnglish(english);
cout << "输入数学成绩:" << endl;
cin >> math;
student[index].SetMath(math);
cout << "输入语文成绩:" << endl;
cin >> chinese;
student[index].SetChinese(chinese);
index ++;
cout << "是否继续输入(Y/N)" << endl;
cin >> c;
}
cout << "=========================打印成绩表================================"<< endl;
for(int j = 0; j < index; j ++)
{
cout << "姓名为:" << endl;
student[j].ShowName();
cout << "年龄为:" << endl;
student[j].ShowAge();
cout << "性别为:"<< endl;
student[j].ShowSex();
cout << "英语学分为:" << student[j].GetEnglishScore() << endl;
cout << "数学学分为:" << student[j].GetMathScore() << endl;
cout << "语文学分为:" << student[j].GetChineseScore() << endl;
cout << "总学分:" << student[j].GetMathScore() * 3 + student[j].GetEnglishScore() * 1.5 + student[j].GetChineseScore() * 2 << endl;
cout <
}
}