为了答辩被迫营业的
话说好久也没更了,出来冒个泡QAQ
写了快几个小时(主要是想写的好看点)
详细的注释里面都有,避重就轻 几乎没怎么用指针,但其实用了也就是分配内存的玩意
纯粹的傻瓜式系统,用了一个全局变量。
顺带提一句,学语言基础从C开始,底层逻辑语言,因为语法简单,同时也核心,再自己学一点C++(因为你会想要偷懒的)
然后转java就是驾轻就熟了。本来是想用java写的
博主🐧2325131626 博主不是技术宅,算半个文科生了
最后谢谢小分队的努力。
废话不多说,我们上代码(doge)和运行结果
//根据C和C++的语言特性来编写的一套简易的学生信息系统
//程序设计浅显易懂 所有方法均采用了无参传入
//运用到了结构体 递归,部分指针知识,冒泡排序 字符串运用。
//本程序秉持着易懂的原理,避免了大量指针的引用,因而增加了代码的冗余
// main函数的实现方法只有4行,因而很多程序的代码块分工明显。
//欢迎改变改写以及提问 QQ2325131626 爱写代码的小权,过来交个朋友嘛QAQ
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<windows.h>
#define OK 1;
int num;
using namespace std;
//创造"学生结构体"相当于C++和java中的对象,其中的名字,学号,性别,专业为其属性
struct Student{
char id[1000];
char name[1000];
char sex[1000];
char major[1000];
}stu[1000];
void welcome_menu();//欢迎界面
int login();//登录界面
void nevigate();//主菜单导航功能
void InsertInfo();//插入信息功能
void Search();//查询功能
void Traverse();//遍历
void Sort();//学生信息排序
void DeleteInfo();//学生信息删除
void Modify();//学生信息修改
void classification();//学生信息分类
void returnOrder();//返回命令
//学生人数初始化为0,全局变量
void welcome_menu()
{
//欢迎界面
system("cls");
printf("\n\n\n");
printf("\t*******************************************************\n\n");
printf("\t **欢迎各位小姐姐小哥哥们使用SWPU学生系统**\n\n");
cout << "本程序由你的权神编写,权哥yyds!QQ2325131626,欢迎加我QAQ,工具人罢了。"<<endl;
printf("\t **** * * * *** * *\n");
printf("\t * * ** * * * * *\n");
printf("\t * * * * * * * * *\n");
printf("\t * * * * * * * * *\n");
printf("\t * * * * * * * *\n");
printf("\t * * * * * * * *\n");
printf("\t **** * * * * * * *\n");
printf("\n\n\n");
system("pause");
}
//登录菜单
int login()
{
int account, password;
cout << "请输入您的账号和密码"<<endl;
cout << "账号:";
cin >> account;
cout << "密码:";
cin >> password;
if (account !=2020 || password !=2020) {
cout << "您的密码错误,请重新输入";
return login();
}
cout << "登陆成功,正在进入学生管理系统"<<endl;
system("pause");
return OK;
}
//导航菜单
void nevigate() {
int x;
system("cls");
while (1) {
printf("\t|*****脱贫攻坚小分队学生管理系统*****|\n");
cout << endl;
printf("\t|**********************|\n");
cout << endl;
printf("\t|***学生系统功能菜单***|\n");
cout << endl;
printf("\t|1---学生信息插入|\n");
cout << endl;
printf("\t|2---学生信息排序|\n");
cout << endl;
printf("\t|3---学生信息查询|\n");
cout << endl;
printf("\t|4---学生信息删除|\n");
cout << endl;
printf("\t|5---学生分类查询|\n");
cout << endl;
printf("\t|6---学生信息修改|\n");
cout << endl;
printf("\t|0--- 退出|\n");
cout << endl;
printf("\t|**********************|\n\n");
cout << endl << endl;
cout << "请输入您想要进行操作的数字" << endl;
cin >> x;
if (x == 1) {
cout << "**** 您选择的是:学生信息插入 **** " << endl;
InsertInfo();
}
else if (x == 2) {
cout << "**** 您选择的是:学生信息排序 **** " << endl;
Sort();
}
else if (x == 3) {
cout << "**** 您选择的是:学生信息查询 **** " << endl;
Search();
}
else if (x == 4) {
cout << "**** 您选择的是:学生信息删除 ****" << endl;
DeleteInfo();
}
else if (x == 5) {
cout << "**** 您选择的是:学生分类查询 ****" << endl;
classification();
}
else if (x == 6) {
cout << "**** 您选择的是:学生信息修改 ****" << endl;
Modify();
}
else if (0 == x) {
exit(1);
}
else {
cout << "您输入的字符有误,请您重新输入";
return nevigate();
}
}
}
void InsertInfo() {
cout << "请你依次输入学生的学号,姓名,性别,专业" << endl;
cout << "学号:";
cin >> stu[num].id;
cout << "姓名:";
cin >> stu[num].name;
cout << "性别:";
cin >> stu[num].sex;
cout << "专业:";
cin >> stu[num].major;
cout << "您输入的信息如下" << endl;
cout << "学号:"<< stu[num].id <<" " << "姓名:" << stu[num].name <<" " << "性别:" << stu[num].sex <<" " << "专业:" << stu[num].major<<endl;
num++;
}
void Search() {
int x;
cout << "请输入您想进行的操作,用操作前的数字"<<endl;
cout << "1--查询所有信息 "<<endl;
cout << "2--按照学号查询 "<<endl;
cout << "3--按照姓名查询 "<<endl;
cin >> x;
if (1 == x) {
char i;
cout << "下面是学生的个人信息遍历"<<endl;
Traverse();
cout << endl;
cout << "按'Y'(同意)返回上一层,或N(结束)或按'0'返回主导航菜单"<<endl;
cin >> i;
if (i == 'Y') {
return Search();
}
else if (i == 'N') {
exit(1);
}
else if (i == '0') {
return nevigate();
}
else {
cout << "您输入的键位有误, 默认结束";
system("pause");
exit(1);
}
}
else if (2 == x) {
cout << "请输入您要查询的学号是";
char auxid[1000];
cin >> auxid;
for (int i = 0; i < num; i++)
{
if (strcmp(auxid,stu[i].id)==0) {
cout << "您所要查询的学生信息如下:" << endl;
cout << "学号:" << stu[i].id << " " << "姓名:" << stu[i].name << " " << "性别:" << stu[i].sex << " " << "专业:" << stu[i].major << endl;
}
if (strcmp(auxid,stu[i].id)!=0&& i == num) {
cout << "没有找到符合的学生信息" << endl;
cout << "即将返回上一层" << endl;
system("pause");
return Search();
}
}
}
else if (3 == x) {
cout << "请输入您要查询的姓名是";
char auxname[1000];
cin >> auxname;
for (int i = 0; i < num; i++)
{
if (strcmp(auxname, stu[i].name) == 0) {
cout << "您所要查询的学生信息如下:" << endl;
cout << "学号:" << stu[i].id << " " << "姓名:" << stu[i].name << " " << "性别:" << stu[i].sex << " " << "专业:" << stu[i].major << endl;
}
if (strcmp(auxname, stu[i].name) != 0 && i == num) {
cout << "没有找到符合的学生信息" << endl;
cout << "即将返回上一层" << endl;
system("pause");
return Search();
}
}
}
else { cout << "您输入的键位有误,请重新输入";
return Search();
}
}
void DeleteInfo() {
cout << "这是以上学生的信息" << endl;
Traverse();
cout << "请输入您想要删除学生的学号" << endl;
char deleteid[1000];
int cnt = 0;
char temp;
cin >> deleteid;
for (int i = 0; i < num; i++)
{
if (strcmp(deleteid, stu[i].id) == 0) {
for (int j = i; j < num - 1; j++)
{
stu[j] = stu[j + 1];
}
num--;
cout << "这是删除过后的学生信息"<<endl;
Traverse();
cnt++;
}
}
if (0==cnt) {
cout << "没有找到此学生的信息"<<endl;
cout << "按Y即将返回上层,按N退出,其他键为返回主菜单"<<endl;
cin >> temp;
if (temp == 'Y') {
return DeleteInfo();
}
else if (temp == 'N') {
exit(1);
}
else {
return nevigate();
}
}
}
//遍历方法
void Traverse() {
if (num == 0) { cout << "学生信息为空!"; }
if (num != 0) {
for (int i = 0; i < num; i++)
{
cout << "学号:" << stu[i].id << " " << "姓名:" << stu[i].name << " " << "性别:" << stu[i].sex << " " << "专业:" << stu[i].major << endl;
}
}
}
//按照性别专业查询(其实改一下这个方法至少可以省20-30行代码)
//我太强调用男还是用女了,不知道有没有哪个调皮人给我输不男不女的。。。
void classification() {
cout << "请输入您想要查询的类别" << endl;
cout << "1--按照性别查询" << endl;
cout << "2--按照专业查询" << endl;
int cnt1 = 0, cnt2 = 0, cnt3 = 0;
//这里强调以下三个计数器问题,这是一个计算机基本也重要思想(最坏情况思想)
//由于计算机要考虑到最坏情况,我们要假设遍历完所有的数字中都没有得到自己想要的值
//这时需要一个辅助计数器,如果在20个之中找到了自己的值,则计数器增1
//如果增1,则后面语句不执行!!
int temp;
cin >> temp;
if (1 == temp) {
cout << "请输入您要查询的性别是:'男','女'" << endl;
char auxsex[100];
cin >> auxsex;
if (strcmp(auxsex, "男") == 0) {
for (int i = 0; i < num; i++)
{
if (strcmp(stu[i].sex, "男") == 0) {
cout << "学号:" << stu[i].id << " " << "姓名:" << stu[i].name << " " << "性别:" << stu[i].sex << " " << "专业:" << stu[i].major << endl;
cnt1++;
}
}
if (cnt1 == 0) {
cout << "抱歉,没有该条件的信息提供" << endl;
char temp1;
cout << "按Y即将返回上层,按N退出,其他键默认退回导航菜单键" << endl;
cin >> temp1;
if (temp1 == 'Y') {
return classification();
}
else if (temp1 == 'N') {
exit(1);
}
else {
return nevigate();
}
}
}
else if (strcmp(auxsex, "女") == 0) {
for (int i = 0; i < num; i++)
{
if (strcmp(stu[i].sex, "女") == 0) {
cout << "学号:" << stu[i].id << " " << "姓名:" << stu[i].name << " " << "性别:" << stu[i].sex << " " << "专业:" << stu[i].major << endl;
cnt2++;
}
}
if (cnt2 == 0) {
cout << "抱歉,没有该条件的信息提供" << endl;
char temp2;
cout << "按Y即将返回上层,按N退出,其他键默认退回导航菜单键" << endl;
cin >> temp2;
if (temp2 == 'Y') {
return classification();
}
else if (temp2 == 'N') {
exit(1);
}
else {
return nevigate();
}
}
}
else {
cout << "您输入的键位有误" << endl;
int temp3;
cout << "按Y即将返回上层,按N退出" << endl;
cin >> temp3;
if (temp3 == 'Y') {
return classification();
}
else if (temp3 == 'N') {
exit(1);
}
else {
cout << "您输入的键位有误,默认返回导航菜单键";
return nevigate();
}
}
}
else if (2 == temp) {
cout << "下面是总共学生信息";
Traverse();
cout << "请输入您要查询的专业是" << endl;
char auxmajor[1000];
cin >> auxmajor;
for (int i = 0; i < num; i++)
{
if (strcmp(auxmajor, stu[i].major) == 0) {
cout << "学号:" << stu[i].id << " " << "姓名:" << stu[i].name << " " << "性别:" << stu[i].sex << " " << "专业:" << stu[i].major << endl;
cnt3++;
}
}
if (cnt3 == 0) {
cout << "抱歉,无法查询到符合条件的学生信息!" << endl;
char temp4;
cout << "按Y即将返回上层,按N退出" << endl;
cin >> temp4;
if (temp4 == 'Y') {
return DeleteInfo();
}
else if (temp4 == 'N') {
exit(1);
}
else {
cout << "您输入的键位有误,默认返回导航菜单键";
return nevigate();
}
}
else {
cout << "您输入的键位有误" << endl;
char temp;
cout << "按Y即将返回上层,按N退出" << endl;
cin >> temp;
if (temp == 'Y') {
return DeleteInfo();
}
else if (temp == 'N') {
exit(1);
}
else {
cout << "您输入的键位有误,默认返回导航菜单键";
return nevigate();
}
}
}
}
//修改学生信息,其实和关键字一样
void Modify() {
cout << "以下是所有的学生信息";
Traverse();
cout << "请输入您想要修改的学生学号";
char auxid[1000];
cin >> auxid;
int cnt1 = 0;
for (int i = 0; i < num; i++)
{
if (strcmp(auxid, stu[i].id) == 0) {
cout << "学号:" << stu[i].id << " " << "姓名:" << stu[i].name << " " << "性别:" << stu[i].sex << " " << "专业:" << stu[i].major << endl;
cout << "请你依次输入学生新的信息"<< endl;
cout << "学号:";
cin >> stu[i].id;
cout << "姓名:";
cin >> stu[i].name;
cout << "性别:";
cin >> stu[i].sex;
cout << "专业:";
cin >> stu[i].major;
cout << "更新学生信息如下" << endl;
cout << "学号:" << stu[i].id << " " << "姓名:" << stu[i].name << " " << "性别:" << stu[i].sex << " " << "专业:" << stu[i].major << endl;
cnt1++;
}
}
if (0 == cnt1) {
cout << "抱歉,没有找到此类学生的信息" << endl;
cout << "即将返回上层...";
system("pause");
return Modify();
}
}
//一个简单的冒泡排序思想
void Sort() {
char tempname[100];
char tempid[100];
char tempmajor[100];
char tempsex[100];
cout << "目前仅支持按照学号进行排序" << endl;
cout << "以下是所有学生的信息" << endl;
Traverse();
for (int i = 0; i < num-1; i++)
{
for (int j = 0; j < num-1; j++)
{
if (strcmp(stu[j].id, stu[j + 1].id) > 0) {
strcpy_s(tempid, stu[j].id);
strcpy_s(stu[j].id,stu[j+1].id);
strcpy_s(stu[j + 1].id, tempid);
strcpy_s(tempname, stu[j].name);
strcpy_s(stu[j].name, stu[j + 1].name);
strcpy_s(stu[j + 1].name, tempname);
strcpy_s(tempsex, stu[j].sex);
strcpy_s(stu[j].sex, stu[j + 1].sex);
strcpy_s(stu[j + 1].sex, tempsex);
strcpy_s(tempmajor, stu[j].major);
strcpy_s(stu[j].major, stu[j + 1].major);
strcpy_s(stu[j + 1].major, tempmajor);
}
}
}
cout << "排序后的信息如下" << endl;
Traverse();
char temp;
cout << "按Y即将返回上层,按N退出,按'其他’返回菜单导航" << endl;
cin >> temp;
if (temp == 'Y') {
return Sort();
}
else if (temp == 'N') {
exit(1);
}
else {
cout << "返回导航菜单键...";
system("pause");
return nevigate();
}
}
//实现代码只有4行
int main() {
welcome_menu();
if (login()){
nevigate();
}
}
      
|