用C语言编写一个程序,内容为职工工资管理系统的设计与实现

用C语言编写一个程序,内容为职工工资管理系统的设计与实现,第1张

就这样吧,工资排序就是比较数的大小,这个会吧?既然只有3个人,就这么简单。如果要查询,就要先保存,写保存函数,再写读取函数,我就不写了。最后建议这种用链表比较好。

#include<stdioh>

#include<stdlibh>

void main()

{

char num[3];

char name[3][9];

char type[3][9];

float money[3];

float sum = 0;

int i;

float average;

printf("请输入职工的信息,\n:");

for(i = 0;i<3;i++)

{

num[i] = i+1;

printf("请输入第%d个信息name:\n",i+1);

scanf("%s",name[i]);

printf("请输入第%d个信息type:\n",i+1);

scanf("%s",type[i]);

printf("请输入第%d个信息money:\n",i+1);

scanf("%f",&money[i]);

}

for(i = 0;i<3;i++)

{

printf("%d %s %s %f",num[i],name[i],type[i],money[i]);

printf("\n");

}

for(i = 0;i<3;i++)

{

sum+=money[i];

}

average = sum/3;

printf("平均工资是:%f\n",average);

getch();

}

#include <iostream>

#include <string>

#define MaxHEAP 100

using namespace std;

class Elem{

private:

int objectID;

int priority;

string proName;

public:

Elem(int objectID=0,int priority=0){

setID(objectID);

setPri(priority);

setProN(proName);

}

int getID(){

return objectID;

}

int getPri(){

return priority;

}

string getProN(){

return proName;

}

void setID(int id){

objectID=id;

}

void setPri(int pri){

priority=pri;

}

void setProN(string s)

{

proName=s;

}

};

class Heap

{

private:

Elem items[MaxHEAP];

int size;

public :

Heap(){

Elem items[MaxHEAP];

setSize(0);}

void setSize(int sz)

{size=sz;}

int heapIsEmpty(){

return size==0;

}

void heapInsert(Elem newItem)

{if(size<MaxHEAP)

{

items[size]=newItem;

int place=size;

int parent=(place-1)/2;

while((parent>=0)&&(items[parent]getPri()<items[place]getPri()))

{

Elem temp=items[parent];

items[parent]=items[place];

items[place]=temp;

place=parent;

parent=(place-1/2);

}

++size;

}

heapRebuild(0);

}

Elem heapDelete(int ID)

{

Elem rootItem;

if(!heapIsEmpty())

{

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

if(items[i]getID()==ID)

{rootItem=items[i];

swap(items[i],items[0]);

}

items[0]=items[--size];

heapRebuild(0);

}

else cout<<"\n错误:目录为空"<<endl;

return rootItem;

}

void heapInit(){

setSize(0);

cout<<"空的项目"<<endl;}

void heapView(){

if(size==0){

cout<<"空的项目!"<<endl;

}

else{

cout<<"共有项目数: "<<size<<endl;

for(int ct=0;ct<size;ct++){

cout<<"ID: "<<items[ct]getID()<<" 优先级: "<<items[ct]getPri()

<<" 工资数目: " <<items[ct]getProN()<<endl;

}

}

}

void search(int ID)

{ int N=0;

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

if(items[i]getID()==ID)

{N++;

cout<<"ID: "<<items[i]getID()<<" 优先级: "<<items[i]getPri()

<<" 名称: " <<items[i]getProN()<<endl; }

if(!N) cout<<"未找到匹配的ID"<<endl;

}

void heapRebuild(int root)

{

int child=2root+1;

if(child<size)

{

int rightChild=child+1;

if((rightChild<size)&&(items[rightChild]getPri()>=items[child]getPri()))

{child=rightChild;

}

if(items[root]getPri()<=items[child]getPri())

{

Elem temp=items[root];

items[root]=items[child];

items[child]=temp;

heapRebuild(child);

}

}

}

};

class priQueue

{private:

Heap h;

public:

priQueue(){

Heap();

}

int priIsEmpty(){

return hheapIsEmpty();

}

void priInit(){

hheapInit();

}

void priInsert(Elem newItem){

hheapInsert(newItem);

}

Elem priDelete(int ID){

return hheapDelete(ID);

}

void priView(){hheapView();

}

void search(int ID)

{

hsearch(ID);

}

};

void showMenu(){

cout<<"------------------------------------------------"<<endl;

cout<<"-----------------工资管理系统-----------------"<<endl;

cout<<"------------------------------------------------"<<endl;

cout<<" 1重置"<<endl;

cout<<" 2输入"<<endl;

cout<<" 3删除"<<endl;

cout<<" 4查询"<<endl;

cout<<" 5打印"<<endl;

cout<<" 0退出"<<endl;

cout<<"------------------------------------------------"<<endl;

}

void showTip(){

cout<<"---------------------------------^_^-- *** 作完成!"<<endl;

cout<<"------------------------------------选择0-5继续"<<endl;

}

