网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
08月13日漏签0天
c语言吧 关注:798,977贴子:4,358,485
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 6回复贴,共1页
<<返回c语言吧
>0< 加载中...

编程题,大家都进来看看

  • 只看楼主
  • 收藏

  • 回复
  • 业余de上帝
  • 毛蛋
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
学生信息:学号,姓名,年龄,性别。试设计--学生信息管理系统,使之能提供以下功能:1,学生信息录入。2,学生信息浏览。3学生信息查询。4学号排序。5学生信息的删除与修改。


  • gccer
  • 毛蛋
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
恩,已阅


2025-08-13 15:18:51
广告
不感兴趣
开通SVIP免广告
  • _Echooff
  • 强能力者
    7
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "conio.h"
#define LEN sizeof(STU)
typedef struct student{                       //定义单向链表.
char *id;
char *name;
int score;
struct student *next;
}STU;
typedef struct{
   char id[20];
   char name[20];
   int score;
}DATA;
STU *insert(STU *head,STU *p){          
STU *p0=p;
STU *p1=head;
STU *p2=p1;
if(p1==NULL){
head=p0;
p0->next=NULL;
}
else{
if(strcmp(p0->id,p1->id)<0){
p0->next=head;
head=p0;
}
else{
while(p1!=NULL&&strcmp(p1->id,p0->id)<0){
   p2=p1;
   p1=p1->next;
}
p0->next=p2->next;
p2->next=p0;
}
}
return head;
}
STU *creat(void){
STU *head=NULL;
STU *p;
char temp[20];
p=(STU *)malloc(LEN);
printf("id:");
gets(temp);
p->id=(char *)malloc(strlen(temp)+1);
strcpy(p->id,temp);
if(!strcmp(p->id,"0")){
free(p);
return head;
}
while(1){
printf("name:");
gets(temp);
p->name=(char *)malloc(strlen(temp)+1);
strcpy(p->name,temp);
printf("score:");
scanf("%d%*c",&p->score);
head=insert(head,p);
p=(STU *)malloc(LEN);
   printf("id:");
   gets(temp);
   p->id=(char *)malloc(strlen(temp)+1);
   strcpy(p->id,temp);
if(!strcmp(p->id,"0")){
free(p);
return head;
}
}
}
STU *datain(void){
   STU *head=NULL,*Temp;
   DATA temp;
   FILE *fp;
   int n;
   fp=fopen("c:\\data.txt","r");
   if(fp==NULL){
   printf("open file error.plz check your c:\\data.txt");
   getch();
   exit(-1);
   }
   while(1){
   n=fread(&temp,sizeof(DATA),1,fp);
   if(n!=1) break;
   Temp=(STU *)malloc(LEN);
   Temp->id=(char *)malloc(strlen(temp.id)+1);
   Temp->name=(char *)malloc(strlen(temp.name)+1);
   strcpy(Temp->id,temp.id);
   strcpy(Temp->name,temp.name);
Temp->score=temp.score;
   head=insert(head,Temp);
   }
   return head;
}
void save(STU *head){
   FILE *fp;
   STU *p=head;
   DATA temp;
   int n=0,i;
   if(head==NULL){
       fp=fopen("c:\\data.txt","w");
       fclose(fp);
       return;
   }
   while(p!=NULL){
   n++;
   p=p->next;
   }
   fp=fopen("c:\\data.txt","w");
   if(fp==NULL){



  • _Echooff
  • 强能力者
    7
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
   printf("not enough memory");
   getch();
   exit(0);
   }
   for(i=0,p=head;i<n;i++){
   strcpy(temp.id,p->id);
   strcpy(temp.name,p->name);
   temp.score=p->score;
   fwrite(&temp,sizeof(DATA),1,fp);
   p=p->next;
   }
   fclose(fp);
}
  
  
  
