C++程序设计

// ConsoleApplication25.cpp : 定义控制台应用程序的入口点。
//1通信录的设计
//	基本要求:
//	定义date类,至少包括年月日;
//	定义person类,至少包括姓名、性别和出生日期;
//	定义人员(staff)类,从person类派生,至少包括电话、地址、邮政编码、邮箱、QQ号和类别(例如:同学、朋友等)。
//	功能要求:
//      1、设计菜单实现功能选择;   
//      2、输入功能:输入人员信息,并保存到文件中;
//     3、查询功能:
//         1)能够根据姓名、电话精确查询人员信息;
//         2)能够根据地址进行模糊查询人员信息;
//	       3)根据人员类别查询人员信息
//     4、根据姓名对人员信息排序输出
//     5、能根据姓名、电话修改人员信息
//     6、能根据姓名、电话删除人员信息
//

#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
using namespace std;

class Data
{
public:
	Data() {};
	Data(int year, int month, int day);
	void set_year(int _year)
	{
		year = _year;
	}
	void set_month(int _month)
	{
		month = _month;
	}
	void set_day(int _day)
	{
		day = _day;
	}
	int get_year()
	{
		return year;
	}
	int get_month()
	{
		return month;
	}
	int get_day()
	{
		return day;
	}
private:
	int year;
	int month;
	int day;
};
Data::Data(int _year, int _month, int _day)
{
	year = _year;
	month = _month;
	day = _day;
}
class Person
{
public:
	Person() {}
	Person(string _name, int _id, string _sex, int _year, int _month, int _day);
	void set_name(string _name)
	{
		name = _name;
	}
	void set_sex(string _sex)
	{
		sex = _sex;
	}
	void set_id(int _id)
	{
		id = _id;
	}
	//person(int a, int b, int c);
	string get_name()
	{
		return name;
	}
	string get_sex()
	{
		return sex;
	}
	int get_id()
	{
		return id;
	}
	void set_year(int _y)
	{
		m_iBirthday.set_year(_y);
	}
	int get_year()
	{
		return m_iBirthday.get_year();
	}
	void set_month(int _m)
	{
		m_iBirthday.set_month(_m);
	}
	int get_month()
	{
		return m_iBirthday.get_month();
	}
	void set_day(int _d)
	{
		m_iBirthday.set_year(_d);
	}
	int get_day()
	{
		return m_iBirthday.get_day();
	}
private:
	string name;
	int id;
	string sex;
	Data m_iBirthday;
};
Person::Person(string _name, int _id, string _sex, int _year, int _month, int _day) :m_iBirthday(_year, _month, _day)
{
	name = _name;
	id = _id;
	sex = _sex;

}
class staff :public Person
{
public:
	staff() {}
	staff(string _phone, string _address, string _code, string _postbox, int _qq, string _category, string _name, int _id, string _sex, int _y, int _m, int _d);
	void set_phone(string _phone)
	{
		phone = _phone;
	}
	void set_address(string _address)
	{
		address = _address;
	}
	void set_code(string _code)
	{
		code = _code;
	}
	void set_qq(int _qq)
	{
		qq = _qq;
	}
	void set_postbox(string _postbox)
	{
		postbox = _postbox;
	}
	void set_category(string _category)
	{
		category = _category;
	}
	string get_phone()
	{
		return phone;
	}
	string get_address()
	{
		return address;
	}
	string get_code()
	{
		return code;
	}
	string get_postbox()
	{
		return postbox;
	}
	int get_qq()
	{
		return qq;
	}
	string get_category()
	{
		return category;
	};

private:
	string phone;
	string address;
	string code;
	string postbox;
	int qq;
	string category;
};
staff::staff(string _phone, string _address, string _code, string _postbox, int _qq, string _category, string _name, int _id, string _sex, int _year, int _month, int _day) :Person(_name, _id, _sex, _year, _month, _day)
{
	phone = _phone;
	address = _address;
	code = _code;
	postbox = _postbox;
	qq = _qq;
	category = _category;

}
void function_1(vector<staff> &v);//输入功能:输入人员信息,并保存到文件中
void writefile(vector<staff> &v);
void function_2(vector<staff> &v);//查询功能
void function_3(vector<staff> &v);//根据姓名对人员信息排序输出
void function_4(vector<staff> &v);//根据姓名、电话修改人员信息
void function_5(vector<staff> &v);//修改模块
int main()
{
	vector<staff> v;
	int m;
	while (1)
	{
		cout << "******     欢迎使用通信录管理系统!          *****" << endl;
		cout << "******         请输入需求!                  *****" << endl;
		cout << "******    1.输入人员信息                     *****" << endl;
		cout << "******    2.查找人员信息                     *****" << endl;
		cout << "******    3.排序输出                         *****" << endl;
		cout << "******    4.能根据姓名、电话修改人员信息     *****" << endl;
		cout << "******    5.能根据姓名、电话删除人员信息     *****" << endl;
		cout << "******    6.退出程序                         *****" << endl;
		cin >> m;
		if (m == 1)
		{
			function_1(v);
			cout << endl;
		}
		else if (m == 2)
		{
			function_2(v);
			cout << endl;
		}
		else if (m == 3)
		{
			function_3(v);

			cout << endl;
		}
		else if (m == 4)
		{
			function_4(v);

			cout << endl;
		}
		else if (m == 5)
		{
			function_5(v);

			cout << endl;

		}
		else if (m == 6)
			break;
	}

	return 0;
}
void function_1(vector<staff> &v)//输入功能:输入人员信息,并保存到文件中
{
	staff s;
	int n;
	int year, month, day, id, qq;
	string name, sex, address, code, category, postbox, phone;
	cout << "请输入你要添加的人数:" << endl;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{

		cout << "第" << i << "个人员的出生年:" << ends;
		cin >> year;
		cout << "第" << i << "个人员的出生月:" << ends;
		cin >> month;
		cout << "第" << i << "个人员的出生天:" << ends;
		cin >> day;
		cout << "第" << i << "个人员的姓名:" << ends;
		cin >> name;
		cout << "第" << i << "个人员的性别(性别为0/1):" << ends;
		cin >> sex;
		cout << "第" << i << "个人员的身份证号:" << ends;
		cin >> id;
		cout << "第" << i << "个人员的电话号码:" << ends;
		cin >> phone;
		cout << "第" << i << "个人员的地址(地址为11/22):" << ends;
		cin >> address;
		cout << "第" << i << "个人员的邮政编码(邮编为000/111):" << ends;
		cin >> code;
		cout << "第" << i << "个人员的邮箱:" << ends;
		cin >> postbox;
		cout << "第" << i << "个人员的QQ:" << ends;
		cin >> qq;
		cout << "第" << i << "个人员的分类(分类为a/b):" << ends;
		cin >> category;
		s.set_year(year);
		s.set_month(month);
		s.set_day(day);
		s.set_name(name);
		s.set_sex(sex);
		s.set_id(id);
		s.set_phone(phone);
		s.set_address(address);
		s.set_code(code);
		s.set_postbox(postbox);
		s.set_qq(qq);
		s.set_category(category);
		v.push_back(s);
	}
	ofstream os;
	ofstream ofs("d:\\b.txt");
	if (!ofs)
	{
		cout << "open failed" << endl;
	}

	ofs << "出生年 " << "出生月 " << "出生日 " << "  " << "姓名 " << "  "
		<< "身份证号 " << "   " << "性别 " << "   " << "电话" << "    " << "地址" << "   " << "邮政编码" << "    " << "邮箱" << "    " << "QQ" << "    " << "类别" << endl;
	vector<staff>::iterator it = v.begin();
	for (; it != v.end(); it++)
	{

		ofs << (*it).get_year() << "  " << (*it).get_month() << "   " << (*it).get_day() << "   " << (*it).get_name() << "  " << (*it).get_id() << (*it).get_sex() << "    "
			<< (*it).get_phone() << "  " << (*it).get_address() << "   " << (*it).get_code() << "  "
			<< (*it).get_postbox() << "   " << (*it).get_qq() << "    " << (*it).get_category() << endl;
	}
	ofs.close();
	cout << "出生年 " << "出生月 " << "出生日 " << "  " << "姓名 " << "  " << "身份证号 " << "  "
		<< "性别 " << "  " << "电话" << "  " << "地址" << "  " << "邮政编码" << "  " << "邮箱"
		<< "  " << "QQ" << "  " << "类别" << endl;

	ifstream ifs("d:\\b.txt");
	if (ifs)
	{
		for (int i = 0; i < n; i++)
		{
			ifs >> year >> month >> day >> name >> id >> sex >> phone >> address >> code >> postbox >> qq >> category;
			cout << year << "  " << month << "  " << day << "  " << name << "    " << id << "   " << sex << "  " << phone << "    " << address << "   " << code << "   " << postbox << "  " << qq << "  " << category << "    " << endl;
		}

	}
	else
		cout << "if failed" << endl;
	ifs.close();
	system("pause");
	system("cls");
}//输入功能:输入人员信息,并保存到文件中
 //输入功能:输入人员信息,并保存到文件中
