theBao 1 year ago
parent 88ef70152e
commit f0650ff07a

BIN
.DS_Store vendored

Binary file not shown.

@ -0,0 +1,151 @@
//
// main.c
// Lab_2
//
// Created by theBao on 2023/11/4.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{
char *id;
char *class;
char *name;
double score1;
double score2;
double score3;
double score;
}Student;
typedef struct{
Student* student;
int nums;
}ss;
ss* init(int);
void toMenu(ss*);
void getCom(ss*);
void Print(Student*);
void allPrint(ss*);
void input(ss*);
void cancel(ss*);
void Select(ss*);
int main(int argc, const char * argv[]){
ss* stu = init(6);
toMenu(stu);
return 0;
}
ss* init(int Nums){
ss* stu = (ss*)malloc(sizeof(ss));
if(!stu) return NULL;
stu->nums = Nums;
stu->student = (Student*)malloc(sizeof(Student)*Nums);
if(!stu->student) return NULL;
for(int i = 0; i < Nums; ++i){
stu->student[i].id = (char*)malloc(sizeof(char)*5);
stu->student[i].class = (char*)malloc(sizeof(char)*2);
stu->student[i].name = (char*)malloc(sizeof(char)*10);
}
return stu;
}
void toMenu(ss*stu){
printf(" 1.input\n");
printf(" 2.delete\n");
printf(" 3.select\n");
printf(" 4.order\n");
printf(" 5.output\n");
printf(" 6.quit\n");
printf("please input your option\n");
getCom(stu);
}
void getCom(ss* stu){
int option;
scanf("%d",&option);
if(option == 1) input(stu);
else if(option == 2) cancel(stu);
else if(option == 3) Select(stu);
//else if(option == 4) sort(stu);
else if(option == 5) ;
else return;
}
void Print(Student*student){
printf("%s,%s,%s,%.1lf,%.1lf,%.1lf,%.1lf\n",student->id,student->class,student->name,student->score1,student->score2,student->score3,student->score);
}
void allPrint(ss*stu){
for(int i = 0; i < stu->nums; ++i){
Print(&stu->student[i]);
}
}
void input(ss*stu){
char *tmp = (char*)malloc(sizeof(char)*3);
do{
printf("Id ");
// get
printf("\n");
printf("class ");
// get
printf("\n");
printf("name ");
// get
printf("\n");
printf("score1 ");
// get
printf("\n");
printf("score2 ");
// get
printf("\n");
printf("score3 ");
// get
printf("\n");
printf("continue?\n");
scanf("%s",tmp);
}while(strcmp(tmp,"yes"));
toMenu(stu);
}
void cancel(ss*stu){
char* tmp = (char*)malloc(sizeof(char)*3);
do{
char*ID = (char*)malloc(sizeof(char)*5);
scanf("%s",ID);
for(int i = 0; i < stu->nums; ++i){
if(strcmp(stu->student[i].id,ID)){
for(int j = i; j < stu->nums-1; ++j){
stu->student[j] = stu->student[j+1];
}
}
}
allPrint(stu);
printf("continue?\n");
scanf("%s",tmp);
}while(strcmp(tmp,"yes"));
toMenu(stu);
}
void Select(ss*stu){
char* tmp = (char*)malloc(sizeof(char)*3);
do{
;
}while(0);
}
//void insert(ss*stu)
Loading…
Cancel
Save