设为首页 加入收藏

TOP

利用c++类和对象建立学生成绩管理系统(二)
2017-07-26 10:22:50 】 浏览:513
Tags:利用 类和 对象 建立 学生 成绩 管理系统
me) == 0)
{
f5 = 1;
n–;
do{
stu[i] = stu[i + 1];
i++;
} while (i <= n);
}
}
if (f5 == 0)
cout << “您要删除的学生不存在”;
cout << “是否要继续删除(输入y或者n)” << endl;
cin >> c;
if (toupper(c) != ‘Y’&&toupper(c) != ‘N’)
{
cout << “输入错误!您只能输入Y或N” << endl;
cin >> c;
}
} while (toupper(c) == ‘Y’);
getchar();
}

void student::save()
{
char filename1[20];
cout << “请输入文件名:”;
cin >> filename1;
ofstream fout(filename1, ios::app);
if (!fout)
cout << “文件不能打开!” << endl;
else
{
for (int i = 0; i < n; i++)
fout << ’ ’ << stu[i].number << ’ ’ << stu[i].name
<< ’ ’ << stu[i].sex << ’ ’ << stu[i].score[0]
<< ’ ’ << stu[i].score[1] << ’ ’ << stu[i].score[2]
<< ’ ’ << stu[i].score[3] << ’ ’ << stu[i].score[4]
<< ’ ’ << stu[i].score[5] << ’ ’ << stu[i].score[6]
<< ’ ’ << stu[i].total << ’ ’ << stu[i].average
<< ’ ’ << stu[i].last;
cout << “保存成功” << endl;
}
fout.close();
getchar();
}

void student::load()
{
char filename2[20];
cout << “请输入您要读取的文件名:”;
cin >> filename2;
ifstream fin(filename2, ios::in);
if (!fin)
cout << “文件打不开!” << endl;
else
{
for (int i = 0;; i++, n = i - 1)
{
if (fin.eof())
break;
fin >> stu[i].number >> stu[i].name

stu[i].sex >> stu[i].score[0] >> stu[i].score[1]
stu[i].score[2] >> stu[i].score[3] >> stu[i].score[4]
stu[i].score[5] >> stu[i].score[6]
stu[i].total >> stu[i].average >> stu[i].last;
}
cout << “文件已读取成功!” << endl;
}
fin.close();
getchar();
}

student & student::operator=(student & T)//重载=运算定义
{
strcpy(name, T.name);
strcpy(sex, T.sex);
number = T.number;
for (int i = 0; i < 7; i++)
score[i] = T.score[i];
total = T.total;
average = T.average;
last = T.last;
return (*this);
}
ostream & operator<<(ostream & scout, student &s2)//重载流插入
{
cout << setw(5) << s2.number << setw(8) << s2.name << setw(6) << s2.sex
<< setw(6) << s2.score[0] << setw(6) << s2.score[1]
<< setw(6) << s2.score[2]<< setw(6) << s2.score[3]
<< setw(6) << s2.score[4] << setw(6) << s2.score[5]
<< setw(7) << s2.score[6] << setw(8) << s2.last << ‘\n’;
return scout;
}
istream & operator>>(istream & scin, student &s1)
{
cout << ‘\n’;
cout << “学号:”;
scin >> s1.number;
cout << “姓名:”;
scin >> s1.name;
cout << “性别:”;
scin >> s1.sex;
cout << “语文:”;
scin >> s1.score[0];
cout << “英语:”;
scin >> s1.score[1];
cout << “数学:”;
scin >> s1.score[2];
cout << “物理:”;
scin >> s1.score[3];
cout << “化学:”;
scin >> s1.score[4];
cout << “生物:”;
scin >> s1.score[5];
cout << “平时成绩:”;
scin >> s1.score[6];
s1.total = s1.score[0] + s1.score[1]
+ s1.score[2] + s1.score[3]
+ s1.score[4] + s1.score[5];
s1.average = s1.total / 6;
s1.last = (int)(s1.score[6] * 0.3 + s1.average*0.7);
return scin;

}
student::student()//构造函数
{
strcpy(name, ” “);
strcpy(sex, ” “);
number = 0;
for (int i = 0; i < 7; i++)
score[i] = 0;
total = 0;
average = 0;
last = 0;
}

void menu()
{
cout << “\n\n\n\t\t\t【学生成绩管理系统主菜单】” << endl;
cout << “\n\n\t\t1.学生成绩录入”;

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇EffectiveC++学习笔记-条款36|37 下一篇在程序中调用C++链接库中的回调函..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目