使用C++语言编写的职工管理系统

使用c++实现职工管理系统的基本功能

0-退出管理程序
1-增加职工信息
2-显示职工信息
3-删除离职职工
4-修改职工信息
5-查找职工信息
6-按照编号排序
7-清空所有文档

 

 

 boss.cpp


#include"Boss.h"
//构造函数
Boss::Boss(int id, string name, int did) {

    this->m_id = id;
    this->m_name = name;
    this->m_number = did;

}
//显示个人信息
void Boss::showinfo() {

    cout << "职工编号:" << this->m_id
        << "\t职工姓名:" << this->m_name
        << "\t岗位:" << this->getdeptname()
        << "\t岗位职责:管理公司所有事务" << endl;
}

//获取岗位名称
string Boss::getdeptname() {

    return string("老板");

}

boss.h

#pragma once
#include<iostream>
#include<string>
using namespace std;
#include"Worker.h"
//经理类
class Boss :public Worker {
public:
    //构造函数
    Boss(int id, string name, int did);
    //显示个人信息
    virtual void showinfo();

    //获取岗位名称
    virtual string getdeptname();

};

Employee.cpp

#include"Employee.h"
#include<string>
//构造函数
Employee::Employee(int id, string name, int did) {

    this->m_id = id;
    this->m_name = name;
    this->m_number = did;


}
//显示个人信息
void Employee::showinfo()
{
    cout << "职工编号:" << this->m_id 
        << "\t职工姓名:" << this->m_name
        << "\t岗位:"<<this->getdeptname()
        << "\t岗位职责:完成经理交给的任务" << endl;

}
//获取岗位名称
string  Employee::getdeptname() {

    return string("普通员工");

}

Employee.h

//普通员工文件
#pragma once
#include<iostream>
#include<string.h>
#include"Worker.h"
using namespace std;
class Employee :public Worker {
public:
    //构造函数
    Employee(int id,string name,int did);

    //显示个人信息
    virtual void showinfo();
    //获取岗位名称
    virtual string getdeptname();
};

manager.h

#include"Manager.h"

//构造函数
Manager::Manager(int id, string name, int did) {

    this->m_id = id;
    this->m_name = name;
    this->m_number = did;

}
//显示个人信息
void Manager::showinfo() {

    cout << "职工编号:" << this->m_id
        << "\t职工姓名:" << this->m_name
        << "\t岗位:" << this->getdeptname()
        << "\t岗位职责:完成老板交给的任务,并且下发任务给普通员工" << endl;
}

//获取岗位名称
string Manager::getdeptname() {

    return string("经理");

}
 

manager.h

#pragma once
#include<iostream>
using namespace std;
#include"Worker.h"
#include<string>
#include<iostream>
using namespace std;
//经理类
class Manager:public Worker {
public:

    //构造函数
    Manager(int id, string name, int did);
    //显示个人信息
    virtual void showinfo();

    //获取岗位名称
    virtual string getdeptname();

};

Worker.h

#pragma once
#include<iostream>
#include<string>
using namespace std;
//职工抽象类
class Worker {
public:
    //显示个人信息
    virtual void showinfo() = 0;
    
    //获取岗位名称
    virtual string getdeptname

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的员工信息管理系统的 C 语言代码示例: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_EMPLOYEES 100 // 最大员工数 struct employee { int id; char name[50]; int age; float salary; }; struct employee employees[MAX_EMPLOYEES]; // 定义员工数组 int num_employees = 0; // 当前员工数 void add_employee() { if (num_employees >= MAX_EMPLOYEES) { printf("员工数已达到上限,无法添加更多员工。\n"); return; } printf("请输入新员工的信息:\n"); printf("编号:"); scanf("%d", &employees[num_employees].id); printf("姓名:"); scanf("%s", employees[num_employees].name); printf("年龄:"); scanf("%d", &employees[num_employees].age); printf("工资:"); scanf("%f", &employees[num_employees].salary); num_employees++; printf("员工添加成功。\n"); } void delete_employee() { int id; printf("请输入要删除的员工编号:"); scanf("%d", &id); int i; for (i = 0; i < num_employees; i++) { if (employees[i].id == id) { // 找到要删除的员工,将其后面的员工依次前移 int j; for (j = i; j < num_employees - 1; j++) { employees[j] = employees[j+1]; } num_employees--; printf("员工删除成功。\n"); return; } } printf("未找到该员工。\n"); } void list_employees() { if (num_employees == 0) { printf("目前没有员工信息。\n"); return; } int i; for (i = 0; i < num_employees; i++) { printf("编号:%d\t姓名:%s\t年龄:%d\t工资:%f\n", employees[i].id, employees[i].name, employees[i].age, employees[i].salary); } } int main() { int choice; while (1) { printf("请选择要执行的操作:\n"); printf("1. 添加员工\n"); printf("2. 删除员工\n"); printf("3. 列出所有员工\n"); printf("4. 退出程序\n"); printf("请选择(输入对应数字):"); scanf("%d", &choice); switch (choice) { case 1: add_employee(); break; case 2: delete_employee(); break; case 3: list_employees(); break; case 4: printf("程序已退出。\n"); exit(0); break; default: printf("无效的选择,请重新输入。\n"); } printf("\n"); } return 0; } ``` 该代码中定义了一个 `employee` 结构体,表示一个员工的信息,包括编号、姓名、年龄和工资。员工信息以数组的形式存储,可以进行添加、删除和列出所有员工的操作。可以通过菜单选择要执行的操作,直到选择退出程序为止。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值