班级通讯录管理系统

#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
struct student
{
char s_no[20];
char s_name[20];
char s_sex[10];
char s_year[10];
char s_month[10];
char s_day[10];
char s_tel[20];
char s_qq[20];
student()
{
memset(s_no, 0,20);
memset(s_name,0,20);
memset(s_sex,0,10);
memset(s_year,0,10);
memset(s_month,0,10);
memset(s_day,0,10);
memset(s_tel,0,20);
memset(s_qq,0,20);
}

};
class StudentContact{
private:
student st[55];

public:
static int num;
void display()
{
cout<<endl<<endl;
cout<<"****************<班级通讯录管理系统>****************"<<endl<<endl;
cout<<"※ ※"<<endl;
cout<<"※ 1. 添加学生基本信息. 2. 删除学生基本信息 . ※" <<endl;
cout<<"※ 3. 查询学生基本信息. 4. 修改学生基本信息 . ※" <<endl;
cout<<"※ 5. 退出程序. ※" <<endl<<endl;
cout<<"*****************************************************"<<endl<<endl;
}
void print(int i){
cout<<"学号:"<<st[i].s_no<<endl;
cout<<"姓名:"<<st[i].s_name<<endl;
if(!strcmp(st[i].s_sex,"1"))
cout<<"性别:"<<"男"<<endl;
else
cout<<"性别:"<<"女"<<endl;
cout<<"出身日期:"<<st[i].s_year<<" 年 "<<st[i].s_month<<" 月 "<<st[i].s_day<<" 日 "<<endl;
cout<<"手机号码:"<<st[i].s_tel<<endl;
cout<<"QQ:"<<st[i].s_qq<<endl;
}
void print(){
for(int i=0;i<num;i++){
for(int j=0;j<num-1-i;j++){
if(strcmp(st[j].s_no,st[j+1].s_no)>0){
char temp[20];
char name[20];
char sex[10];
char year[10];
char month[10];
char day[10];
char tel[20];
char qq[20];
strcpy(temp,st[j+1].s_no);
strcpy(st[j+1].s_no,st[j].s_no);
strcpy(st[j].s_no,temp);
strcpy(name,st[j+1].s_name);
strcpy(st[j+1].s_name,st[j].s_name);
strcpy(st[j].s_name,name);
strcpy(sex,st[j+1].s_sex);
strcpy(st[j+1].s_sex,st[j].s_sex);
strcpy(st[j].s_sex,sex);
strcpy(year,st[j+1].s_year);
strcpy(st[j+1].s_year,st[j].s_year);
strcpy(st[j].s_year,year);
strcpy(month,st[j+1].s_month);
strcpy(st[j+1].s_month,st[j].s_month);
strcpy(st[j].s_month,month);
strcpy(day,st[j+1].s_day);
strcpy(st[j+1].s_day,st[j].s_day);
strcpy(st[j].s_day,day);
strcpy(tel,st[j+1].s_tel);
strcpy(st[j+1].s_tel,st[j].s_tel);
strcpy(st[j].s_tel,tel);
strcpy(qq,st[j+1].s_qq);
strcpy(st[j+1].s_qq,st[j].s_qq);
strcpy(st[j].s_qq,qq);
}
}
}
for(int h=0;h<num;h++)
print(h);
}

void addStudent(student &s){
num++;
int x=1;
int y;
cout<<"输入学号(0~9十二位数字,格式:1022060013146):";
cin>>s.s_no;
cout<<"输入姓名:";
cin>>s.s_name;
cout<<"输入性别(1:男,0:女):";
cin>>s.s_sex;
cout<<"输入出生日期(格式:1987 01 01):";
cin>>s.s_year>>s.s_month>>s.s_day;
cout<<"输入手机号码(0~9十一位数字,格式:15060026654):";
cin>>s.s_tel;
cout<<"输入QQ号(0~9十位数字,格式:924890461):";
cin>>s.s_qq;
for(int i=0;i<num;i++)
{
if(!strcmp(st[i].s_no,""))
{
strcpy(st[i].s_no,s.s_no);
strcpy(st[i].s_name,s.s_name);
strcpy(st[i].s_sex,s.s_sex);
strcpy(st[i].s_year,s.s_year);
strcpy(st[i].s_month,s.s_month);
strcpy(st[i].s_day,s.s_day);
strcpy(st[i].s_tel,s.s_tel);
strcpy(st[i].s_qq,s.s_qq);
y=i;
x=0;
cout<<endl<<endl;
cout<<"第"<<num<<"学生的基本信息添加成功!"<<endl;
print(y);
}

if(x==0)
{
break;
}
}
}
void deleteStudent(student &s){
cin>>s.s_no;
int x=1;
for(int i=0;i<num;i++){
if(!strcmp(st[i].s_no,s.s_no))
{
strcpy(st[i].s_no,"");
strcpy(st[i].s_name,"");
strcpy(st[i].s_sex,"");
strcpy(st[i].s_year,"");
strcpy(st[i].s_month,"");
strcpy(st[i].s_day,"");
strcpy(st[i].s_tel,"");
strcpy(st[i].s_qq,"");
num--;
cout<<"删除成功";
for(int j=i;j<num;j++){
strcpy(st[j].s_no,st[j+1].s_no);
strcpy(st[j].s_name,st[j+1].s_name);
strcpy(st[j].s_sex,st[j+1].s_sex);
strcpy(st[j].s_year,st[j+1].s_year);
strcpy(st[j].s_month,st[j+1].s_month);
strcpy(st[j].s_day,st[j+1].s_day);
strcpy(st[j].s_tel,st[j+1].s_tel);
strcpy(st[j].s_qq,st[j+1].s_qq);
}
return;
}
else x=0;
}

if(x==0)
cout<<"在该班没有该学生!";
}
void findAllStudent(){
print();
}
void findStudentFromNo(student &s){
lable2:
cout<<"输入你要查找的学生的学号:"<<endl;
cin>>s.s_no;
int x;
for(int k=0;k<num;k++)
if(!strcmp(st[k].s_no,s.s_no))
{
print(k);
x=1;
return;
}else{
x=0;
}
if(x==0){
cout<<"没有找到该学号!"<<endl;
goto lable2;
}
}
};
int StudentContact::num=0;
int main(){
StudentContact stc;
student stu;
while(1){
int key;
int findSwitchKey;
stc.display();
// labl:
cout<<"请选择操作(1~4),(5)退出"<<endl;
cin>>key;
if(key>=1 && key<=5)
switch(key)
{
case 1:
cout<<" 输入添加的资料:"<<endl;
stc.addStudent(stu);
break;
case 2:
if(stc.num>0){
cout<<"输入学生的学号:"<<endl;
stc.deleteStudent(stu);
}
else
cout<<"该班没有学生!删除失败。";
break;
case 3:
labe1:
cout<<"请选择操作(1~2),(1:按学号查找学生的基本信息,2:查找所用学生的基本信息)"<<endl;
cin>>findSwitchKey;
if(findSwitchKey>=1&&findSwitchKey<=2)
switch(findSwitchKey){
case 1:
stc.findStudentFromNo(stu);
break;
case 2:
stc.findAllStudent();
break;
}
else{
cout<<"你的输入有误请重新输入!"<<endl<<endl;
goto labe1;
}
break;
case 4:cout<<"";
break;
case 5:{
cout<<"感谢你使用本系统!"<<endl;
exit(1);
}
}
else{
cout<<"你的输入为:"<<"该输入有误!请输入正确的操作(1~5)"<<endl<<endl;
// goto labl;
continue;
}
}
return 0;
}

转载于:https://www.cnblogs.com/cqhstyle/p/4777513.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值