📄 xue.txt
字号:
// 学生社团管理系统.cpp : Defines the entry point for the console application.
//
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
class CStudent
{
public:
string ID;
string Name;
string Sex;
string BanJi;
string College;
CStudent();
};
CStudent::CStudent()
{
}
int main(int argc, char* argv[])
{
cout<<"***********************************************************************"<<endl;
cout<<"*************************************学籍管理系统**********************"<<endl;
cout<<"***********************************************************************"<<endl;
CStudent student[1000];
int i = 0 ;
int TotalNum = 0;
ifstream fin("student.txt");
string str;
string ID , Name , Sex , BanJi , College;
while(!fin.eof())
{
getline(fin,str);
student[i].ID = str;
getline(fin,str);
student[i].Name = str;
getline(fin,str);
student[i].Sex= str;
getline(fin,str);
student[i].BanJi = str;
getline(fin,str);
student[i].College = str;
i++;
}
fin.clear();
fin.close();
TotalNum = i;
while(1)
{
cout<<"请选择您要进行的操作:1 添加。 2 删除。3 修改。 4 查询。 5 退出"<<endl;
cin>>i;
///////////////////
switch(i)
{
case 1:
{
while(1)
{
cout<<"添加信息"<<endl;
cout<<"请输入学号:"; cin >>ID; cout<<endl;
cout<<"请输入姓名:"; cin >>Name; cout<<endl;
cout<<"请输入性别:"; cin >>Sex; cout<<endl;
cout<<"请输入班机:"; cin >>BanJi; cout<<endl;
cout<<"请输入学院:"; cin >>College; cout<<endl;
student[TotalNum].ID = ID;
student[TotalNum].Name = Name;
student[TotalNum].Sex = Sex;
student[TotalNum].BanJi = BanJi;
student[TotalNum].College = College;
TotalNum++;
cout<<"继续 Y 退出 N"<<endl;
cin >>str;
if(str == "N"||str == "n")
{
break;
}
}
};
break;
case 2:
{
while(1)
{
cout<<"查询信息"<<endl;
cout<<"请输入要删除学员学号:"; cin >>ID; cout<<endl;
int i =0;
int j =0;
int index = -1;
for(i =0 ; i < TotalNum ; i++)
{
if(student[i].ID == ID)
index = i;
break;
}
if(index == -1)
{
cout<<"学号输入错误!或者该学员不存在!"<<endl;;
}
else
{
for(i =index ; i < TotalNum ; i++)
{
student[i] = student[i+1];
}
TotalNum--;
}
cout<<"继续 Y 退出 N"<<endl;
cin >>str;
if(str == "N"||str == "n")
{
break;
}
}
};
break;
case 3:
{
while(1)
{
cout<<"修改信息"<<endl;
cout<<"请输入要修改学员学号:"; cin >>ID; cout<<endl;
int i =0;
int j =0;
int index = -1;
for(i =0 ; i < TotalNum ; i++)
{
if(student[i].ID == ID)
index = i;
break;
}
if(index == -1)
{
cout<<"学号输入错误!或者该学员不存在!"<<endl;;
}
else
{
cout<<"请输入学号:"; cin >>ID; cout<<endl;
cout<<"请输入姓名:"; cin >>Name; cout<<endl;
cout<<"请输入性别:"; cin >>Sex; cout<<endl;
cout<<"请输入班机:"; cin >>BanJi; cout<<endl;
cout<<"请输入学院:"; cin >>College; cout<<endl;
student[index].ID = ID;
student[index].Name = Name;
student[index].Sex = Sex;
student[index].BanJi = BanJi;
student[index].College = College;
}
cout<<"继续 Y 退出 N"<<endl;
cin >>str;
if(str == "N"||str == "n")
{
break;
}
}
};
break;
case 4:
{
while(1)
{
cout<<"查询信息"<<endl;
cout<<"1 输入学号查询学生信息。2 输入班级号查询班级信息 "<<endl;
int c;
int i , index=-1;
cin>>c;
switch(c)
{
case 1:
{
cout<<"请输入学员学号:"; cin >>ID; cout<<endl;
for(i =0 ; i < TotalNum ; i++)
{
if(student[i].ID == ID)
index = i;
break;
}
if(index == -1)
{
cout<<"学号输入错误!或者该学员不存在!"<<endl;;
}
else
{
cout<<"学号:"<<student[index].ID; cout<<endl;
cout<<"姓名:"<<student[index].Name; cout<<endl;
cout<<"性别:"<<student[index].Sex; cout<<endl;
cout<<"班机:"<<student[index].BanJi; cout<<endl;
cout<<"学院:"<<student[index].College; cout<<endl;
}
};
break;
case 2:
{
cout<<"请输入班级号:"; cin >>BanJi; cout<<endl;
for(i =0 ; i < TotalNum ; i++)
{
if(student[i].BanJi == BanJi)
{
index = i;
cout<<"学号:"<<student[i].ID<<" 姓名:"<<student[i].Name<<"“性别:"<<student[i].Sex;
cout<<endl;
}
}
if(index == -1)
{
cout<<"班级号输入错误!"<<endl;
}
};
break;
}
cout<<"继续 Y 退出 N"<<endl;
cin >>str;
if(str == "N"||str == "n")
{
break;
}
}
};
break;
case 5:
break;
default:
cout<<"输入错误!!!"<<endl;
}
//////////////////////
}
ofstream fout("student.txt");
for(i = 0 ; i < TotalNum ; i ++)
{
fout<<student[i].ID<<endl;
fout<<student[i].Name<<endl;
fout<<student[i].Sex<<endl;
fout<<student[i].BanJi<<endl;
fout<<student[i].College<<endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -