学生管理系统(雏形)c++

先这样,之后改

#include<iostream>
#include<string>
#define MAX 1000
using namespace std;
struct Student
{
	string name;
	int sex;
	int id;
	string phone;
	string addr;
	int score[6];
};
struct StudentBook
{
	struct Student studentarray[MAX];
	int size;
};
//添加
void addStudent(StudentBook* abs)
{
	if (abs->size == MAX)
	{
		cout << "内容已满" << endl;
		return;
	}
	else
	{
		//name
		string name;
		cout << "input name" << endl;
		cin >> name;
		abs->studentarray[abs->size].name = name;
		//sex
		cout << "input sex" << endl;
		cout << "1 --- man " << " 2 --- woman" << endl;
		int s_sex = 0;
		cin >> s_sex;
		while (true)
		{
			if (s_sex == 1 || s_sex == 2)
			{
				abs->studentarray[abs->size].sex = s_sex;
				break;
			}
			else
			{
				cout << "error " << " please input 1 or 2" << endl;
			}
		}
		//id
		cout << "input id " << endl;
		int s_id = 0;
		cin >> s_id;
		abs->studentarray[abs->size].id = s_id;
		//phone
		cout << "input phone" << endl;
		string s_phone;
		cin >> s_phone;
		abs->studentarray[abs->size].phone = s_phone;
		//add
		cout << "input address" << endl;
		string s_add;
		cin >> s_add;
		abs->studentarray[abs->size].addr = s_add;
		//score
		cout << "input 6 subjects score " << endl;
		int s_score[6];
		for (int i = 0; i < 6; i++)
		{
			cout << "input "<< i+1 <<" subjects score:" << endl;
			cin >> s_score[i];
			abs->studentarray[abs->size].score[i] = s_score[i];
		}
		abs->size++;
		cout << "恭喜添加成功" << endl;
		system("pause");
		system("cls");
	}
}
//显示
void showStudent(StudentBook* abs)
{
	if (abs->size == 0)
	{
		cout << "当前无人" << endl;
	}
	else
	{
		for (int i = 0; i < abs->size; i++)
		{
			cout << "name: " << abs->studentarray[i].name << "\t";
			cout << "sex: " << (abs->studentarray[i].sex == 1 ? "男" : "女") << "\t";
			cout << "id: " << abs->studentarray[i].id << "\t";
			cout << "phone: " << abs->studentarray[i].phone << "\t";
			cout << "address: " << abs->studentarray[i].addr << "\t";
			for (int j = 0; j < 6; j++)
			{
				cout << "score No."<<j+1 <<" subject :"<< abs->studentarray[i].score[j] << "\t";
			}
			cout <<""<<endl;
			
		}
	}
	system("pause");
	system("cls");
}
//判断学生是否存在
int isExist(StudentBook* abs, string s_name)
{
	for (int i = 0; i < abs->size; i++)
	{
		if (abs->studentarray[i].name == s_name)
		{
			return i;
		}
	}
	return -1;
}
//删除学生
void deleteStudent(StudentBook* abs)
{
	cout << "input delete student:" << endl;
	string s_name;
	cin >> s_name;
	int ret = isExist(abs, s_name);
	if (ret != -1)
	{
		for (int i = ret; i < abs->size; i++)
		{
			abs->studentarray[i] = abs->studentarray[i + 1];
		}
		abs->size--;
		cout << "删除成功" << endl;
	}
	else
	{
		cout << "查无此人" << endl;
	}
	system("pause");
	system("cls");
 }
//查找
void findStudent(StudentBook* abs)
{
	string s_name;
	cout << "input find name :" << endl;
	cin >> s_name;
	int i = isExist(abs, s_name);
	if (i !=-1)
		{
			cout << "name: " << abs->studentarray[i].name << "\t";
			cout << "sex: " << (abs->studentarray[i].sex == 1 ? "男" : "女") << "\t";
			cout << "id: " << abs->studentarray[i].id << "\t";
			cout << "phone: " << abs->studentarray[i].phone << "\t";
			cout << "address:" << abs->studentarray[i].addr << "\t";
			for (int j = 0; j < 6; j++)
			{
				cout << "score No." << j + 1 << " subject :" << abs->studentarray[i].score[j] << "\t";
			}
			cout << "" << endl;
		}
	else 
	{
		cout << "查无此人" << endl;
	}
	system("pause");
	system("cls");
}
//修改学生
void modifyStudent(StudentBook* abs)
{
	string s_name;
	cout << "input modify name :" << endl;
	cin >> s_name;
	int i = isExist(abs, s_name);
	if (i != -1)
	{
		//name
		string name;
		cout << "input name" << endl;
		cin >> name;
		abs->studentarray[i].name = name;
		//sex
		cout << "input sex" << endl;
		cout << "1 --- man " << " 2 --- woman" << endl;
		int s_sex = 0;
		cin >> s_sex;
		while (true)
		{
			if (s_sex == 1 || s_sex == 2)
			{
				abs->studentarray[i].sex = s_sex;
				break;
			}
			else
			{
				cout << "error " << " please input 1 or 2 " << endl;
			}
		}
		//id
		cout << "input id " << endl;
		int s_id = 0;
		cin >> s_id;
		abs->studentarray[i].id = s_id;
		//phone
		cout << "input phone " << endl;
		string s_phone;
		cin >> s_phone;
		abs->studentarray[i].phone = s_phone;
		//add
		cout << "input address " << endl;
		string s_add;
		cin >> s_add;
		abs->studentarray[i].addr = s_add;
		//score
		int s_score[6];

		for (int j = 0; j < 6; j++)
		{
			cout << "input " << i + 1 << " subjects score:" << endl;
			cin >> s_score[j];
			abs->studentarray[i].score[j] = s_score[j];
		}
		cout << "" << endl;
		cout << "恭喜添加成功" << endl;
	}
	else
	{
		cout << "查无此人" << endl;
	}
	system("pause");
	system("cls");
}
void cleanStudent(StudentBook* abs)
{
	abs->size = 0;
	cout << "链表清空" << endl;
	system("pause");
	system("cls");
}
void showMenu()
{
	cout << "1.添加学生" << endl;
	cout << "2.显示学生" << endl;
	cout << "3.删除学生" << endl;
	cout << "4.查找学生" << endl;
	cout << "5.修改学生" << endl;
	cout << "6.清空学生" << endl;
	cout << "0.退出系统" << endl;
}
int main()
{
	StudentBook abs;
	int select = 0;
	abs.size = 0;
	while (true)
	{
		showMenu();
		cin >> select;
		switch (select)
		{
		case 1:		//添加学生
			addStudent(&abs);
			break;
		case 2:		//显示学生
			showStudent(&abs);
			break;
		case 3:		//删除学生
			deleteStudent(&abs);
			break;
		case 4:		//查找学生
			findStudent(&abs);
			break;
		case 5:		//修改学生
			modifyStudent(&abs);
			break;
		case 6:		//清空学生
			cleanStudent(&abs);
			break;
		case 0:		//退出系统
			cout << "欢迎下次使用" << endl;
			system("pause");
			return 0;
			break;
		default:
			cout << "error" << endl;
			system("pause");
			system("cls");
			break;
		}
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值