📄 xueshengsushe.txt
字号:
#include<iostream.h>
#include<string.h>
class student//学生类
{
public:
char student_name[10];
int room_number;
int student_number;
int student_sc;
};
student student_info[16];
int number=0;
///////////////////////////////////////////////////////////////////////
void input()//输入函数
{
cout<<"输入学生人数:";
cin>>number;
if(number<=16)
{
for(int i=0;i<number;i++)
{
cout<<"输入学生学号:";
cin>>student_info[i].student_number;
cout<<"输入学生姓名:";
cin>>student_info[i].student_name;
student_info[i].student_sc=i+1;
cout<<"输入房间号:";
cin>>student_info[i].room_number;
}
cout<<"输入完毕。"<<endl;
}
else{cout<<"人数超过容纳上限。"<<endl;}
}
/////////////////////////////////////////////////////////////////////////////
void show()//显示函数
{
cout<<"姓名"<<" "<<"学号"<<" "<<"序号"<<" "<<"房间"<<endl;
for(int i=0;i<number;i++)
{
cout<<student_info[i].student_name<<" ";
cout<<student_info[i].student_number<<" ";
cout<<student_info[i].student_sc<<" ";
cout<<student_info[i].room_number<<endl;
}
}
//////////////////////////////////////////////////////////////////////////
void del()//删除函数
{
cout<<"输入要删除的学生号:"<<endl;
int temp=0;
cin>>temp;
for(int i=0;i<number;i++)
{
if(student_info[i].student_number==temp)
{
for(int j=i;(j+1)<number;j++)
{
student_info[j].student_number=student_info[j+1].student_number;
student_info[j].student_sc=student_info[j+1].student_sc;
student_info[j].room_number=student_info[j+1].room_number;
strcpy(student_info[j].student_name,student_info[j+1].student_name);
}
student_info[number].student_number=0;
student_info[number].student_sc=0;
student_info[number].room_number=0;
strcpy(student_info[number].student_name,"");
}
}
}
////////////////////////////////////////////////////////////////////////////
void change()//交换函数
{
cout<<"输入要交换的学生号:";
char temp_name[10];
int temp_number=0;
int temp_sc=0;
int temp_room=0;
int i,j;
cin>>i>>j;
i--;
j--;
temp_number=student_info[j].student_number;
temp_sc=student_info[j].student_sc;
temp_room=student_info[j].room_number;
strcpy(temp_name,student_info[j].student_name);
student_info[j].student_number=student_info[i].student_number;
student_info[j].student_sc=student_info[i].student_sc;
student_info[j].room_number=student_info[i].room_number;
strcpy(student_info[j].student_name,student_info[i].student_name);
student_info[i].student_number= temp_number;
student_info[i].student_sc=temp_sc;
student_info[i].room_number=temp_room;
strcpy(student_info[i].student_name,temp_name);
}
//////////////////////////////////////////////////////////////////////////
void search_sc()//查找序号
{
int temp=0;
cout<<"输入要查询的序号:";
cin>>temp;
int i=0;
while(student_info[i].student_sc!=(temp)) i++;
cout<<student_info[i].student_name<<" ";
cout<<student_info[i].student_number<<" ";
cout<<student_info[i].student_sc<<" ";
cout<<student_info[i].room_number<<endl;
}
//////////////////////////////////////////////////////////////////////////
void search_name()//查找姓名
{
char temp[10];
cout<<"输入要查询的姓名:";
cin>>temp;
int i=0;
while(strcmp(student_info[i].student_name,temp)) i++;
cout<<student_info[i].student_name<<" ";
cout<<student_info[i].student_number<<" ";
cout<<student_info[i].student_sc<<" ";
cout<<student_info[i].room_number<<endl;
}
/////////////////////////////////////////////////////////////////////////
void search_number()//查找学号
{
int temp=0;
cout<<"输入要查询的学号:";
cin>>temp;
int i=0;
while(student_info[i].student_number!=(temp)) i++;
cout<<student_info[i].student_name<<" ";
cout<<student_info[i].student_number<<" ";
cout<<student_info[i].student_sc<<" ";
cout<<student_info[i].room_number<<endl;
}
//////////////////////////////////////////////////////////////////////////
void win()//界面函数
{
while(1)
{
cout<<endl<<"系统菜单:" <<endl;
cout<<"1、修改子菜单"<<endl;
cout<<"2、查询子菜单" <<endl;
int server=0;
cout<<"输入子菜单类型:" ;
cin>>server;
if(server==1)
{
cout<<"1、输入:"<<endl;
cout<<"2、删除"<<endl;
cout<<"3、交换"<<endl;
cout<<"4、显示所有"<<endl;
cout<<"5、结束"<<endl;
cout<<"选择子菜单:";
int temp=0;
cin>>temp;
switch(temp)
{
case 1:
input();break;
case 2:
del();break;
case 3:
change();break;
case 4:
show();break;
case 5:
exit(0);
} }
else if(server==2)
{
cout<<"1、按姓名查询"<<endl;
cout<<"2、按学号查询"<<endl;
cout<<"3、按序号查询"<<endl;
cout<<"选择子菜单:";
int temp;
cin>>temp;
switch(temp)
{
case 1:
search_name();break;
case 2:
search_number();break;
case 3:
search_sc();break;
}
}
}
}
/////////////////////////////////////////////////////////////////////////
void main()//主函数
{
win();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -