高分求一个c语言程序

qianxiyun 2003-12-24 11:34:57
编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班号和成绩,教师数据由编号、姓名、职称、和部门。要求将编号、姓名输入和显示设计成一个类person,并作为学生数据操作类student和教师数据操作类teacher的基类。
class person
{
private:
int no;
char name[10];
public:
void input();
void disp();
};
class student:public person
{
private:
char depart[6];
int degree;
public:
void input();
void disp();
};

class teacher:public person
{
private:
char prof[10];
char depart[10];
public:
void input();
void disp();
};

帮忙,谢谢:)给我程序我立刻给分!
...全文
48 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
godhate 2003-12-27
  • 打赏
  • 举报
回复
赶紧给分啊,说话算不算啊!
wodeyouxian 2003-12-27
  • 打赏
  • 举报
回复
是啊是啊,作业一定要自己做的,不然学不到好东西的
holy198048 2003-12-27
  • 打赏
  • 举报
回复
干这行,必须自己做啊
analyser2003 2003-12-27
  • 打赏
  • 举报
回复
你又来求程序?
sky914 2003-12-26
  • 打赏
  • 举报
回复
佩服!
作业还是自己做比较好啊!
liushuaiboy 2003-12-26
  • 打赏
  • 举报
回复
grooving(东游西逛)兄,佩服佩服
dunpher 2003-12-25
  • 打赏
  • 举报
回复
没意思
Linevan 2003-12-25
  • 打赏
  • 举报
回复
又是作业题。。。。。。
grooving 2003-12-25
  • 打赏
  • 举报
回复
#include "stdio.h"
#include "string.h"
typedef struct
{ char name[6];
int num;
int eng,math,tot;
} STUDENT;

readdat(STUDENT *stu,int *nn)
{
int i=0,n=*nn;
FILE *fp;
if((fp=fopen("record.txt","r"))==NULL)
{ printf("The record.txt can't open!");exit(0);
}
while(i<n)
{ stu[i].num=1001+i;
fscanf(fp,"%s %d %d",stu[i].name,&stu[i].eng,&stu[i].math);
if(!strcmp(stu[i].name,"****"))break;
if(stu[i].eng>=0&&stu[i].eng<=100&&stu[i].math>=0&&stu[i].math<=100)
{ stu[i].tot=stu[i].eng+stu[i].math;
i++;
}
}
fclose(fp);
*nn=i;
}

creat(STUDENT *stu,int *nn)
{
int n,i=0;
clrscr();
printf("Please enter the NUMBER of the record(s):(1~10)");
scanf("%d",&n);
if(n<1||n>10)
{ printf("The number is not correct!!");
exit(0);
}
else *nn=n;
printf("Please input the record(s) as following format:\n");
printf("Name English Math\n\n");
while(i<n)
{ stu[i].num=1001+i;
scanf("%s %d %d",stu[i].name,&stu[i].eng,&stu[i].math);
if(stu[n].eng>=0&&stu[n].eng<=100&&stu[n].math>=0&&stu[n].math<=100)
{ stu[i].tot=stu[i].eng+stu[i].math;
i++;
}
}
printf("\nThe record(s) is(are) inputed successfully\n");
}

index()
{ clrscr();
printf("\n\n\t1 Init Record(s)\n");
printf("\t2 List Record(s)\n");
printf("\t3 Insert Record\n");
printf("\t4 Delete Record\n");
printf("\t5 Modify Record\n");
printf("\t6 Search the Max Score\n");
printf("\t0 Exit\n\n");
}

list(STUDENT *stu,int n)
{
int i;
clrscr();
printf(" Num Name English Math TotalScore\n\n");
for(i=0;i<n;i++)
printf(" %-10d%-10s%-10d%-10d%-12d\n",stu[i].num,stu[i].name,stu[i].eng,stu[i].math,stu[i].tot);
}

