幼儿园班级信息管理系统

#include<iostream>
#include<fstream>
#include<cstring>
#define N 1000  
using namespace std;
class staff
{
public:
	char name[20];//姓名
	char birthday[20];//出生年月
	char sex[20];//性别
	char address[20];//住址
	float height;//身高
	float weight;//体重
	char father[20];//父亲姓名
	char monther[20];//母亲姓名
	char father_phone[20];//父亲联系方式
	char monther_phone[20];//母亲联系方式
	char info[20];//备注


	void show()
	{
		cout << "姓名:" << name << "  "
			<< "出生年月:" << birthday << "  "
			<< "性别:" << sex << "  "
			<< "住址:" << address << "  "
			<< "身高:" << height << "  "
			<< "体重:" << weight << "  "
			<< "父亲姓名:" << father << "  "
			<< "母亲姓名:" << monther << "  "
			<< "父亲联系方式:" << father_phone << "  "
			<< "母亲联系方式:" << monther_phone << "  "
			<< "任务备注内容:" << info << endl;

	}
};

class staff_List
{
private:
	staff* s;
	int n;//当前记录的职工人数
public:
	staff_List()
	{
		n = 0;
		s = new staff[N];
	}
	void add();//添加小朋友信息
	void change();//更改小朋友信息
	void deleate();//删除小朋友信息
	void find_father_monther();//查找小朋友父母信息
	void find_address();//查找小朋友住址信息
	void sort_weight();//小朋友体重排序
	void sort_height();//小朋友身高排序
	void show();//统计男女生比例
	void save();//保存信息
	void read();//读取信息
	void menu();//菜单

};

//菜单
void staff_List::menu()
{
	cout << "****************************************************" << endl;
	cout << "****************幼儿园班级信息管理系统**************" << endl;
	cout << "****************  1.添加小朋友信息    **************" << endl;
	cout << "****************  2.更改小朋友信息    **************" << endl;
	cout << "****************  3.删除小朋友信息    **************" << endl;
	cout << "****************  4.查找小朋友父母信息**************" << endl;
	cout << "****************  5.查找小朋友住址信息**************" << endl;
	cout << "****************  6.小朋友体重排序    **************" << endl;
	cout << "****************  7.小朋友身高排序    **************" << endl;
	cout << "****************  8.保存小朋友信息    **************" << endl;
	cout << "****************  9.读取小朋友信息    **************" << endl;
	cout << "****************  10.统计男女生比例   **************" << endl;
	cout << "****************  0.退出管理系统      **************" << endl;
	cout << "****************************************************" << endl;
}

//增加小朋友信息
void staff_List::add()
{
	cout << "请输入小朋友信息:" << endl;

	cout << "请输入姓名:";
	cin >> s[n].name;
	for (int i = 0; i < n; i++)
	{
		if (s[n].name == s[i].name)
		{
			cout << "存在该信息,添加失败!" << endl;
			return;
		}
	}

	cout << "请输入出生年月:";
	cin >> s[n].birthday;
	cout << "请输入性别:";
	cin >> s[n].sex;
	cout << "请输入住址:";
	cin >> s[n].address;
	cout << "请输入身高:";
	cin >> s[n].height;
	cout << "请输入体重:";
	cin >> s[n].weight;
	cout << "请输入父亲姓名:";
	cin >> s[n].father;
	cout << "请输入母亲姓名:";
	cin >> s[n].monther;
	cout << "请输入父亲联系电话:";
	cin >> s[n].father_phone;
	cout << "请输入母亲联系电话:";
	cin >> s[n].monther_phone;
	cout << "请输入备注:";
	cin >> s[n].info;


	n++;
	cout << "添加小朋友信息成功!" << endl;
}

//修改小朋友信息
void staff_List::change()
{
	if (n <= 0)
	{
		cout << "没有小朋友信息,系统将返回主菜单,请先录入!" << endl;
		return;
	}
	cout << "请输入需要修改的小朋友姓名:" << endl;
	char name[20];
	cin >> name;

	for (int i = 0; i < n; i++)
	{
		if (!strcmp(name,s[i].name))
		{
			cout << "请输入出生年月:";
			cin >> s[i].birthday;
			cout << "请输入性别:";
			cin >> s[i].sex;
			cout << "请输入住址:";
			cin >> s[i].address;
			cout << "请输入身高:";
			cin >> s[i].height;
			cout << "请输入体重:";
			cin >> s[i].weight;
			cout << "请输入父亲姓名:";
			cin >> s[i].father;
			cout << "请输入母亲姓名:";
			cin >> s[i].monther;
			cout << "请输入父亲联系电话:";
			cin >> s[i].father_phone;
			cout << "请输入母亲联系电话:";
			cin >> s[i].monther_phone;
			cout << "请输入备注:";
			cin >> s[i].info;

			cout << "修改成功!" << endl;
			return;
		}
	}
	cout << "不存在该信息!" << endl;
}

//删除小朋友信息
void staff_List::deleate()
{
	if (n <= 0)
	{
		cout << "没有小朋友信息,系统将返回主菜单,请先录入!" << endl;
		return;
	}
	cout << "请输入需要删除的小朋友姓名:" << endl;
	char name[20];
	cin >> name;

	for (int i = 0; i < n; i++)
	{
		if (!strcmp(name, s[i].name))
		{
			for (int j = i; j < n - 1; j++)
			{
				s[j] = s[j + 1];
			}
			n--;
			cout << "删除成功!" << endl;
			return;
		}
	}
	cout << "不存在该信息!" << endl;
}

//查找小朋友父母信息
void staff_List::find_father_monther()
{
	if (n <= 0)
	{
		cout << "没有小朋友信息,系统将返回主菜单,请先录入!" << endl;
		return;
	}

	int temp = 0;
	cout << "请输入需要查询的姓名:" << endl;
	char name[20];
	cin >> name;

	for (int i = 0; i < n; i++)
	{
		if (!strcmp(name, s[i].name))
		{
			temp++;

			cout << "父亲姓名:" << s[i].father << "  "
				<< "母亲姓名:" << s[i].monther << "  "
				<< "父亲联系方式:" << s[i].father_phone << "  "
				<< "母亲联系方式:" << s[i].monther_phone << endl;
			return;
		}
	}
	if (temp == 0)
	{
		cout << "不存在该信息!" << endl;

	}
}

//查找小朋友住址信息
void staff_List::find_address()
{
	if (n <= 0)
	{
		cout << "没有小朋友信息,系统将返回主菜单,请先录入!" << endl;
		return;
	}

	int temp = 0;
	cout << "请输入需要查询的姓名:" << endl;
	char name[20];
	cin >> name;

	for (int i = 0; i < n; i++)
	{
		if (!strcmp(name, s[i].name))
		{
			temp++;

			cout << "小朋友住址:" << s[i].address << endl;
			return;
		}
	}
	if (temp == 0)
	{
		cout << "不存在该信息!" << endl;

	}
}

//统计男女生比例
void staff_List::show()
{
	if (n <= 0)
	{
		cout << "没有小朋友信息,系统将返回主菜单,请先录入!" << endl;
		return;
	}
	else
	{
		int boy = 0;
		int girl = 0;
		for (int i = 0; i < n; i++)
		{
			if (!strcmp("男", s[i].sex))
			{
				boy++;
			}
			if (!strcmp("女", s[i].sex))
			{
				girl++;
			}
		}

		cout << "男女生比例为:" << boy << ":" << girl << endl;
	}
}

//保存小朋友信息
void staff_List::save()
{
	ofstream outFile;
	outFile.open("staff.txt");
	int i = 0;
	for (i = 0; i < n; i++)
	{
		outFile << s[i].name << " "
			<< s[i].birthday << " "
			<< s[i].sex << " "
			<< s[i].address << " "
			<< s[i].height << " "
			<< s[i].weight << " "
			<< s[i].father << " "
			<< s[i].monther << " "
			<< s[i].father_phone << " "
			<< s[i].monther_phone << " "
			<< s[i].info << endl;


	}
	cout << "文件保存成功!" << endl;
	outFile.close();
}

//读取小朋友信息
void staff_List::read()
{
	ifstream in("staff.txt", ios::in);
	if (!in.is_open())
	{
		cout << "打开文件失败" << endl;
		return;
	}
	while (!in.eof())
	{
		in >> s[n].name
			>> s[n].birthday
			>> s[n].sex
			>> s[n].birthday 
			>> s[n].height
			>> s[n].weight
			>> s[n].father
			>> s[n].monther
			>> s[n].father_phone
			>> s[n].monther_phone
			>> s[n].info;


		n++;
	}
	n--; 

	cout << "文件导入成功!" << endl;
	in.close();
}

//小朋友体重排序
void staff_List::sort_weight()
{
	if (n <= 0)
	{
		cout << "没有小朋友信息,系统将返回主菜单,请先录入!" << endl;
		return;
	}
	else
	{
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n - 1 - i; j++)
			{
				if (s[j].weight > s[j + 1].weight)
				{
					staff ss = s[j];
					s[j] = s[j + 1];
					s[j + 1] = ss;
				}
			}

		}

		cout << "排序信息如下:" << endl;
		for (int i = 0; i < n; i++)
		{
			s[i].show();
		}
	}
}

//小朋友身高排序
void staff_List::sort_height()
{
	if (n <= 0)
	{
		cout << "没有小朋友信息,系统将返回主菜单,请先录入!" << endl;
		return;
	}
	else
	{
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n - 1 - i; j++)
			{
				if (s[j].height > s[j + 1].height)
				{
					staff ss = s[j];
					s[j] = s[j + 1];
					s[j + 1] = ss;
				}
			}

		}

		cout << "排序信息如下:" << endl;
		for (int i = 0; i < n; i++)
		{
			s[i].show();
		}
	}
}


//主函数
int main()
{
	staff_List s;
	int a;
	while (1) {
		s.menu();
		cout << "请选择功能编号0-10" << endl;
		cin >> a;
		if (a < 0 || a > 10)
		{
			cout << "输入错误,请选择有效指令0-10!" << endl;
			cin >> a;
		}
		switch (a) {
		case 1:
			s.add();
			break;
		case 2:
			s.change();
			break;
		case 3:
			s.deleate();
			break;
		case 4:
			s.find_father_monther();
			break;
		case 5:
			s.find_address();
			break;
		case 6:
			s.sort_weight();
			break;
		case 7:
			s.sort_height();
			break;
		case 8:
			s.save();
			break;
		case 9:
			s.read();
			break;
		case 10:
			s.show();
			break;
		case 0:
			cout << "谢谢使用!" << endl;
			exit(0);
		}
	}
	return 0;
}

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值