职工信息管理系统:(c++程序设计)详细如下

职工信息管理系统:(c++程序设计)详细如下,第1张

//职工信息管理

// BCB6下通过

#include <iostream>

using namespace std;

typedef enum{m=1, f} gender;

typedef enum{none, salesman, technician, salesmanager, manager} position;

typedef float RMB;

class Employee

{

public:

Employee(int n, string nm, int yr, gender sx)

:num(n),name(nm),age(yr),sex(sx),salary(0), rank(1),pos(none){ }

virtual void Print()

{

cout<<num<<" "<<name<<" "<<age<<" "<<((sex==1) "male":"female")<<" "<<rank<<"级 薪水"<<salary<<" 职务 ";

ShowPos();

}

void SetPos(position ps){pos=ps;}

void ShowPos()

{

switch (pos)

{

case salesman: cout<<"salesman"; break;

case technician: cout<<"technician"; break;

case salesmanager: cout<<"salesmanager"; break;

case manager: cout<<"manager";break;

case none: cout<<"none"; break;

}

cout<<endl;

}

virtual RMB Payment(){ return salary=0;};

protected:

int num;

string name;

int age;

gender sex;

position pos;

int rank;

RMB salary;

};

class Salesman: virtual public Employee

{

public:

Salesman(int n, string nm, int yr, gender sx)

:Employee(n, nm, yr, sx)

{Employee::SetPos(salesman); Prompt();}

Salesman(Employee &emp):Employee(emp)

{Employee::SetPos(salesman); Prompt();}

virtual RMB Payment(){ return salary=004sales;} //调用该函数设置薪水salary,并可返回值

void Prompt();

protected:

RMB sales; //销往额,子类对象特有的属性

};

void Salesman::Prompt()

{

cout<<"Num: "<<num<<" "<<name<<endl;

cout<<"请输入销售额: ";

cin>> sales;

Payment();

cout<<endl;

}

class Manager:virtual public Employee

{

public:

Manager(int n, string nm, int yr, gender sx)

:Employee(n, nm, yr, sx)

{SetPos(manager); rank=4; salary=8000;}

Manager(Employee &emp):Employee(emp)

{Employee::SetPos(manager);rank=4; salary=8000;}

};

class SalesManager: public Manager, public Salesman

{

public:

SalesManager(int n, string nm, int yr, gender sx)

: Employee(n, nm, yr, sx),Manager(n, nm, yr, sx), Salesman(n, nm, yr, sx)

{pos=salesmanager; rank=3; Payment();}

SalesManager(Employee &emp):Employee(emp),Manager(emp),Salesman(emp){pos=salesmanager; rank=3; Payment();}

virtual RMB Payment(){ return salary=5000+ 0005sales;} //调用该函数设置薪水salary,并可返回值

};

class Technician: public Employee

{

public:

Technician(int n, string nm, int yr, gender sx)

:Employee(n, nm, yr, sx)

{Employee::SetPos(technician); rank=2; Prompt();}

Technician(Employee &emp):Employee(emp)

{ Employee::SetPos(technician); rank=2; Prompt();}

virtual RMB Payment(){ return salary=100work_hours;} //调用该函数设置薪水salary,并可返回值

void Prompt()

{

cout<<"Num: "<<num<<" "<<name<<endl;

cout<<"请输入工作小时数: ";

cin>> work_hours;

Payment();

cout<<endl;

}

private:

int work_hours; //工作小时数,子类对象特有的属性

};

int main(void )

{

const int N=4;

cout<<"测试一:"<<endl;

Salesman wang(101,"wang",30,f);

Technician Li(102,"Li", 25,m);

SalesManager Sman(105, "Sman", 40, f);

wangPrint();

LiPrint();

SmanPrint();

Employee empl[N]; //基类对象指针的数组

cout<<endl;

cout<<"测试二:"<<endl;

cout<<"请输入职员信息: 姓名(字母) 年龄 性别(m/f) 回车"<< endl;

for (int i=0; i<N; ++i)

{

string name;

int age;

char x;

gender sex;

cin>>name; cin>>age; cin>>x;

if (x=='m') sex=m;

else sex=f;

empl[i]=new Employee(1001+i, name, age, sex); //生成基类对象

empl[i]->Print();

cinclear();

std::string t;

std::getline(cin,t); //将当前行从缓存中取出

}

cout<<endl;

cout<<"指派职务,1salesman,2technician,3manager,4salesmanager"<<endl;

cout<<"请键入数字"<< endl;

int pos;

for (int i=0; i<N; ++i)

{

empl[i]->Print();

cout<<"职务: ";

cin>>pos;

cinclear();

string t;

getline(cin,t);

Employee ptnew; //基类指针

switch (pos) //根据指派的职务产生相应的子类对象

{

case 1:

ptnew=new Salesman(empl[i]); break; //基类指针指向子类对象

case 2:

ptnew=new Technician(empl[i]); break;

case 3:

ptnew=new Manager(empl[i]); break;

case 4:

ptnew=new SalesManager(empl[i]); break;

}

delete empl[i]; //释放原来的基类对象所用的内存

empl[i]=ptnew; //使原来的基类指针指向新的子类对象

}

for (int i=0; i<N; ++i)

empl[i]->Print(); //显示指派职务之后的各子类对象的属性

system("pause");

return 0;

}

#include

#include

#include

using namespace std;

typedef struct student {

unsigned m_id;

string m_name;

unsigned m_age;

string m_sex;

string m_address;

string m_contact;

string m_dormitory;

struct student m_next;

}student;

class CStudent {

private :

student head;

public :

CStudent() {

head = new student;

head->m_id = 0;

head->m_name = "noname";

head->m_next = NULL;

}

~CStudent() {

student p = head,q;

while(p) {

q = p;

p = q->m_next;

delete q;

}

}

student readdata(int model); // model = 1:不读取学号,2:不读取姓名,其他,读取所有信息

void entering();

bool insert(const student &astu);

student findid(unsigned id) const;

student findname(const string &name) const;

student findsex(const string &sex) const;

student finddormitory(const string &dormitory) const;

unsigned boys() const;

unsigned girls() const;

unsigned headcount() const;

bool eraseid();

bool erasename();

bool modifyid();

bool modifyname();

void Show() const;

void query() const;

void friend statistics(const CStudent &aclss);

void friend erase(CStudent &aclss);

void friend modify(CStudent &aclss);

};

string readstring() {

string str;

while(cinget() != '\n');

cin >> str;

return str;

}

student CStudent::readdata(int model) {

student tmp;

if(model != 1) { cout < "学 号: "; cin >> tmpm_id; }

if(model != 2) { cout << "姓 名: "; tmpm_name = readstring(); }

cin >> tmpm_age;

cout << "性 别: ";

tmpm_sex = readstring();

cout << "住 址: ";

tmpm_address = readstring();

cout << "****: ";

tmpm_contact =readstring();

cout << "寝 室: ";

tmpm_dormitory = readstring();

return tmp;

}

void CStudent::entering() {

student tmp;

cout << "学号(0 to return): ";

cin >> tmpm_id;

while(tmpm_id) {

if(findid(tmpm_id) == NULL) {

cout << "姓 名: ";

tmpm_name = readstring();

cout << "年 龄: ";

cin >> tmpm_age;

cout << "性 别: ";

tmpm_sex = readstring();

cout << "住 址: ";

tmpm_address = readstring();

cout << "****: ";

tmpm_contact = readstring();

cout << "寝 室: ";

tmpm_dormitory = readstring();

insert(tmp);

}

else cout << "重复的学号:" << tmpm_id << endl;

cout << "学号(0 to return): ";

cin >> tmpm_id;

}

}

student CStudent::findid(unsigned id) const {

student p;

for(p = head; p->m_next; p = p->m_next)

if(p->m_next->m_id == id) return p;

return NULL;

}

student CStudent::findname(const string &name) const {

student p;

for(p = head; p->m_next; p = p->m_next)

if(p->m_next->m_name == name) return p;

return NULL;

}

student CStudent::findsex(const string &sex) const {

student p;

for(p = head; p->m_next; p = p->m_next)

if(p->m_next->m_sex == sex) return p;

return NULL;

}

student CStudent::finddormitory(const string &dormitory) const {

student p;

for(p = head; p->m_next; p = p->m_next)

if(p->m_next->m_dormitory == dormitory) return p;

return NULL;

}

bool CStudent::insert(const student &astu) {

student newnode,p = head;

if(p->m_next == NULL) {

p->m_next = new student(astu);

p->m_next->m_next = NULL;

return true;

}

while(p->m_next) {

if(p->m_next->m_id == astum_id) {

cout << "重复的学号,插入失败!\n";

return false;

}

if(p->m_next->m_id > astum_id) {

newnode = new student(astu);

newnode->m_next = p->m_next;

p->m_next = newnode;

return true;

}

p = p->m_next;

}

p->m_next = new student(astu);

p->m_next->m_next = NULL;

return true;

}

unsigned CStudent::boys() const {

unsigned cnt = 0;

student p;

for(p = head->m_next; p; p = p->m_next)

if(p->m_sex == "男") ++cnt;

return cnt;

}

unsigned CStudent::girls() const {

unsigned cnt = 0;

student p;

for(p = head->m_next; p; p = p->m_next)

if(p->m_sex == "女") ++cnt;

return cnt;

}

unsigned CStudent::headcount() const {

unsigned cnt = 0;

student p;

for(p = head->m_next; p; p = p->m_next,++cnt);

return cnt;

}

bool CStudent::eraseid() {

student q,p;

unsigned id;

cout << "输入要删除的学号:";

cin >> id;

p = findid(id);

if(p == NULL) {

cout << "没有找到学号是\"" << id << "\"的学生,删除失败!\n";

return false;

}

q = p->m_next;

p->m_next = q->m_next;

delete q;

return true;

}

bool CStudent::erasename() {

student q,p;

string name;

cout << "输入要删除人的姓名:";

name = readstring();

p = findname(name);

if(p == NULL) {

cout << "没有找到姓名是\"" << name << "\"的学生,删除失败!\n";

return false;

}

q = p->m_next;

p->m_next = q->m_next;

delete q;

return true;

}

bool CStudent::modifyid() {

student tmp,p;

unsigned id;

cout << "输入要修改的学号:";

cin >> id;

p = findid(id);

if(p == NULL) {

cout << "没有找到学号是\"" << id << "\"的学生,修改失败!\n";

return false;

}

tmp = readdata(1);

tmpm_id = id;

p = tmp;

return true;

}

bool CStudent::modifyname() {

student p,tmp;

string name;

cout << "输入要修改人的姓名:";

name = readstring();

p = findname(name);

if(p == NULL) {

cout << "没有找到姓名是\"" << name << "\"的学生,修改失败!\n";

return false;

}

tmp = readdata(2);

tmpm_name = name;

p = tmp;

return true;

}

int menu() {

int choice;

do {

system("cls");

cout << "\t\n";

cout << "\t 学生基本信息管理系统 \n";

cout << "\t==========================\n";

cout << "\t 1、录入学生信息 \n";

cout << "\t 2、显示学生信息 \n";

cout << "\t 3、查询学生信息 \n";

cout << "\t 4、添加学生信息 \n";

cout << "\t 5、统计学生信息 \n";

cout << "\t 6、删除学生信息 \n";

cout << "\t 7、修改学生信息 \n";

cout << "\t 0、退出管理系统 \n";

cout << "\t\n";

cout << "\n\t请选择:";

cin >> choice;

}while(choice 0 || choice > 7);

return choice;

}

void show(student p) {

cout < p->m_id << " " < p->m_name << " " < p->m_age << " ";

cout < p->m_sex << " " < p->m_address << " ";

cout < p->m_contact << " " < p->m_dormitory << endl;

}

void CStudent::Show() const {

student p;

cout << "----------------------------------------------------------\n";

for(p = head->m_next; p; p = p->m_next) show(p);

cout << "----------------------------------------------------------\n";

system("pause");

}