void writefile(vector<staff> &v)
{
	staff s;
	int n;
	int year, month, day, id, qq;
	string name, sex, address, code, category, postbox, phone;
	cout << "请输入已输入的人数:" << endl;
	cin >> n;
	vector<staff>::iterator it = v.begin();
	ofstream os;
	ofstream ofs("d:\\b.txt");
	if (!ofs)
	{
		cout << "open failed" << endl;
	}

	ofs << "出生年 " << "  " << "出生月 " << "  " << "出生日 " << "  " << "姓名 " << "  "
		<< "身份证号 " << "   " << "性别 " << "   " << "电话" << "    " << "地址" << "   " << "邮政编码" << "    " << "邮箱" << "    " << "QQ" << "    " << "类别" << endl;
	for (; it != v.end(); it++)
	{

		ofs << (*it).get_year() << "  " << (*it).get_month() << "   " << (*it).get_day() << "   " << (*it).get_name() << "  " << (*it).get_id() << (*it).get_sex() << "    "
			<< (*it).get_phone() << "  " << (*it).get_address() << "   " << (*it).get_code() << "  "
			<< (*it).get_postbox() << "   " << (*it).get_qq() << "    " << (*it).get_category() << endl;
		
	}
	ofs.close();
	cout << "出生年 " << "出生月 " << "出生日 " << "  " << "姓名 " << "  " << "身份证号 " << "  "
		<< "性别 " << "  " << "电话" << "  " << "地址" << "  " << "邮政编码" << "  " << "邮箱"
		<< "  " << "QQ" << "  " << "类别" << endl;
	ifstream ifs("d:\\b.txt");
	if (ifs)
	{
		for (int i = 0; i < n; i++)
		{
			ifs >> year >> month >> day >> name >> id >> sex >> phone >> address >> code >> postbox >> qq >> category;
			cout << year << "  " << month << "  " << day << "  " << name << "    " << id << "   " << sex << "  " << phone << "    " << address << "   " << code << "   " << postbox << "  " << qq << "  " << category << "    " << endl;
		}

	}
	else
		cout << "if failed" << endl;
	ifs.close();
	system("pause");
	system("cls");
}
void function_2(vector<staff> &v)
{
	staff s;
	int n;
	string name, sex, address, code, category, postbox, phone;
	cout << "1、按照姓名和电话查找" << endl;
	cout << "2、按照地址查询" << endl;
	cout << "3、按照类别查询" << endl;
	cout << "请选择查找方式对应的序号!" << endl;
	cin >> n;
	vector<staff>::iterator it = v.begin();
	bool find = false;
	while (1)
	{
		if (n == 1)
		{
			cout << "请输入姓名和电话" << endl;
			cin >> name >> phone;
			for (; it != v.end(); it++)        //for (int i = 0; i < a; i++)
			{
				if (name == (*it).get_name() || phone == (*it).get_phone())
				{
					//v.push_back(*it);
					cout << "输出人员信息:" << endl;
					cout << "出生年 " << "  " << "出生月 " << "  " << "出生日 " << "  " << "姓名 " << "  " << "身份证号 " << "  "
						<< "性别 " << "  " << "电话" << "  " << "地址" << "  " << "邮政编码" << "  " << "邮箱"
						<< "  " << "QQ" << "  " << "类别" << endl;
					cout << (*it).get_name() << "  " << (*it).get_id() << "  " << (*it).get_sex() << "  " << (*it).get_year()
						<< "  " << (*it).get_month() << "  " << (*it).get_day() << "  " << (*it).get_phone() << "  " << (*it).get_address()
						<< "  " << (*it).get_code() << "  " << (*it).get_postbox() << "  " << (*it).get_qq() << "  " << (*it).get_category() << "  " << endl;
				}
				else if (name != (*it).get_name() || phone != (*it).get_phone())
				{
					cout << "输入错误!请重新输入" << endl;
				}
				system("pause");
				system("cls");
			}
		}
		else if (n == 2)
		{
			cout << "请输入地址" << endl;
			cin >> address;
			for (; it != v.end(); it++)        //for (int i = 0; i < a; i++)
			{
				if (address == (*it).get_address())
				{
					//v.push_back(*it);
					cout << "输出人员信息:" << endl;
					cout << "出生年 " << "  " << "出生月 " << "  " << "出生日 " << "  " << "姓名 " << "  " << "身份证号 " << "  "
						<< "性别 " << "  " << "电话" << "  " << "地址" << "  " << "邮政编码" << "  " << "邮箱"
						<< "  " << "QQ" << "  " << "类别" << endl;
					cout << (*it).get_year() << "  " << (*it).get_month() << "  " << (*it).get_day() << (*it).get_name()
						<< "  " << (*it).get_id() << "  " << (*it).get_sex()
						<< "  " << "  " << (*it).get_phone() << "  " << (*it).get_address()
						<< "  " << (*it).get_code() << "  " << (*it).get_postbox() << "  "
						<< (*it).get_qq() << "  " << (*it).get_category() << "  " << endl;
				}
			}
			system("pause");
			system("cls");
			break;
		}
		else if (n == 3)
		{
			cout << "请输入类别" << endl;
			cin >> category;
			for (; it != v.end(); it++)        //for (int i = 0; i < a; i++)
			{
				if (category == (*it).get_category())
				{
					//v.push_back(*it);
					cout << "输出人员信息:" << endl;
					cout << "出生年 " << "  " << "出生月 " << "  " << "出生日 " << "  " << "姓名 " << "  " << "身份证号 " << "  "
						<< "性别 " << "  " << "电话" << "  " << "地址" << "  " << "邮政编码" << "  " << "邮箱"
						<< "  " << "QQ" << "  " << "类别" << endl;
					cout << (*it).get_name() << "  " << (*it).get_id() << "  " << (*it).get_sex() << "  " << (*it).get_year() << "  "
						<< (*it).get_month() << "  " << (*it).get_day() << "  " << (*it).get_phone() << "  " << (*it).get_address() << "  " << (*it).get_code() << "  " << (*it).get_postbox() << "  "
						<< (*it).get_qq() << "  " << (*it).get_category() << "  " << endl;
				}
			}
			system("pause");
			system("cls");
		}
		break;
	}
	if (!find)cout << "查无此人!" << endl;
}
//查询功能
void function_3(vector<staff> &v)
{
	staff s;
	int n, m;
	cout << "按照姓名排序后的结果为:" << endl;
	vector<staff>::iterator it = v.begin();
	n = v.size();
	m = v.size();
	for (int i = 0; i<n - 1; i++)
	{
		for (int j = 0; j<n - 1 - i; j++)
		{
			if (v[j].get_name()>v[j + 1].get_name())//进行冒泡排序
			{
				s = v[j];
				v[j] = v[j + 1];
				v[j + 1] = s;
			}
		}

		for (int i = 0; i < m; i++)
		{
			cout << "出生年 " << "出生月 " << "出生日 " << "  " << "姓名 " << "  " << "身份证号 " << "  " << "性别 " << "  " << "电话" << "  "
				<< "地址" << "  " << "邮政编码" << "  " << "邮箱" << "  " << "QQ" << "  " << "类别" << endl;
			cout << v[i].get_name() << "  " << v[i].get_id() << "  " << v[i].get_sex() << "  " << v[i].get_year()
				<< v[i].get_month() << "  " << v[i].get_day() << "  " << v[i].get_phone() << "  " << v[i].get_address() << "  " << v[i].get_code() << "  " << v[i].get_postbox() << "  "
				<< v[i].get_qq() << "  " << v[i].get_category() << "  " << endl;
		}
	}
}
//根据姓名对人员信息排序输出
void function_4(vector<staff> &v)//修改模块
{
	int year, month, day, qq;
	string name, sex, address, code, category, postbox, phone;
	string record;
	vector<staff>::iterator it = v.begin();
	cout << "请输入电话或姓名:" << endl;
	cin >> record;
	for (; it != v.end(); it++)
	{
		if ((*it).get_name() == record || (*it).get_phone() == record)
		{
			cout << "请输入需要修改的年份:" << endl;
			cin >> year;
			cout << "请输入需要修改的月份:" << endl;
			cin >> month;
			cout << "请输入需要修改的天数:" << endl;
			cin >> day;
			cout << "请输入需要修改的性别:" << endl;
			cin >> sex;
			cout << "请输入需要修改的地址:" << endl;
			cin >> address;
			cout << "请输入需要修改的邮编:" << endl;
			cin >> code;
			cout << "请输入需要修改的邮件:" << endl;
			cin >> postbox;
			cout << "请输入需要修改的电话号码:" << endl;
			cin >> phone;
			cout << "请输入需要修改的QQ:" << endl;
			cin >> qq;
			cout << "请输入需要修改的类别:" << endl;
			cin >> category;
			(*it).set_year(year);
			(*it).set_month(month);
			(*it).set_category(category);
			(*it).set_day(day);
			(*it).set_sex(sex);
			(*it).set_code(code);
			(*it).set_address(address);
			(*it).set_postbox(postbox);
			(*it).set_phone(phone);
			(*it).set_qq(qq);
			(*it).set_category(category);
			cout << "修改后的人员信息为:" << endl;
			cout << "姓名:" << (*it).get_name() << "    " << endl << "年份:" << "    " << (*it).get_year() << "    " << endl
				<< "月份:" << (*it).get_month() << "    " << endl << "天数:" << (*it).get_day() << "    "
				<< endl << "性别:" << (*it).get_sex() << "    " << endl << "地址:" << (*it).get_address() << "    "
				<< endl << "邮编:" << (*it).get_code() << "    " << endl << "邮件:" << (*it).get_postbox() << "    " << endl
				<< "电话号码:" << (*it).get_phone() << "    " << endl << "QQ:" << (*it).get_qq() << "    " << endl
				<< "类别:" << "    " << (*it).get_category() << "    " << endl;
		}
	}
	writefile(v);
}
//能根据姓名、电话修改人员信息
void function_5(vector<staff> &v)
{
	staff s;
	int n;
	string record;
	int year, month, day, id, qq;
	string name, sex, address, code, category, postbox, phone;
	vector<staff>::iterator it = v.begin();
	cout << "请输入姓名或电话:" << endl;
	cin >> record;
	for (; it != v.end(); it++)
	{
		if ((*it).get_name() == record || (*it).get_phone() == record)
		{
			v.erase(it);
			cout << "删除成功!" << endl;
			for (int i = 0; i < v.size(); i++)
			{
				cout << "姓名:" << v[i].get_name() << endl;
				cout << "年份:" << v[i].get_year() << endl;
				cout << "月份:" << v[i].get_month() << endl;
				cout << "天数:" << v[i].get_day() << endl;
				cout << "性别:" << v[i].get_sex() << endl;
				cout << "地址:" << v[i].get_address() << endl;
				cout << "邮编:" << v[i].get_code() << endl;
				cout << "邮件:" << v[i].get_postbox() << endl;
				cout << "电话号码:" << v[i].get_phone() << endl;
				cout << "QQ:" << v[i].get_qq() << endl;
				cout << "类别:" << "" << v[i].get_category() << endl;
			}
		}
		writefile(v);
	}
	
}
//能根据姓名、电话删除人员信息



  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