/*输出链表函数*/
void display(STU *head){         
STU *p=head;
if(p==NULL){
system("cls");
printf("none list\n");
getch();
return;
}
printf("=========================================\n");
printf("%-10s\t%-8s\t%3s\n","ID","NAME","SCORE");
while(p!=NULL){
printf("%-10s\t%-8s\t%3d\n",p->id,p->name,p->score);
p=p->next;
}
printf("=========================================\n");
getch();
}
void search(STU *head,char *id){
STU *p=head;
if(head==NULL){
system("cls");
   printf("=========================================\n");
printf("         this is a none list\n");
printf("=========================================\n");
getch();
}
else{
while(strcmp(p->id,id)!=0&&p->next!=NULL){
p=p->next;
}
if(strcmp(p->id,id)==0){
printf("=========================================\n");
printf("%-10s\t%-8s\t%3s\n","ID","NAME","SCORE");
printf("%-10s\t%-8s\t%3d\n",p->id,p->name,p->score);
printf("=========================================\n");
getch();
}
else{
printf("=========================================\n");
printf("            cannot find\n");
printf("=========================================\n");
getch();
}
}
}
STU *del(STU *head,char *id){
     STU *p,*delnode;
     p=head;
     delnode=p;
     if(p==NULL){
         system("cls");
         printf("=========================================\n");
         printf("        this is a none list!\n");
         printf("=========================================\n");
         getch();
         return head;
     }
     else{
         if(strcmp(delnode->id,id)==0){
             head=delnode->next;
             free(delnode);
             return head;



  • _Echooff
  • 强能力者
    7
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
         }
         else{
             while(delnode!=NULL&&strcmp(delnode->id,id)!=0){
                 p=delnode;
                 delnode=delnode->next;
             }
             if(delnode==NULL){
                 printf("no such id\n");
                 getch();
                 return head;
             }
             else{
                 p->next=delnode->next;
                 free(delnode);
                 return head;
             }
         }
     }
}
void sort(STU *head){
int i,j,n=0;
STU st[50];
STU *p;
STU temp;
if(head==NULL){
system("cls");
printf("=========================================\n");
printf("        this is a none list!\n");
printf("=========================================\n");
getch();
}
else{
for(p=head;p!=NULL;){                   //遍历整个链表确定节点数n
   p=p->next;
   n++;
}
p=head;
for(i=0;i<n;i++){                                        //复制链表数据域内容到结构体数组
st[i].id=(char *)malloc(strlen(p->id)+1);
st[i].name=(char *)malloc(strlen(p->name)+1);
strcpy(st[i].id,p->id);
strcpy(st[i].name,p->name);
st[i].score=p->score;
p=p->next;
}
for(i=0;i<n-1;i++)                            //冒泡排序
for(j=0;j<n-1-i;j++)
if(st[j].score<st[j+1].score){
   temp=st[j];
   st[j]=st[j+1];



  • _Echooff
  • 强能力者
    7
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
   st[j+1]=temp;
}
printf("=========================================\n");
printf("%-10s\t%-8s\t%3s\n","ID","NAME","SCORE");
for(i=0;i<n;i++){
printf("%-10s\t%-8s\t%3d\n",st[i].id,st[i].name,st[i].score);
}
printf("=========================================\n");
getch();
}
}
STU *check(void){
   FILE *fp;
   STU *head;
   int n;
   fp=fopen("c:\\check.txt","r");
   if(fp==NULL){
   fp=fopen("c:\\check.txt","w");
   fprintf(fp,"%d",0);
   fclose(fp);
   fp=fopen("c:\\check.txt","r");
   }
   fscanf(fp,"%d",&n);  
   fclose(fp);
   n++;
   if(n==1){
   printf("first time to use.please input data\n");
   getch();
   system("cls");                     
   head=creat();
   fp=fopen("c:\\check.txt","w");
   fprintf(fp,"%d",n);
   fclose(fp);
   return head;
   }
   head=datain();
   fp=fopen("c:\\check.txt","w");
   fprintf(fp,"%d",n);
   fclose(fp);
   return head;     
}
int main(){
   STU *head=NULL,*pNew;
   char temp[20];
   int choice;
   system("title Admin");
   head=check();
   for(;;){
   system("cls");
   printf("================================\n");
   printf("1.display\n");
   printf("2.insert\n");
   printf("3.del\n");
   printf("4.search\n");
   printf("5.display by score\n");
   printf("6.exit and save\n");
   printf("================================\n");
   printf("choice:");
   scanf("%d%*c",&choice);
   switch(choice){
   case 1:display(head);break;
   case 2:pNew=(STU *)malloc(LEN);
   printf("id:");
   gets(temp);
   pNew->id=(char *)malloc(strlen(temp)+1);
   strcpy(pNew->id,temp);
   printf("name:");
   gets(temp);
   pNew->name=(char *)malloc(strlen(temp)+1);
   strcpy(pNew->name,temp);
   printf("score:");
   scanf("%d%*c",&pNew->score);
   head=insert(head,pNew);
   break;
   case 3:printf("input the id you wanna del:");
   gets(temp);
   head=del(head,temp);
   break;
   case 4:printf("input the id you wanna search:");
   gets(temp);
   search(head,temp);
   break;
   case 5:sort(head);
   break;
   default:save(head);
   exit(0);
   }
   }
   getch();
   return 0;
}



登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 6回复贴,共1页
<<返回c语言吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示