void CStudent::query() const {

int select;

unsigned id;

string name;

student p;

cout << "1、按学号查询\n2、按姓名查询\n0、返回\n";

cin >> select;

switch(select) {

case 1 : cout < "请输入学号:"; cin >> id;

if(p = findid(id)) show(p->m_next);

break;

case 2 : cout << "请输入姓名:"; name = readstring();

if(p = findname(name)) show(p->m_next);

break;

case 0 : return;

default : cout << "选择错误。\n";

}

system("pause");

}

void statistics(const CStudent &a) {

unsigned total = aheadcount();

unsigned boys = aboys();

unsigned girls = agirls();

cout << "学生总数:" << total << "人。\n";

cout << "其中,男生:" << boys << "名。";

cout << "女生:" << girls << "名。\n";

system("pause");

}

void erase(CStudent &a) {

int select;

unsigned id;

string name;

student p,q;

cout << "1、按学号删除\n2、按姓名删除\n0、返回\n";

cin >> select;

switch(select) {

case 1 : cout < "请输入学号:"; cin >> id;

if(p = afindid(id)) {

q = p->m_next;

p->m_next = q->m_next;

delete q;

cout << "成功删除 " << id << " 的信息。\n";

}

break;

case 2 : cout << "请输入姓名:"; name = readstring();

if(p = afindname(name)) {

q = p->m_next;

p->m_next = q->m_next;

delete q;

cout << "成功删除 " << name << " 的信息。\n";

}

break;

case 0 : return;

default : cout << "选择错误。\n";

}

system("pause");

}

void modify(CStudent &a) {

int select;

cout << "1、按学号修改\n2、按姓名修改\n0、返回\n";

cin >> select;

switch(select) {

case 1 : if(amodifyid()) cout << "修改成功。\n"; break;

case 2 : if(amodifyname()) cout << "修改成功。\n"; break;

case 0 : return;

default : cout << "选择错误。\n";

}

system("pause");

}

int main() {

CStudent a;

int an;

do {

an = menu();

switch(an) {

case 1 : aentering(); break;

case 2 : aShow(); break;

case 3 : aquery(); break;

case 4 : aentering(); break;

case 5 : statistics(a); break;

case 6 : erase(a); break;

case 7 : modify(a); break;

case 0 : break;

default : cout << "选择错误。\n"; break;

}

}while(an);

return 0;

}

#include <iostream>

#include <iomanip>

#include <string>

#include <fstream>//输入/输出文件流类

using namespace std;

const int Maxr=100;//最多的读者

const int Maxb=100;//最多的图书

const int Maxbor=5;//每位读者最多借五本书

//读者类,实现对读者的信息的描述

class Reader

{

private:

int tag; //删除标记 1:已删 0:未删

int no; //读者编号

char name[10]; //读者姓名

int borbook[Maxbor];//所借图书

public:

Reader() {}

char getname() {return name;} //获取姓名

int gettag() {return tag;} //获取删除标记

int getno() {return no;} //获取读者编号

void setname(char na[]) //设置姓名

{

strcpy(name,na);

}

void delbook(){ tag=1; }//设置删除标记 1:已删 0:未删

void addreader(int n,char na)//增加读者

{

tag=0;

no=n;

strcpy(name,na);

for(int i=0;i<Maxbor;i++)

borbook[i]=0;

}

void borrowbook(int bookid)//借书 *** 作

{

for(int i=0;i<Maxbor;i++)

{

if (borbook[i]==0)

{

borbook[i]=bookid;

return;

}

}

}

int retbook(int bookid)//还书 *** 作

{

for(int i=0;i<Maxbor;i++)

{

if(borbook[i]==bookid)

{

borbook[i]=0;

return 1;

}

}

return 0;

}

void disp()//读出读者信息

{

cout << setw(5) << no <<setw(10) << name<<"借书编号:[";

for(int i=0;i<Maxbor;i++)

if(borbook[i]!=0)

cout << borbook[i] << "|";

cout << "]"<<endl;

}

};

//读者类库,实现建立读者的个人资料

class RDatabase

{

private:

int top; //读者记录指针

Reader read[Maxr];//读者记录

public:

RDatabase() //构造函数,将readertxt读到read[]中

{

Reader s;

top=-1;

fstream file("readertxt",ios::in);//打开一个输入文件

while (1)

{

fileread((char )&s,sizeof(s));

if (!file)break;

top++;

read[top]=s;

}

fileclose(); //关闭 readertxt

}

void clear()//删除所有读者信息

{

top=-1;

}

int addreader(int n,char na)//添加读者时先查找是否存在

{

Reader p=query(n);

if (p==NULL)

{

top++;

read[top]addreader(n,na);

return 1;

}

return 0;

}

Reader query(int readerid)//按编号查找

{

for (int i=0;i<=top;i++)

if (read[i]getno()==readerid &&

read[i]gettag()==0)

{

return &read[i];

}

return NULL;

}

void disp() //输出所有读者信息

{

for (int i=0;i<=top;i++)

read[i]disp();

}

void readerdata();//读者库维护

~RDatabase() //析构函数,将read[]写到readertxt文件中

{

fstream file("readertxt",ios::out);

for (int i=0;i<=top;i++)

if (read[i]gettag()==0)

filewrite((char )&read[i],sizeof(read[i]));

fileclose();

}

};

void RDatabase::readerdata()

{

char choice;

char rname[20];

int readerid;

Reader r;

while (choice!='0')

{

cout <<"\n\n\t\t\t读 者 维 护\n\n\n\t\t 1 新 增\n\n\t\t 2 更 改\n\n\t\t 3 删 除\n\n\t\t 4 查 找\n\n\t\t 5 显 示\n\n\t\t 6 全 删\n\n\t\t 0 退 出"<<endl;

cin >> choice;

switch (choice)

{

case '1':

cout << "输入读者编号:";

cin >> readerid;

cout << "输入读者姓名:";

cin >> rname;

addreader (readerid,rname);

break;

case '2':

cout << "输入读者编号:";

cin >> readerid;

r=query(readerid);

if (r==NULL)

{

cout << " 该读者不存在 "<<endl;

break;

}

cout << "输入新的姓名:";

cin >> rname;

r->setname(rname);

break;

case '3':

cout << " 输入读者编号:";

cin >> readerid;

r=query(readerid);

if (r==NULL)

{

cout <<" 该读者不存在" << endl;

break;

}

r->delbook();

break;

case '4':

cout << "读入读者编号:";

cin >> readerid;

r=query(readerid);

if (r==NULL)

{

cout <<"该读者不存在"<< endl;

break;

}

r->disp();

break;

case '5':

disp();

break;

case '6':

clear();

break;

default:cout<<"输入错误,请从新输入:";break;

}

}

}

//图书类,实现对图书的描述,图书的编号,书名,借出,还入等

class Book

{

private:

int tag;//删除标记 1:已删 0:未删

int no;//图书编号

char name[20];//书名

int onshelf;//是否再架 1:再架 2:已借

public:

Book(){}

char getname() { return name; }//获取姓名

int getno(){ return no; }//获取图书编号

int gettag(){ return tag; }//获取删除标记

void setname(char na[])//设置书名

{

strcpy(name,na);

}

void delbook(){ tag=1;}//删除图书

void addbook(int n,char na)//增加图书

{

tag=0;

no=n;

strcpy(name,na);

onshelf=1;

}

int borrowbook()//借书 *** 作

{

if (onshelf==1)

{

onshelf=0;

return 1;

}

return 0;

}

void retbook()//还书 *** 作

{

onshelf=1;

}

void disp()//输出图书

{

cout << setw(6) << no << setw(18) << name << setw(10)

<<(onshelf==1 "在架":"已借") <<endl;

}

};

//图书库类,实现对图书的维护,查找,删除等

class BDatabase

{

private:

int top; //图书记录指针

Book book[Maxb]; //图书记录

public:

BDatabase()//构造函数,将booktxt读到book[]中

{

Book b;

top=-1;

fstream file("booktxt",ios::in);

while (1)

{

fileread((char )&b,sizeof(b));

if (!file) break;

top++;

book[top]=b;

}

fileclose();

}

void clear()//全删

{

top=-1;

}

int addbook(int n,char na)//增加图书

{

Book p=query(n);

if (NULL==p)

{

top++;

book[top]addbook(n,na);

return 1;

}

return 0;

}

Book query(int bookid)//查找图书

{

for (int i=0;i<=top;i++)

if (book[i]getno()==bookid &&book[i]gettag()==0)

{

return &book[i];

}

return NULL;

}

void bookdata();//图书库维护

void disp()

{

for (int i=0;i<=top;i++)

if (book[i]gettag()==0)

book[i]disp();

}

~BDatabase()//析构函数,将book[]写到booktxt文件中

{

fstream file("booktxt",ios::out);

for (int i=0;i<=top;i++)

if (book[i]gettag()==0)

filewrite((char )&book[i],sizeof(book[i]));

fileclose();

}

};

