m0_59971450 2021-07-09 16:14 采纳率: 50%
浏览 46
已采纳

改为C++,具体怎么该呀,

#include<stdio.h>
#include <string.h>
#include <stdlib.h>
struct teach{
int xh;
char gh[20];
char xm[20];
int gl;
char zc[20];
double gz;
char dh[13];
struct teach *next;
};
void menu1();
void menu2();
void menuM();
int load();
void creatList(struct teach *head);
void brow(struct teach *head);
void find(struct teach *head);
void findNo(struct teach *head,char no[]);
void del(struct teach *head,char gh[]);
int main(){
int choice;
char gh[20];
struct teach *head;
int dl=load();
if(dl==1){
creatList(head);
while(1){
menuM();
printf("请选择操作(0-5):\n");
scanf("%d",&choice);
switch(choice){
case 1:
brow(head);
break;
case 2:
find(head);
break;
case 3:
printf("请输入工号:\n");
scanf("%s",gh);
del(head,gh);
break;
case 4:
break;
case 5:
break;
default:
return 0;
}
system("pause");
system("cls");
}
}
return 0;
}
void del(struct teach *head,char gh[]){
struct teach *pre,*p;
if(head==NULL){
printf("表为空!\n");
return;
}
pre=head;
p=head->next;
while(p!=NULL){
if(strcmp(p->gh,gh)==0){
pre->next=p->next;
printf("删除成功!\n");
printf("序号 工号\t姓名\t工龄\t职称\t工资\t联系方式\n");
printf("%d %s\t%s\t%d\t%s\t\t%-6.2f\t\t%-s\n",
p->xh,p->gh,p->xm,p->gl,p->zc,p->gz,p->dh);
free(p);
break;
}
pre=p;
p=p->next;
}
if(p == NULL) printf("查无此人!\n");
}
void findNo(struct teach *head,char no[]){
if(head==NULL){
printf("表为空!\n");
return;
}
head=head->next;
printf("序号 工号\t姓名\t工龄\t职称\t工资\t联系方式\n");
while(head){
if(strcmp(head->gh,no)==0){
printf("%d %s\t%s\t%d\t%s\t\t%-6.2f\t\t%-s\n",
head->xh,head->gh,head->xm,head->gl,head->zc,head->gz,head->dh);
break;
}
head=head->next;
}
if(head == NULL) printf("查无此人!\n");
}
void find(struct teach *head){
int c,tage;
char no[20];
while(1){
printf("*********************************************\n");
printf("
1-----------按教工工号信息查询 \n");
printf("
2-----------按教工工龄信息查询 \n");
printf("
0-----------退出 *\n");
printf("**********************************************\n");
printf("请选择(0-2):\n");
scanf("%d",&c);
if(c==1){
printf("gh:");
scanf("%s",no);
findNo(head,no);
}
else if(c==2){
printf("gl:");
scanf("%d",&tage);
//findTage(head,tage);
}
else
return ;
}
}
void menuM(){
printf("*********************************************\n");
printf("
1-----------教工信息浏览 \n");
printf("
2-----------教工信息查询 \n");
printf("
3-----------教工信息删除 \n");
printf("
4-----------教工信息插入 \n");
printf("
5-----------教工信息修改 \n");
printf("
0-----------退出 *\n");
printf("**********************************************\n");
}
void brow(struct teach *head){
if(head==NULL){
printf("表为空!\n");
return;
}
printf("序号 工号\t姓名\t工龄\t职称\t工资\t联系方式\n");
head=head->next;
while(head){
printf("%d %s\t%s\t%d\t%s\t\t%-6.2f\t\t%-s\n",
head->xh,head->gh,head->xm,head->gl,head->zc,head->gz,head->dh);
head=head->next;
}
}
void creatList(struct teach *head){
FILE *fp;
struct teach tmp,tail;
fp=fopen("tea.txt","at+");
if(fp==NULL){
printf("Open file fail!\n");
head=NULL;
return;
}
head =(struct teach
)malloc(sizeof(struct teach));
head->next=NULL;
tail= head;
while(1){
tmp=(struct teach
)malloc(sizeof(struct teach));
tmp->next=NULL;
if(fscanf(fp,"%d %s %s %d %s %lf %s",&tmp->xh,tmp->gh,tmp->xm,&tmp->gl,tmp->zc,&tmp->gz,tmp->dh)!=7) break;
if(head->next==NULL){
head->next = tmp;
tail = tmp;
}else{
tail->next=tmp;
tail = tmp;
}
}
fclose(fp);
free(tmp);
}
void menu1(){
printf("**********************************\n");
printf("1------------登陆
\n");
printf("0------------退出
*\n");
printf("*************************************\n");
}
int load(){
int c=3,dl;
char name[20],pass[10];
while(c){
system("cls");
menu1();
printf("请选择(0/1):\n");
scanf("%d",&dl);
getchar();
if(dl==1){
printf("请输入用户名:\n");
scanf("%s",name);
printf("请输入密码:\n");
scanf("%s",pass);
c--;
if(strcmp("aaa",name)==0&&strcmp("123456",pass)==0){//登陆成功创建链表
return 1;
}else if(c!=0){
printf("用户名或密码错误,还有%d次机会\n",c);
system("pause");
}
else
return 0;
}
else
return 0;
}
}

  • 写回答

2条回答 默认 最新

  • qfl_sdu 2021-07-09 16:23
    关注

    stdio.h改为iostream
    string.h改为string
    stdlib.h可以删掉
    如果用到了string类型,需要在include下面添加using namespace std;
    scanf("%s",gh);这种改成cin >> gh;
    scanf("%d",&dl);这种改成cin >> dl; //注意,不需要加&符号
    printf("用户名或密码错误,还有%d次机会\n",c);改成 cout << "用户名或密码错误,还有"<< c << "次机会" << endl; //endl是回车符。

    cout <<"序号 工号\t姓名\t工龄\t职称\t工资\t联系方式" << endl;
    cout << p->xh <<" " << p->gh << "\t" << p->xm << "\t" << p->gl << "\t" << p->zc << "\t" << p->gz << "\t" << p->dh << endl;
    

    tmp=(struct teach*)malloc(sizeof(struct teach));改成tmp = new teach();

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已采纳回答 7月10日
  • 创建了问题 7月9日

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算