标题 学生管理系统
#define _CRT_SECURE_NO_WARNINGS
#include <malloc.h>
#include
#include <stdio.h>
#include <stdlib.h>
#include
#include
using namespace std;
void mainmenu();
void query_by_name();
void print_student(struct student *s);
typedef struct student
{
long int num; //学号
char name[20]; //姓名
int age; //年龄
char sex[10]; //性别
char birthday[20]; //出生日期
char address[30]; //地址
long long int tele_num; //电话
char E_mail[30]; //电子邮箱地址
struct student* next; //指向下一个结构体对象的指针
}student;
//创建一个学生链表
typedef struct student_lsit{
student head;
int count;
}s_list;
//声明一个链表
s_list list;
int count = 0;
void query_by_num(const s_list lt, const int num_01);
void query_by_name(const s_list ls);
void del(s_list* p);
void change(s_list lt);
void devise(struct student* p);
//录入一个学生的信息
void record(s_list*p)
{
int i = 0;
student* temp = &(p->head);
while (i<p->count)
{
temp = temp->next;
i++;
}
student* st = (student*)malloc(sizeof(student));
cout << "请输入学生学号:";
cin >> st->num;
cout << "请输入学生姓名:";
cin >> st->name;
cout << "请输入学生年龄:";
cin >> st->age;
cout << "请输入学生性别:";
cin >> st->sex;
cout << "请输入学生出生日期:";
cin >> st->birthday;
cout << "请输入学生地址:";
cin >> st->address;
cout << "请输入学生电话:";
cin >> st->tele_num;
cout << "请输入学生邮箱:";
cin >> st->E_mail;
st->next = temp->next;
temp->next = st;
p->count++;
cout << "该学生的信息为" << endl;
cout << "---------------------------------------------" << endl;
print_student(st);
st->next = NULL;
return ;
}
int strcmp_01(char* p1, char* p2) {
// 指针形参判空
if (p1 == NULL || p2 == NULL)
{
printf(" 函数 int strcmp_01( char* p1, char* p2 );有形参为空,没有继续执行的必要\n");
return -1;
}
int i = 0;
while (p1[i] != '\0' && p2[i] != '\0')
{
if (p1[i] != p2[i])
{
return 0;
}
else
{
i++;
}
}
if (p1[i] == '\0' && p2[i] == '\0')
{
return 1;
}
else
{
return 0;
}
}
int aa = 0;
void welcome() {
cout<<"\n±-------------------------------------------+"<< endl;
cout << “| |” << endl;
cout << “| 欢迎使用学生信息管理 |” << endl;
cout << “| |” << endl;
cout << “±-------------------------------------------+” << endl;
cout << "\n管理员初始用户名密码均为admin,您有3次输入机会!" << endl;
char userName[10];
char userPWD[10];
char Name[10] = "admin";
cout << "请输入用户名:" ;
cin >> userName;
cout << "\n" << endl;
cout << "请输入用户密码:";
cin >> userPWD;
if (strcmp_01(userName,Name)==1&&strcmp_01(userPWD,Name)==1)
{
cout << "登录成功" << endl;
mainmenu();
}
else
{
cout << "文件错误,登录失败" << endl;
aa++;
if (aa>2)
{
cout << "输入错误次数超过3次!" << endl;
}
else
{
welcome();
}
}
return;
}
//浏览全部信息
void displayAll(const s_list lt) {
student* temp = lt.head.next;
if (lt.count==0)
{
cout << "信息栏里无任何学生信息,请录入!" << endl;
}
cout << std::left << setw(8) << "学号" << std::left << setw(8) <<
"姓名" << std::left << setw(8) << "年龄" << std::left << setw(8) << "性别" << std::left
<< setw(10) << "出生年月" << std::left << setw(11) << "地址" << std::left << setw(8) << "电话"
<< std::left << setw(12) << "E-mail" << endl;
cout << "-----------------------------------------------------------------------" << endl;
while (temp!=NULL)
{
cout << std::left << setw(8) << temp->num << std::left <<
setw(8) << temp->name << std::left << setw(8) << temp->age << std::left << setw(8)
<< temp->sex << std::left << setw(10) << temp->birthday << std::left << setw(11) << temp->address
<< std::left << setw(8) << temp->tele_num << std::left << setw(10) << temp->E_mail << endl;
temp = temp->next;
}
cout <<"学生总数为:"<< lt.count<<endl;
}
//查询
void query() {
cout << “\n±-------------------------------+” << endl;
cout << “| 按学号查询 请按 1 |” << endl;
cout << “| 按姓名查询 请按 2 |” << endl;
cout << “| 取消 请按 0 |” << endl;
cout << “±-------------------------------+” << endl;
int b = 0;
cout << “请输入您的选择:”;
cin >> b;
switch (b)
{
case 1:
int num_01;
cout << “请输入要查询的学号:”;
cin >> num_01;
query_by_num(list,num_01);
cout << “按任意字符键返回主菜单!”;
char j;
cin >> j;
if (j) {
mainmenu();
}
break;
case