⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sql.cpp

📁 1、 模拟一间公司(有普通工人、经理、销售员、计时工人和计件工人)的雇员月工资单管理系统
💻 CPP
字号:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <graphics.h>
#include <strstrea.h>
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include "item.h"
#include "employee.h"
#include "labour.h"
#include "manager.h"
#include "commis.h"
#include "piece.h"
#include "hourly.h"
#include "lpiece.h"
extern void MessageBox(char *);
extern void judgeKey(Item *);
void loadFun()
{
  char fName[20], lName[20],ofile[25],type,t;
  int data1,data2,amount,flag,j=0,k=1;
  int x1=150,y1=150,x2=420,y2=220;
  setcolor(GREEN);
  rectangle(x1,y1,x2,y2);
  setfillstyle(1,CYAN);
  floodfill(x1+2,y1+2,GREEN);
  setfillstyle(1,BLACK);
  bar(x1+20,y2+1,x2+20,y2+20);
  bar(x2+1,y1+20,x2+20,y2);
  setcolor(BLUE);
  settextjustify(CENTER_TEXT,CENTER_TEXT);
  settextstyle(0,0,1);
  outtextxy((x1+x2)/2,y1+20,"Open a file:");
  bar(x1+30,y1+40,x2-30,y2-10);
  gotoxy(25,13);
  while(1)
  {
    t=getch();
    if(((t>47&&t<58)||(t>64&&t<91)||(t>96&&t<123)||(t==92)||(t==46)||(t==58))&&(j<24))
    {
      ofile[j]=t;
      cout<<ofile[j];
      j++;
    }
    else if(t==8&&j>0)
      {
	ofile[j-1]=0;
	gotoxy(wherex()-1,13);
	bar(x1+33+j*8,y1+40,x1+41+j*8,y2-10);
	j--;
      }
    else if(t==27) {k=0;break;}
    else if(t==13)
    {
      ofile[j]='\0';
      break;
    }
  }
  if(k)
  {
    ifstream fin(ofile);
    fin>>fName;
    if(strcmp(fName,"Employee:")==0)
    {
      Manager *pm;pm->delAll();
      HourlyWorker *ph;ph->delAll();
      CommissionWorker *pc;pc->delAll();
      PieceWorker *pp;pp->delAll();
      LabourWorker *pl;pl->delAll();
      LabourAndPiece *pa;pa->delAll();
      fin>>fName;
      if(strcmp(fName,"Manager:")==0)
      {
	fin>>amount;
	for(flag=0;flag<amount;flag++)
	{
	  fin>>fName>>lName>>data1>>data2;
	  pm=new Manager(fName,lName,data1,data2);
	}
	fin>>fName;
      }
      if(strcmp(fName,"Commission:")==0)
      {
	fin>>amount;
	for(flag=0;flag<amount;flag++)
	{
	  fin>>fName>>lName>>data1>>type;
	  pc=new CommissionWorker(fName,lName,data1,type);
	}
	fin>>fName;
      }
      if(strcmp(fName,"Hourly:")==0)
      {
	fin>>amount;
	for(flag=0;flag<amount;flag++)
	{
	  fin>>fName>>lName>>data1;
	  ph=new HourlyWorker(fName,lName,data1);
	}
	fin>>fName;
      }
      if(strcmp(fName,"Piece:")==0)
      {
	fin>>amount;
	for(flag=0;flag<amount;flag++)
	{
	  fin>>fName>>lName>>data1>>type;
	  pp=new PieceWorker(fName,lName,data1,type);
	}
	fin>>fName;
      }
      if(strcmp(fName,"Labour:")==0)
      {
	fin>>amount;
	for(flag=0;flag<amount;flag++)
	{
	  fin>>fName>>lName>>data1;
	  pl=new LabourWorker(fName,lName,data1);
	}
	fin>>fName;
      }
      if(strcmp(fName,"LabourAndPiece:")==0)
      {
	fin>>amount;
	for(flag=0;flag<amount;flag++)
	{
	  fin>>fName>>lName>>data1>>data2>>type;
	  pa=new LabourAndPiece(fName,lName,data1,data2,type);
	}
	fin>>fName;
      }
    MessageBox("Load Completed");
    }
    else MessageBox("Error:can't load the file's data");
    fin.close();
  }
  setfillstyle(1,BLUE);
  bar(x1,y1,x2+20,y2+20);
};

void saveFun()
{
  char fName[20], lName[20],ofile[25],type,t;
  int data1,data2,amount,flag,j=0,k=1;
  int x1=150,y1=150,x2=420,y2=220;
  setcolor(GREEN);
  rectangle(x1,y1,x2,y2);
  setfillstyle(1,CYAN);
  floodfill(x1+2,y1+2,GREEN);
  setfillstyle(1,BLACK);
  bar(x1+20,y2+1,x2+20,y2+20);
  bar(x2+1,y1+20,x2+20,y2);
  setcolor(BLUE);
  settextjustify(CENTER_TEXT,CENTER_TEXT);
  settextstyle(0,0,1);
  outtextxy((x1+x2)/2,y1+20,"Save to file:");
  bar(x1+30,y1+40,x2-30,y2-10);
  gotoxy(25,13);
  while(1)
  {
    t=getch();
    if(((t>47&&t<58)||(t>64&&t<91)||(t>96&&t<123)||(t==92)||(t==58)||(t==46))&&(j<24))
    {
      ofile[j]=t;
      cout<<ofile[j];
      j++;
    }
    else if(t==8&&j>0)
      {
	ofile[j-1]=0;
	gotoxy(wherex()-1,13);
	bar(x1+33+j*8,y1+40,x1+41+j*8,y2-10);
	j--;
      }
    else if(t==27) {k=0;break;}
    else if(t==13)
    {
      ofile[j]='\0';
      break;
    }
  }
  if(k)
  {
    Manager *pm;
    CommissionWorker *pc;
    HourlyWorker *ph;
    PieceWorker *pp;
    LabourWorker *pl;
    LabourAndPiece *pa;
    ofstream fout(ofile);
    fout<<"Employee:"<<endl;
    pm->saveList(fout);
    pc->saveList(fout);
    ph->saveList(fout);
    pp->saveList(fout);
    pl->saveList(fout);
    pa->saveList(fout);
    MessageBox("Saving...  Ok!");
  }
  setfillstyle(1,BLUE);
  bar(x1,y1,x2+20,y2+20);
};

void quitFun()
{
MessageBox("Exiting...  Bye!!!");
exit(0);
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -