void StudentList::registerStudentRecord() { int id; string name; int kor; int math; int eng; while (1) { if (isFlag() == false) { break; } else { cout << "학생의 인적사항을 입력하시오" << endl; cout << "학번 : "; cin >> id; cout << "이름 : "; cin >> name; cout << "학생의 성적을 입력하시오" << endl; cout << "국어 : "; cin >> kor; cout << "수학 : "; cin >> math; cout << "영어 : "; cin >> eng; Student s(id, name, kor, math, eng); // 학생 Entity 생성자 insertStudent(s); // 학생 Entity의 정보를 List 객체 배열에 할당; } cout << "학번, 이름, 성적 입력 후 더 입력?(y/n)" << endl; char select; cin >> select; switch (select) { case 'y': case 'Y': flag = true; break; case 'n': case 'N': flag = false; break; default: cout << "잘못 입력하셨습니다." << endl; break; } } flag = true; // 메뉴에서 재등록을 위한 초기화 }
int main(int argc,char **argv){ FILE *fp; char line[LINE_LENGTH]; struct Institute* header; struct Student* newStudent; struct Group* groupHeader; int studentNum=0; int groupNum = atoi(argv[2]); int i; if(argc!=3){ fprintf(stderr,"Must be 3 args!\n"); exit(0); } if((fp = fopen(argv[1],"r"))==NULL){ fprintf(stderr,"Open file %s failed!\n",argv[1]); exit(0); } header = (struct Institute*)malloc(sizeof(struct Institute)); if(header==NULL){ fprintf(stderr,"Malloc new institute failed!\n"); exit(0); } header->next = NULL; fgets(line,LINE_LENGTH,fp); while(!feof(fp)){ memset(line,0,LINE_LENGTH); fgets(line,LINE_LENGTH,fp); if(line[0]==0){ continue; } studentNum++; // printf("line : %s",line); newStudent = (struct Student*)malloc(sizeof(struct Student)); if(newStudent==NULL){ fprintf(stderr,"Malloc new student failed!\n"); exit(0); } sscanf(line,"%*[^,],%[^,],%[^,],%[^,],%[^,]",newStudent->ID,newStudent->name,newStudent->major,newStudent->institute); newStudent->next = NULL; insertStudent(header,newStudent); } groupHeader = (struct Group*)malloc(groupNum*sizeof(struct Group)); if(groupHeader==NULL){ fprintf(stderr,"Malloc group failed!\n"); exit(0); } for(i=0;i<groupNum;i++){ groupHeader[i].num = 0; groupHeader[i].ps = NULL; } divideIntoGroups(header,groupHeader,groupNum,studentNum); printGroups(groupHeader,groupNum); freeGroups(groupHeader,groupNum); freeInstitute(header); return 0; }
int main(){ student_t *head, *newStudent,*temp; int age,major; float gpa; char * name, *name1, cr; char *msg; int i; int answer,data; head = NULL; printf("You are now entering the student zone!\n"); answer = menu(); while(answer != 7){ switch (answer) { case 1: printf("enter age:\n"); scanf("%d%c",&age,&cr); printf("enter gpa:\n"); scanf("%f%c",&gpa,&cr); printf("enter major:\n"); scanf("%d%c",&major,&cr); printf("enter name:\n"); name = getline(); //printf("length: %d\n",strlen(name)); newStudent = createStudent(age, name,major,gpa); break; case 2: insertStudent(&head,newStudent); break; case 3: printf("enter student name to delete\n"); name1 = getline(); deleteStudent(&head,name1); free(name1); break; case 4: printf("enter student name to investigate\n"); name1 = getline(); data = dataMenu(); switch (data) { case 1: temp = findStudent(head, name1); if(temp == NULL){ printf("Student %s not found \n",name1); break; } age = getAge( temp); printf("The age of %s, is %d\n",name1,age); break; case 2: temp = findStudent(head, name1); if(temp == NULL){ printf("Student %s not found \n",name1); break; } gpa = getGpa( temp); printf("The gpa of %s, is %f\n",name1,gpa); break; case 3: temp = findStudent(head, name1); if(temp == NULL){ printf("Student %s not found \n",name1); break; } major = getMajor( temp); printf("The gpa of %s, is %d\n",name1,major); break; default: break; } break; case 5: temp = head; while(temp != NULL){ msg = toString( temp); printf("%s\n",msg); temp = temp->link; } break; case 6: insertStudentRear(&head,newStudent); break; default: break; } answer = menu(); } printf("BYE\n"); return(0); }