Developed by Zhuxiaoxie Xiaoboren and Zhangcui
经过几个星期的奋战,我们三人终于把课设弄完了,在体验了成功的快感的同时也感受到了debug的痛苦与煎熬,幸而检查的时候程序没有挂,自觉写的还可以,所以扔上来纪念一下
总体思路
界面控制流程图
头晕勿看…
// main.c
#include <stdio.h>
#include "function.h"
#include "tool_f.h"
#include "console_output_control.h"
int main() {
Init();
int isRun [FUNCNUM] = {
0};
int state = 1;
pCls p = CreateClass();
while (state) {
Cls();
printf("*****************************************************************************\n");
printf("* 1. Read from a file *\n");
printf("* 2. Append record manually *\n");
printf("* 3. Calculate total and average score of every course *\n");
printf("* 4. Calculate total and average score of every student *\n");
printf("* 5. Sort in descending order by total score of every student *\n");
printf("* 6. Sort in ascending order by total score of every student *\n");
printf("* 7. Sort in ascending order by number *\n");
printf("* 8. Sort in dictionary order by name *\n");
printf("* 9. Search by number *\n");
printf("* 10. Search by name *\n");
printf("* 11. Statistic analysis for every course *\n");
printf("* 12. List record *\n");
printf("* 13. Write to a file *\n");
printf("* 14. Correct the information of a student *\n");
printf("* 0 . Exit *\n");
printf("*****************************************************************************\n\n");
printf(" Please input your choice: \n\n");
printf(" ");
scanf("%d",&state);
TurnPage(state);
if (!IsRun(isRun,state,p)) {
continue ;
}
switch (state) {
case 0 :
isRun[0] = 1;
Free(p);
EndPut();
break;
case 1 :
if (Input(p) == 0)
isRun[1] = 1;
break;
case 2:
if (ManualInput(p)==0)
isRun[2] = 1;
break;
case 3:
isRun[3] = 1;
ScoreofCrs(p);
break;
case 4:
isRun[4] = 1;
ScoreofStu(p);
break;
case 5:
isRun[5] = 1;
SortbyDScore(p);
break;
case 6:
isRun[6] = 1;
SortbyAScore(p);
break;
case 7:
isRun[7] = 1;
SortbyNum(p);
break;
case 8:
isRun[8] = 1;
SortbyName(p);
break;
case 9:
isRun[9] = 1;
printf("Please input the Stu No. you want:\n");
int no;
scanf("%d",&no);
pStu pstu = SearchNum (p,no);
if (pstu == NULL) {
TurnPage(-1);
printf("No such a student!\n");
} else {
PrintListboard(p->sumcrs);
PrintStu(&pstu->data,p->sumcrs);
}
break;
case 10:
isRun[10] = 1;
printf("Please input the name you want:\n");
char s[NAMEMAX+1];
getchar();
gets(s);
pstu = SearchName (p->inf.head->next,s);
if (pstu == NULL) {
TurnPage(-1);
printf("No such a student!\n\n");
break;
}
PrintListboard(p->sumcrs);
while (pstu)
{
PrintStu(&pstu->data,p->sumcrs);
pstu = SearchName(pstu->next,s);
}
break;
case 11:
isRun[11] = 1;
Analysis(p);
break;
case 12:
isRun[12] = 1;
ListRecord(p);
break;
case 13:
isRun[13] = 1;
WtF(p);
break;
case 14:
isRun[14] = 1;
Correct(p);
break;
default :
printf("ERROR ! NO SUCH A CHOICE! \n");
printf("Please input your choice again:\n");
}
}
return 0;
}
//function.h
/* 1. Read from a file
* 2. Append record manually
* 3. Calculate total and average score of every course
* 4. Calculate total and average score of every student
* 5. Sort in descending order by total score of every student
* 6. Sort in ascending order by total score of every student
* 7. Sort in ascending order by number
* 8. Sort in dictionary order by name
* 9. Search by number
* 10. Search by name
* 11. Statistic analysis for every course
* 12. List record
* 13. Write to a file
* 14. Correct the information of a student that has already been stored
* 0 . Exit
*/
#define STUNOMAX 10 // Max of length of Stu No.
#define NAMEMAX 20 // Max of length of name
#define SUBMAX 6 // Max of subjects
#define STUMAX 30 // Max of students in a class
#define FILENAMEMAX 32 //Max of filename
#define RANKLEN 6 // Length of rank for output
#define SUMLEN 8 // Length of sum for output
#define AVERLEN 10 // Length of average for output
#define CRSLEN 10 // Length of course for output
#define MALLOCERR 1 // the num exit() use when malloc() errors occur
#define FUNCNUM 14 // num of functions in function.h
typedef struct {
int stunum; // student number
int rank; // rank in the class
char name[NAMEMAX+1]; // namelist
double score[SUBMAX+2]; // score of each subject, score[0] is the sum and score[sumcrs+1] is the average
} Data,*pData;
typedef struct Node { // Node of linked list
Data data;
struct Node *next;
} Student,*pStu;
typedef struct Listinf { // pointers to the first and last node of the linked list
pStu head,tail;
} Inf,*pInf;
typedef struct {
Inf inf; // v_3.0 replace array of structure with a linked list
int sumstu; // sum of students in the class
int sumcrs; // sum of subjects in the exam
double crssco[SUBMAX+1];// sum of score of each course
double avercrs[SUBMAX+1];// average of each course
} Class,*pCls;
/* V 1.0 functions */
int Input (pCls p); //Input the information of the class, return 0 if success ,else return -1
void ScoreofCrs (pCls p); //Calculate total and average score of every course
void ScoreofStu (pCls p); //Calculate total and average score of every student
void SortbyDScore(pCls p); //Sort in descending order by total score of every student
void SortbyAScore(pCls p); //Sort in ascending order by total score of every stuednet
voi