insert(STUDENT **student,int *nn)
{
int i,n=*nn;
STUDENT *stu=*student;
clrscr();
if(n>=10)
{ stu=(STUDENT *)realloc(stu,(sizeof(STUDENT))*(n+1));
if(!stu) {printf("Insert Failed!!"); exit(0);}
*student=stu;
}
stu[n].num=stu[n-1].num+1;
printf("Please enter the Student's Name and English and Math's Score\n");
scanf("%s %d %d",stu[n].name,&stu[n].eng,&stu[n].math);
if(stu[n].eng>=0&&stu[n].eng<=100&&stu[n].math>=0&&stu[n].math<=100)
{ stu[n].tot=stu[n].eng+stu[n].math;
(*nn)+=1;
printf("\n\nThe record is inserted successfully");
}
else printf("\n\nThe score is(are) Error\n");
}

delete(STUDENT *stu,int *nn)
{
int i,m;
list(stu,*nn);
printf("\n\nPlease Enter the Num that you want to delete:");
getchar();
scanf("%d",&m);
if( (m>1000) && (m<=*nn+1000) )
{ for(i=0;i<*nn;i++)
if(stu[i].num==m)break;
if(i==*nn)
printf("\n\nThe %4d's record is not exist\n" ,m);
else
{ for(;i<*nn-1;i++)
stu[i]=stu[i+1];
(*nn)-=1;
printf("\n\nThe record is deleted successfully\n");
}
}
else printf("\n\nThe %4d's record is not exist\n" ,m);
}

modify(STUDENT *stu,int n)
{
int m,i;
STUDENT a;
list(stu,n);
printf("\n\nPlease Enter the Num that you want to delete(Enter n)to Cancer:");
getchar();
scanf("%d",&m);
if((m>1000)&&m<=n+1000)
{ for(i=0;i<n;i++)
if(stu[i].num==m)break;
if(i==n)
{ printf("\n\nThe %4d's record is not exist\n" ,m);
exit(0);
}
printf("Please enter the English and Math's Score\n");
scanf("%d %d",&a.eng,&a.math);
if(a.eng>=0&&a.eng<=100&&a.math>=0&&a.math<=100)
{ m=m-1;
stu[i].eng=a.eng;
stu[i].math=a.math;
stu[i].tot=stu[i].eng+stu[i].math;
printf("\n\nThe record is modified successfully\n");
}
else printf("\n\nThe score is(are) Error\n");
}
else printf("\n\nThe %4d's record is not exist\n" ,m);
}

search(STUDENT *stu,int n)
{
int i,k=0;
clrscr();
for(i=1;i<n;i++)
if(stu[i].tot>stu[k].tot) k=i;
printf("The best score is:\t%5d\n\n",stu[k].tot);
printf("The record's detail is(are): \n");
printf(" Num Name English Math TotalScore\n\n");
for(i=0;i<n;i++)
if(stu[i].tot==stu[k].tot)
printf(" %-10d%-10s%-10d%-10d%-12d\n",stu[i].num,stu[i].name,stu[i].eng,stu[i].math,stu[i].tot);
}

main()
{
STUDENT *stu;
int i,n=10,r;
stu=(STUDENT *)malloc(sizeof(STUDENT)*n);
if(!stu)
{ printf("ERROR\n"); exit(0); }
readdat(stu,&n);
while(1)
{ index();
printf(" Please choose the operation's number you want:");
scanf("%d",&r);
switch(r)
{ case 0: exit(0);
case 1: { creat(stu,&n); break; }
case 2: { list(stu,n); break; }
case 3: { insert(&stu,&n); break; }
case 4: { delete(stu,&n); break; }
case 5: { modify(stu,n); break; }
case 6: { search(stu,n); break; }
default: continue;
}
printf("\n\n\nPlease press Enter to continue...");
getchar();getchar();
}
}
19830711 2003-12-25
  • 打赏
  • 举报
回复
up
Bandry 2003-12-25
  • 打赏
  • 举报
回复
没意思
qianxiyun 2003-12-24
  • 打赏
  • 举报
回复
请大家帮个忙好吗?先谢谢了

69,335

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