c 语言实现简易学生管理系统
#include <iostream>
#include <string>
using namespace std;
void show();
void rankSource();
void addStudent();
void deleteStudent();
void remarkSource();
void showInformation();
int find();
void findSource();
void findName();
typedef struct student
{
string name;
string gender;
double source;
}student;
student stu[300];
int number = 0;
void findSource()
{
int flag = find();
cout << stu[flag].source << endl;
}
void findName()
{
int flag = find();
cout << stu[flag].name <<" "<< stu[flag].gender<<" " <<stu[flag].source<< endl;
}
void rankSource( )
{
cout << "按成绩从小到大排序还是从大到小排序,小输入(1),大输入(0)" << endl;
bool mini;
cin >> mini;
student temp;
for(int i=0;i<number;i++)
{
for(int j=0;j<number;j++)
{
if(!mini){
if(stu[i].source > stu[j].source){
temp = stu[j];
stu[j] = stu[i];
stu[i] = temp;
}
}else{
if(stu[i].source < stu[j].source){
temp = stu[j];
stu[j] = stu[i];
stu[i] = temp;
}
}
}
}
}
void showInformation( )
{
for(int i=0;i<number;i++)
{
cout << stu[i].name <<" "<<stu[i].gender <<" " << stu[i].source <<endl;
}
}
void remarkSource()
{
int flag = find();
if(flag != -1){
cout << "输入修改后的成绩" << endl;
cin >> stu[flag].source;
cout << "修改成功" << endl;
}else{
cout << "修改失败" << endl;
}
}
void addStudent()
{
int n = number;
cout << "输入学生的姓名 性别 分数 "<<endl;
cin >> stu[n].name >> stu[n].gender >> stu[n].source;
number++;
}
int find( )
{
cout << "输入学生的姓名" <<endl;
string name;
cin >> name;
int flag =-1;
for (int i =0 ;i<number; i++){
if(stu[i].name == name){
flag = i;
break;
}
}
if(flag == -1) {
cout <<"未找到该学生"<< endl;
return -1;
}
return flag;
}
void deleteStudent()
{
int flag = find();
if(flag != -1){
for(int i=flag;i<number-1;i++){
stu[i] = stu[i+1];
}
}
number--;
}
void show()
{
cout << "------------------------------------" <<endl;
cout << "---------1.添加学生-------------------" <<endl;
cout << "---------2.删除学生-------------------" <<endl;
cout << "---------3.修改学生的成绩--------------" <<endl;
cout << "---------4.查看学生的成绩--------------" <<endl;
cout << "--------5.查看所有学生的信息------------" <<endl;
cout << "------6.对学生的成绩进行排序-------------" <<endl;
cout << "--------7.查找某个学生-----------------" <<endl;
cout << "-------8.退出或者任意退出----------------" <<endl;
cout << "-------------------------------------" <<endl;
}
int main(int argc, const char * argv[]) {
while(1){
show();
int count ;
cin >> count;
switch (count) {
case 1:addStudent();
break;
case 2:deleteStudent();
break;
case 3:remarkSource();
break;
case 4:findSource();
break;
case 5:showInformation();
break;
case 6:rankSource();
break;
case 7:findName();
break;
default:exit(1);
break;
}
}
return 0;
}