c++实现一个简单的人员管理系统

c++一个简单的人员管理系统

本菜鸟根据黑马的需求自己写(没看他写的,只看了看需求)的一个管理系统
在这里插入图片描述

#include<iostream>
using namespace std;
struct Person
{
	string name;
	int age;
	string address;
};
void showMenu();
void Add(Person *p,int s);
void Display(Person p[],int s);
void Delete(Person* p, int s);
void Find(Person p[],int s);
void Modify(Person* p, int s);
void DeleteAll(Person *p,int s);
int main() {
	int select = 0;
	Person p[10];
	int s = 0;
	while (true) {
		showMenu();
		cin >> select;
		switch (select)
		{
		case 1:
			Add(p,s);
			s++;
			break;
		case 2:
			Display(p,s);
			break;
		case 3:
			Delete(p, s);
			s--;
			break;
		case 4:
			Find(p,s);
			break;
		case 5:
			Modify(p, s);
			break;
		case 6:
			DeleteAll(p, s);
			s = 0;
			break;
		case 0:
			exit(0);
		default:
			break;
		}
		//break;
	}
	return 0;
}
void showMenu() {
	cout << "1.Add" << endl;
	cout << "2.Display All" << endl;
	cout << "3.Delete someone" << endl;
	cout << "4.Find someone" << endl;
	cout << "5.Modify" << endl;
	cout << "6.Delete All" << endl;
	cout << "0.Exit" << endl;
	return;
}
void Add(Person *p,int s) {
	string name;
	int age = 0;
	string address;
	cout << "Please input name: " << endl;
	cin >> name;
	cout << "Please input age: " << endl;
	cin >> age;
	cout << "Please input address: " << endl;
	cin >> address;
	p[s].address = address;
	p[s].age = age;
	p[s].name = name;
	return;
}
void Display(Person p[], int s) {
	if (s == 0) {
		cout << "无数据!!!" << endl;
		return;
	}
	for (int i = 0;i < s;i++) {
		cout << "名字: " << p[i].name
			<< "   年龄: " << p[i].age  
			<< "   地址: " << p[i].address 
			<< endl;
	}
	return;
}
void Delete(Person* p, int s) {
	string WillDele;
	cout << "Please input delete name:" << endl;
	cin >> WillDele;
	int i = 0;
	for (i = 0;i < s;i++) {
		if (p[i].name == WillDele) {
			p[i] = {"",NULL,""};
			break;
		}
	}
	if (i == s-1) return;
	if (i < s && i>=0) {
		for (int j = i; j < s - 1; j++) {
			p[j] = p[j + 1];
		}
	}
	p[s-1] = { "",NULL,"" };
	return;
}
void Find(Person p[],int s) {
	string name;
	cout << "Please input find name: " << endl;
	cin >> name;
	int i;
	for (i = 0;i < s;i++) {
		if (p[i].name == name) {
			break;
		}
	}
	cout << "名字: " << p[i].name
		<< "   年龄: " << p[i].age
		<< "   地址: " << p[i].address
		<< endl;
	return;
}
void Modify(Person* p, int s) {
	string name;
	string Newname;
	int Newage = 0;
	string Newaddress;
	cout << "Please input modify name: " << endl;
	cin >> name;
	int i;
	for (i = 0;i < s;i++) {
		if (p[i].name == name) {
			break;
		}
	}
	cout << "Please input new name: " << endl;
	cin >> Newname;
	cout << "Please input new age: " << endl;
	cin >> Newage;
	cout << "Please input new address: " << endl;
	cin >> Newaddress;
	p[i].address = Newaddress;
	p[i].age = Newage;
	p[i].name = Newname;
	return;
}
void DeleteAll(Person *p,int s) {
	for (int i = 0;i < s;i++) {
		p[i] = { "",NULL,"" };
	}
}

作为c++初学者,自己写的还有很大的进步空间,发出来也算激励一下自己。

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【员工管理系统】 问题描述:每个员工的信息包括:编号、姓名、性别、出生年月、学历、职务、电话、住址等。系统能够完成员工信息的查询、更新、插入、删除、排序等功能。 基本要求:排序:按不同关键字,对所有员工的信息进行排序;查询:按特定条件查找员工;更新,按编号对某个员工的某项信息进行修改;插入,加入新员工的信息;删除,按编号删除已离职的员工的信息。 选作内容:实现图形用户界面。 通过链表实现 数据结构: #include #include #include #include #include using namespace std; typedef struct workers{ char name[15];//姓名 char department[18];//单位 char gender;//性别 unsigned int age;//年龄 unsigned long long telephone;//电话 unsigned long wage;//工资 unsigned long num;//职工号 struct workers *next; }*Linklist,Lnode; void frist_print() { printf("\t\t⊙▽⊙ ⊙▽⊙ ⊙▽⊙ ⊙▽⊙ ⊙▽⊙ ⊙▽⊙ \n\n"); printf("\t\t\t欢迎进入员工管理系统\n"); } void menu() { printf("\n\t\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); printf("\t\t \t ◎1.创建员工信息\t \n"); printf("\t\t \t ◎2.插入员工信息\t \n"); printf("\t\t \t ◎3.修改员工信息\t \n"); printf("\t\t \t ◎4.删除员工信息\t \n"); printf("\t\t \t ◎5.查询员工信息\t \n"); printf("\t\t \t ◎6.员工信息排序\t \n"); printf("\t\t \t ◎7.显示员工信息\t \n"); printf("\t\t \t ◎8.员工工资情况\t \n"); printf("\n\t\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); printf("注意:输入均以回车作为结束\n"); printf("please choise 1--8:\t "); //putchar(12); } void Inset(Linklist Head){ Linklist s,L; unsigned int agee; unsigned long wagee,numm;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值