17070047 / 17070047/CodeStructureCourse
路笑通
- Lingua principale
- C++
- Stelle
- 16
- Fork
- 2
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
1、实验目的
通过本实验掌握排序的基本算法和过程以及查找的基本方法和过程。
2、实验内容
设计一个排序和查找系统。能够实现对给定的一组学生的借书证信息(如:卡号、姓名、系别、班号等)进行排序和查找。
1)按照卡号顺序进行排序;
2)能够实现查找某个系的所有的借书卡号并输出。
3、实验要求
(1)建立关于借书证信息结点的结构体;
(2)定义借书证信息的记录并录入基本信息;
(3)写出用某种排序算法(如冒泡排序)按关键字对记录进行排序的算法函数;
(4)对借书证信息的记录按系名建立索引查找结构;
(5)输入某个要查找的系名,用索引查找方法查找并输出该系的所有借书证信息。
编译环境:Dev c++
```c
#include
#include
#include
#define MAXSIZE 100 //借书证信息记录个数的最大值
typedef struct { //建立关于借书证信息结点的结构体
int cardNum; //卡号
char name[10]; //姓名
char major[20]; //系名
int classNum; //班号
}libCardInfo;
typedef struct{ //定义借书证信息的记录
libCardInfo cardInfo;
}recordInfo; //记录类型定义
typedef struct{
recordInfo r[MAXSIZE+1]; //r[0]一般不用于存放排序码
int length; //待排序文件中记录的个数
}table; //待排序文件类型
void input(table *tab){ //录入基本信息
char s='Y';
tab->length=1;
while(s=='Y' || s=='y' && tab->length <= MAXSIZE)
{
printf("\n请输入借书证卡号:");
scanf("%d", &tab->r[tab->length].cardInfo.cardNum);
printf("请输入持卡人姓名:");
scanf("%s", &tab->r[tab->length].cardInfo.name);
printf("请输入持卡人系别:");
scanf("%s", &tab->r[tab->length].cardInfo.major);
printf("请输入持卡人班号:");
scanf("%d", &tab->r[tab->length].cardInfo.classNum);
printf("请问是否继续录入?(Y/N):");
scanf("%c", &s);
getchar();
tab->length++;
}
}
void output(libCardInfo *info){ //输出卡基本信息
printf("\t╔ ╗\n");
printf("\t 借书证卡号:%d\n",info->cardNum);
printf("\t 持卡人姓名:%s\n",info->name);
printf("\t 持卡人系别:%s\n",info->major);
printf("\t 持卡人班号:%d\n",info->classNum);
printf("\t╚ ╝\n");
}
void shellinsertsort(table *tab){ //希尔插入排序并输出
int i,j,d;
d=tab->length/2;
while(d>=1){
for(i=d+1; ilength; i++){ //从第d+1个元素开始,将所有的元素有序的插入相应分组中
tab->r[0]=tab->r[i]; //保存第i个元素
j=i-d; //向前找插入位置
while(j>0&&tab->r[0].cardInfo.cardNumr[j].cardInfo.cardNum){ //排序码比较找插入位置并后移
tab->r[j+d]=tab->r[j]; //记录后移
j=j-d; //继续向前查找
}
tab->r[j+d]=tab->r[0]; //插入第i个元素的副本
}
d=d/2;
}
for(i=1; ilength; i++){
output(&tab->r[i].cardInfo);
}
}
void seqSearch(table *tab){
int i=1, j=1;
char major[20];
printf("\n请输入你要查找的系名:");
scanf("%s",major);
while(ilength){
if(!strcmp(tab->r[i].cardInfo.major,major)){
output(&(tab->r[i].cardInfo));
j=0;
}
i++;
}
if(j) printf("\t\t 『没有该系别的记录!』\n");
}
//main.c
int main() {
int x, set=1;
table tab;
while(set){
printf("\t\t╔ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═╗\n");
printf("\t\t║ ║\n");
printf("\t\t╠ 欢迎使用借书证管理系统 ╣\n");
printf("\t\t║ ║\n");
printf("\t\t╔ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═╗\n");
printf("\t\t║ 1.录入借书证基本信息 ║\n");
printf("\t\t║ ║\n");
printf("\t\t║ 2.输出已有借书证信息 ║\n");
printf("\t\t║ ║\n");
printf("\t\t║ 3.系名查找借书证信息 ║\n");
printf("\t\t║ ║\n");
printf("\t\t║ 4.退出借书证管理系统 ║\n");
printf("\t\t╔ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═╗\n");
printf("请按你的需求选择操作:");
scanf("%d",&x);
switch(x){
case 1:input(&tab);break;
case 2:shellinsertsort(&tab);break;
case 3:seqSearch(&tab);break;
case 4:set=0;printf("\t\t\t『系统退出成功!』\n");break;
default: printf("没有该选项对应的操作!");
}
system("pause");
system("cls");
}
return 0;
}
```


Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
The issue describes a student coursework system for managing library cards with sorting and searching. The provided C code includes struct definitions, input/output functions, a shell sort, and a sequential search. To start, examine the main.c file to understand the menu flow. The task likely involves implementing the missing index search structure as per requirement (4) and integrating it with the existing sequential search. Run the program in a C environment like Dev-C++ to see current behavior, then design an index (e.g., a separate array or linked list) by major. Testing involves adding records and verifying the index search outputs all cards for a given major.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- c, cpp
- Ambito
- cli
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100