void BDatabase::bookdata()

{

char choice;

char bname[40];

int bookid;

Book b;

while (choice!='0')

{

cout <<"\n\n\n\t\t\t图 书 维 护 "<<endl<<endl;

cout<<"\t\t1 新 增\n \t\t2 更 改\n\t\t3 删 除\n\t\t4 查 找\n\t\t5 显 示\n\t\t6 全 删\n\t\t0 退 出"<<endl;

cin >> choice;

switch (choice)

{

case '1':

cout << "输入图书编号:"<<endl;

cin >> bookid;

cout << "输入图书书名:"<<endl;

cin >> bname;

addbook(bookid,bname);

break;

case '2':

cout << "输入图书编号:"<<endl;

cin >> bookid;

b=query(bookid);

if (b==NULL)

{

cout << " 该图书不存在 "<<endl;

break;

}

cout << "输入新的书名:"<<endl;

cin >> bname;

b->setname(bname);

break;

case '3':

cout <<" 读入图书编号:"<<endl;

cin >> bookid;

b=query(bookid);

if (b==NULL)

{

cout <<" 该图书不存在" << endl;

break;

}

b->delbook();

break;

case '4':

cout << " 读入图书编号:"<<endl;

cin >> bookid;

b=query(bookid);

if (b==NULL)

{

cout <<" 该图书不存在"<< endl;

break;

}

b->disp();

break;

case '5':

disp();

break;

case '6':

clear();

break;

default:cout<<"输入错误,请从新输入:";

}

}

}

//main() 函数的实现,程序的主界面的引导

void main()

{

char choice;

int bookid,readerid;

RDatabase ReaderDB;

Reader r;

BDatabase BookDB;

Book b;

while(choice!='0')

{

cout <<endl<<endl<<"\t\t\t 图 书 管 理 系 统\n\n\n";

cout <<"\t\t\t1 借 书\n\n\t\t\t2 还 书 \n\n\t\t\t3 图 书 维 护\n\n\t\t\t4 读 者 维 护\n\n\t\t\t0 离 开"<<endl;

cin >> choice;

switch (choice)

{

case '1':

cout <<" 借书 读者编号:";

cin >>readerid;

cout <<" 图书编号: ";

cin >>bookid;

r=ReaderDBquery(readerid);//按编号查找

if (NULL==r)

{

cout <<" 不存在该读者,不能借书"<< endl;

break;

}

b=BookDBquery(bookid);

if (b==NULL)

{

cout <<" 不存在该图书,不能借书"<< endl;

break;

}

if (b->borrowbook()==0)

{

cout << " 该图书已借出,不能借书"<< endl;

break;

}

r->borrowbook(b->getno());

break;

case '2':

cout<<"还书\n 读者编号:";

cin >>readerid;

cout << " 图书编号:";

cin >>bookid;

r=ReaderDBquery(readerid);

if (r==NULL)

{

cout <<" 不存在该读者,不能还书" << endl;

break;

}

b=BookDBquery(bookid);

if (b==NULL)

{

cout <<" 不存在该图书,不能还书" <<endl;

break;

}

b->retbook();

r->retbook(b->getno());

break;

case '3':

BookDBbookdata();

break;

case '4':

ReaderDBreaderdata();

break;

default:cout<<"输入错误,请从新输入:";

}

}

}

以上就是关于职工信息管理系统:(c++程序设计)详细如下全部的内容,包括:职工信息管理系统:(c++程序设计)详细如下、用C++设计一个学生考试成绩信息管理程序、图书信息管理系统设计c程序设计等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10006482.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存