C++ 雇员信息保存及查询

该博客介绍了如何使用C++设计一个Employee类,包含雇员姓名、编号(格式为XXX-L)和受雇日期,并实现输入验证。接着,设计了一个EmployeePay类,继承自Employee,增加了月工资和部门号,并实现了获取数据和输出数据的功能。在主函数中,创建了EmployeePay对象并进行了数据输入和输出操作。
摘要由CSDN通过智能技术生成

C++基础题目:

题目
先设计一个 Employee 类,要求它能保存:
(1)雇员的姓名;
(2)雇员编号,格式为 “XXX-L”,其中X为0-9的数字,L为A~M的字母;(3)受雇日期。
并自行设计相应成员函数。
随后设计一个类 EmployeePay,它继承 Employee 类,能够保存:
(1)月工资,使用float类型,为正数;
(2)部门号,使用整型,为正数。
并自行设计相应成员函数。

//雇员.h及其函数实现
#pragma once
#include <iostream>
#include <regex>
using namespace std;
class Employee
{
public:
	string name;
	string number;
	string date;
	bool isnumber(string num)
	{
		regex pattern("[0-9]{3}-[A-M]");
		return regex_match(num, pattern);
	}
	bool isdate(string date)
	{
		regex pattern("[0-9]{4}-[0-9]{2}-[0-9]{2}");
		return regex_match(date, pattern);
	}
void in()
	{
		cout << "请输入雇员姓名:" << endl;
		cin >> name;
		cout << "请输入雇员编号(例如:012-A):" << endl;
		cin >> number;
		if (!isnumber(number))
		{
			cout << "输出错误的雇员编号!" << endl;
			system("pause");
			return;
		}
		cout << "请输入雇员受雇日期(2016-03-25):" << endl;
		cin >> date;
		if (!isdate(date))
		{
			cout << "输入错误的受雇日期!" << endl;
			system("pause");
			return;
		}
	}
	void out()
	{
		cout << "雇员姓名为:" << name << endl;
		cout << "雇员编号为:" << number << endl;
		cout << "受雇日期为:" << date << endl;
	}
};
//雇员pay.h及其函数实现
#pragma once
#include "Employee.h"
class EmployeePay:public Employee
{
private:
	float wage;
	int department;
public:
	void getdata()
	{
		cout << "请输入雇员月工资:" << endl;
		cin >> wage;
		cout << "请输入雇员部门号(例如:16):" << endl;
		cin >> department;
	}
	void outdata()
	{
		cout << "月工资为:" << wage << "¥" << endl;
		cout << "部门号为:" << department << endl;
	}
};

//主函数.cpp
#include <iostream>
#include "EmployeePay.h"
int main()
{
	EmployeePay a;
	a.in();
	a.getdata();
	a.out();
	a.outdata();
	system("pause");
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值