来模糊查询职工信息,并将查询结果输出;3、能够统计并输出所有职工的工资总和、平均工资和最高工资者的信息;4、能够按照工资从高到低排序并输出职工信息。 以下是一个实现职工工资管理系统的示例代码: ```c++ #include <iostream> #include <fstream> #include <string> #include <vector> #include <algorithm> using namespace std; // 定义职工 class Employee { public: string name; // 姓名 string gender; // 性别 string id; // 工号 string phone; // 电话 string dept; // 所在科室 double salary; // 工资 }; // 定义职工管理 class EmployeeManager { public: vector<Employee> employees; // 所有职工信息 // 从文件中读取职工信息 void loadFromFile(string filename) { ifstream ifs(filename); if (!ifs) { cout << "Error: cannot open file " << filename << endl; return; } Employee emp; while (ifs >> emp.name >> emp.gender >> emp.id >> emp.phone >> emp.dept >> emp.salary) { employees.push_back(emp); } ifs.close(); cout << "Load " << employees.size() << " employees from file " << filename << endl; } // 将职工信息保存到文件中 void saveToFile(string filename) { ofstream ofs(filename); if (!ofs) { cout << "Error: cannot open file " << filename << endl; return; } for (auto &emp : employees) { ofs << emp.name << ' ' << emp.gender << ' ' << emp.id << ' ' << emp.phone << ' ' << emp.dept << ' ' << emp.salary << endl; } ofs.close(); cout << "Save " << employees.size() << " employees to file " << filename << endl; } // 添加职工信息 void addEmployee() { Employee emp; cout << "Enter employee's name: "; getline(cin, emp.name); cout << "Enter employee's gender (male or female): "; getline(cin, emp.gender); cout << "Enter employee's id: "; getline(cin, emp.id); cout << "Enter employee's phone: "; getline(cin, emp.phone); cout << "Enter employee's department: "; getline(cin, emp.dept); cout << "Enter employee's salary: "; cin >> emp.salary; cin.ignore(); // 忽略换行符 employees.push_back(emp); cout << "Add employee successfully!" << endl; } // 根据工号查询职工信息 void searchById() { string id; cout << "Enter employee's id to search: "; getline(cin, id); for (auto &emp : employees) { if (emp.id == id) { cout << "Name: " << emp.name << endl; cout << "Gender: " << emp.gender << endl; cout << "Id: " << emp.id << endl; cout << "Phone: " << emp.phone << endl; cout << "Department: " << emp.dept << endl; cout << "Salary: " << emp.salary << endl; return; } } cout << "Cannot find employee with id " << id << endl; } // 根据姓名模糊查询职工信息 void searchByName() { string name; cout << "Enter employee's name to search: "; getline(cin, name); vector<Employee> result; for (auto &emp : employees) { if (emp.name.find(name) != string::npos) { result.push_back(emp); } } if (result.empty()) { cout << "Cannot find employee with name " << name << endl; } else { for (auto &emp : result) { cout << "Name: " << emp.name << endl; cout << "Gender: " << emp.gender << endl; cout << "Id: " << emp.id << endl; cout << "Phone: " << emp.phone << endl; cout << "Department: " << emp.dept << endl; cout << "Salary: " << emp.salary << endl; } } } // 统计职工工资总和、平均工资和最高工资者的信息 void getStatistics() { double sum = 0, maxSalary = 0; for (auto &emp : employees) { sum += emp.salary; maxSalary = max(maxSalary, emp.salary); } double avgSalary = employees.empty() ? 0 : sum / employees.size(); cout << "Total salary: " << sum << endl; cout << "Average salary: " << avgSalary << endl; cout << "Employee(s) with highest salary: " << endl; for (auto &emp : employees) { if (emp.salary == maxSalary) { cout << "Name: " << emp.name << endl; cout << "Gender: " << emp.gender << endl; cout << "Id: " << emp.id << endl; cout << "Phone: " << emp.phone << endl; cout << "Department: " << emp.dept << endl; cout << "Salary: " << emp.salary << endl; } } } // 按照工资从高到低排序并输出职工信息 void sortBySalary() { sort(employees.begin(), employees.end(), [](const Employee &a, const Employee &b) { return a.salary > b.salary; }); for (auto &emp : employees) { cout << "Name: " << emp.name << endl; cout << "Gender: " << emp.gender << endl; cout << "Id: " << emp.id << endl; cout << "Phone: " << emp.phone << endl; cout << "Department: " << emp.dept << endl; cout << "Salary: " << emp.salary << endl; } } }; int main() { EmployeeManager manager; manager.loadFromFile("employees.txt"); while (true) { cout << "Menu:" << endl; cout << "1. Add employee" << endl; cout << "2. Search by id" << endl; cout << "3. Search by name" << endl; cout << "4. Get statistics" << endl; cout << "5. Sort by salary" << endl; cout << "6. Save to file" << endl; cout << "0. Exit" << endl; int choice; cout << "Enter your choice: "; cin >> choice; cin.ignore(); // 忽略换行符 switch (choice) { case 0: return 0; case 1: manager.addEmployee(); break; case 2: manager.searchById(); break; case 3: manager.searchByName(); break; case 4: manager.getStatistics(); break; case 5: manager.sortBySalary(); break; case 6: manager.saveToFile("employees.txt"); break; default: cout << "Invalid choice, please try again!" << endl; } } return 0; } ``` 这个序使用了和文件读写等 C++ 特性,实现了简单的职工工资管理系统。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值