int main(){

string i="-1";

int ID,PRI;

string proName;

Elem in;

priQueue PQ;

PQpriInit();

system("cls");

showMenu();

cout<<"选择菜单中的数字以便处理数据!"<<endl;

cin>>i;

system("cls");

while(i!="0")

{ if(i=="1")

{ system("cls");

showMenu();

cout<<"你选择了1,项目将全部清空:"<<endl;

PQpriInit();

showTip();

}

else if(i=="2")

{system("cls");

showMenu();

cout<<"你选择了2,输入ID,优先级,工资"<<endl;

cout<<"输入 ID(数字):"<<endl;

cin>>ID;

cout<<"输入优先级(数字):"<<endl;

cin>>PRI;

cout<<"输入工资数目(数字):"<<endl;

cin>>proName;

insetID(ID);

insetPri(PRI);

insetProN(proName);

PQpriInsert(in);

showTip();

}

else if(i=="3")

{system("cls");

showMenu();

cout<<"你选择了3,请选择你要删除的ID号"<<endl;

cin>>ID;

PQpriDelete(ID);

showTip();

}

else if(i=="4")

{system("cls");

showMenu();

cout<<"你选择了4,输入要查找的项目ID号"<<endl;

cin>>ID;

PQsearch(ID);

showTip();

}

else if(i=="5")

{system("cls");

showMenu();

cout<<"你选择了5,整个系统工资情况显示如下:"<<endl;

PQpriView();

showTip();

}

else {

system("cls");

showMenu();

cout<<"无效输入!"<<endl;

}

cin>>i;

system("cls");

}

return 0;

}

分数太低了。这个不好做啊。

#include <stdioh>

#include <malloch>

#include <stringh>

#include <conioh>

#define N 2

typedef struct Workers

{

int id;

char name[9];

char sex;  

int age;

int sal;

struct Workers next;

}  worker;

worker head;

int odd=0,even=0;

void initList()

{

    head=(worker )malloc(sizeof(worker));

    head->next=NULL;

}

void getMsg()

{

    int i;

    worker newD,p=head;

    while(p->next)

    {

        p=p->next;

    }

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

    {

        newD=(worker )malloc(sizeof(worker));

        newD->next=NULL;

        printf("please enter date\nid  name   sex   age  salary \n");

        scanf("%d %s %c %d %d",&newD->id,newD->name,&newD->sex,&newD->age,&newD->sal);

        p->next=newD;

        p=p->next;

    }

}

void saveData()

{

    FILE fpwd,fpwo;

    worker p=head;

    FILE fp=fopen("outputtxt","wb+");

    fpwd=fopen("worker3txt","wb+");

    fpwo=fopen("worker4txt","wb+");

    odd=even=0;

    while(p->next)

    {

        p=p->next;

        fwrite(p,sizeof(worker),1,fp);

        if(p->id%2==0){

            even++;

            fwrite(p,sizeof(worker),1,fpwo);}

        else{

            even++;

            fwrite(p,sizeof(worker),1,fpwd);}

    }

    fclose(fp);

    fclose(fpwd);

    fclose(fpwo);

}

void readData()

{

    FILE fp;int i;

    worker p,newD;

    p=head;

    fp=fopen("outputtxt","rb+");

                                                                                               

    while(p->next)

    {

        p=p->next;

    }

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

    {

        newD=(worker )malloc(sizeof(worker));

        newD->next=NULL;

        fread(newD,sizeof(worker),1,fp);

        p->next=newD;

        p=p->next;

    }

    fclose(fp);

}

void showodd()

{  

    FILE fp;int i;

    fp=fopen("worker3txt","rb+");

        printf("以下为奇数\n");

    while(!feof(fp))

    {

        worker date;

        fread(&date,sizeof(worker),1,fp);

        printf("%d %s %c %d %d\n",dateid,datename,datesex,dateage,datesal);

    }

    fclose(fp);

}

void showeven()

{

    FILE fp;int i;

    fp=fopen("worker4txt","rb+");

        printf("以下为偶数\n");

    while(!feof(fp))

    {  

        worker date;

        fread(&date,sizeof(worker),1,fp);

        printf("%d %s %c %d %d\n",dateid,datename,datesex,dateage,datesal);

    }

    fclose(fp);

}

void main()

{

    while(1){

    worker p;

    char ch;

    initList();

    p=head;

    printf("\nplease select 1,2,others \n");

    ch=getch();

    if(ch=='1')  

    {

    getMsg();

    saveData();

    }

    else if(ch=='2')  

    {

        readData();

        while(p->next)

        {  

        p=p->next;

        printf("%d %s %c %d %d\n",p->id,p->name,p->sex,p->age,p->sal);

        }

    }

    else

    {

                                                                                                

        printf("are u need to show odd and even \n");

        ch=getch();

        if(ch=='1')

        {

            showodd();

            showeven();

        }

                                                                                               

                                                                                               

    }              

                                                                                           

                                                                                           

    }

}

以上就是关于用C语言编写一个程序,内容为职工工资管理系统的设计与实现全部的内容,包括:用C语言编写一个程序,内容为职工工资管理系统的设计与实现、求C语言 工资管理系统 原代码、哪位大神能帮我用c语言写个程序,是职工工资管理系统的,要求如下:等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存