Student Course electives-Book Management System (C ++) Part 2

Source: Internet
Author: User

// Functionstu. h typedef struct subjects {int num; // course No. Char name [20]; // Course name char kind [10]; // Course Nature int stime; // int tTime in total; // int etime in course of teaching; // int score in lab or computer; // int term in credits; // struct subjects * Next in course class term ;} sub; sub * create_form () {sub * head, * tail, * P; int num, stime, tTime; int etime, score, term; char name [20], kind [10]; int size = sizeof (sub); Head = tail = NULL; printf ("Enter the elective course information: (course number, name, nature, total class hours, teaching hours, Lab or hands-on hours, credits, course class term)/n "); scanf (" % d % S % d ", & num, name, kind, & stime, & tTime, & etime, & score, & term); While (num! = 0) {P = (sub *) malloc (size); P-> num = num; strcpy (p-> name, name); strcpy (p-> kind, kind); P-> stime = stime; P-> tTime = tTime; P-> etime = etime; P-> score = score; P-> term = term; if (Head = NULL) Head = P; else tail-> next = P; tail = P; scanf ("% d % S % d", & num, name, kind, & stime, & tTime, & etime, & score, & term) ;}tail-> next = NULL; return head;} void SaveFile (sub * head) {sub * P; file * FP; if (FP = fopen ("E: // subjects.txt", "W ")) = NULL) {printf ("Open fail! /N "); exit (0);} fprintf (FP," course No. Course name Course Nature total class hours lab or on-board hours course class term/N "); for (P = head; P = p-> next) fprintf (FP, "% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D/N", p-> num, p-> name, p-> kind, p-> stime, p-> tTime, p-> etime, p-> score, p-> term); If (fclose (FP) {printf ("Close fail! /N "); exit (0);} printf (" the created information is stored in the/N "file of the elastic subjects.txt");} void savefileadd (sub * head) {sub * P; file * FP; if (FP = fopen ("E: // subjectsadd.txt", "W") = NULL) {printf ("Open fail! /N "); exit (0);} fprintf (FP," course No. Course name Course Nature total class hours lab or on-board hours course class term/N "); for (P = head; P = p-> next) fprintf (FP, "% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D/N", p-> num, p-> name, p-> kind, p-> stime, p-> tTime, p-> etime, p-> score, p-> term); If (fclose (FP) {printf ("Close fail! /N "); exit (0);} printf ("/n "in the latest subjectsadd.txt file where the modified information is stored in the edisk root directory);} void savefiledel (sub * head) {sub * P; file * FP; if (FP = fopen ("E: // subjectsdel.txt", "W") = NULL) {printf ("Open fail/N "); exit (0);} fprintf (FP, "course No. Course name Course Nature total course class lab or on-board course class semester/N"); For (P = head; p; P = p-> next) fprintf (FP, "% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D/N ", p-> num, p-> name, p-> kind, p-> stime, p-> tTime, p-> etime, p-> score, p-> term); If (fclose (F P) {printf ("Close fail! /N "); exit (0);} printf (" the modified information is stored in the/N "file of the edisk root directory.);} void Prin (sub * head) {sub * PTR; if (Head = NULL) {printf ("no records! /N "); return;} printf (" course No. Course name Course Nature total class hours practice or on-board course hours course class term/N "); For (PTR = head; PTR; PTR = PTR-> next) printf ("% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D/N", PTR-> num, PTR-> name, PTR-> kind, PTR-> stime, PTR-> tTime, PTR-> etime, PTR-> score, PTR-> term );} void search (sub * head) {int A, num; int T = 1; char type [10]; char CH = 'A', substring; sub * PTR; while (Ch! = '') {Printf (" if you want to search by course nature, enter 1. If you want to search by credit, enter 2:/N "); scanf (" % d ", & A); Switch (a) {Case 1: printf ("Enter the nature of the course to be searched:/N"); scanf ("% s", type ); printf ("course No. Course name Course Nature total class hours practice or on-board class credits course class term/N"); For (PTR = head; PTR = PTR-> next) if (strcmp (type, PTR-> kind) = 0) {printf ("% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D/N", PTR-> num, PTR-> name, PTR-> kind, PTR-> stime, PTR-> tTime, PTR-> etime, PTR-> score, PTR-> term); t = 0;} If (t) printf ("not found! /N "); t = 1; break; Case 2: printf (" Enter the credits for the course to be searched/N "); scanf (" % d ", & num ); printf ("course No. Course name Course Nature total class hours practice or on-board class credits course class term/N"); For (PTR = head; PTR = PTR-> next) if (PTR-> score = num) {printf ("% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D/N ", PTR-> num, PTR-> name, PTR-> kind, PTR-> stime, PTR-> tTime, PTR-> etime, PTR-> score, PTR-> term); t = 0;} If (t) printf ("not found! /N "); t = 1;} printf (" continue searching press enter, End Press space:/N "); character = getchar (); // assign the carriage return key to the carriage return key. Otherwise, the carriage return key entered in the case will be assigned to the CH key, so use the carriage return key to fill the key. Ch = getchar () ;}} sub * insert (sub * head) {sub * PTR, * ptr2, * subj; int size = sizeof (sub ); char CH = 'A', while; while (Ch! = '') {Subj = (sub *) malloc (size); PTR = subj; printf (" Enter the course information to insert:/N "); scanf ("% d % S % d", & subj-> num, subj-> name, subj-> kind, & subj-> stime, & subj-> tTime, & subj-> etime, & subj-> score, & subj-> term); If (Head = NULL) {head = PTR; head-> next = NULL;} else {for (ptr2 = head; ptr2; ptr2 = ptr2-> next) if (ptr2-> next = NULL) {ptr2-> next = subj; subj-> next = NULL; break;} printf ("continue inserting, press enter, and press space:/N "); keys = getchar (); // assign the carriage return key to Ch 1. Otherwise, the input return key after the input of subj-> term is assigned to CH, so use limit to fill it. Ch = getchar ();} return head;} sub * del (sub * head) {sub * P1, * P2; char CH = 'A', substring; int num; while (Ch! = '') {Printf (" Enter the course number you want to delete:/N "); scanf (" % d ", & num ); if (Head-> num = num) {P2 = head; head = head-> next; free (P2);} If (Head = NULL) return NULL; p1 = head; P2 = head-> next; while (P2) {If (P2-> num = num) {p1-> next = P2-> next; free (P2);} else p1 = P2; P2 = p1-> next;} printf ("continue to delete, press enter, and press space:/N "); keys = getchar (); // assign the Enter key to keys. Otherwise, the Enter key after num is input will be assigned to CH, so use keys to fill it. Ch = getchar () ;}return head;} void choose (sub * head) {sub * P, * q; int A [5]; int num, total = 0, I = 0, J; printf ("Enter the number of the course to be selected, separate the numbers with spaces, and end with 0/N"); scanf ("% d ", & num); While (num! = 0) {for (P = head; P = p-> next) if (p-> num = num) {Total = total + P-> score; A [I] = num; I ++;} scanf ("% d", & num);} If (total <60) printf ("the total number of elective credits is less than 60, failed to select course! /N "); else {printf (" selected successfully! /N "); printf (" the course you selected is:/N "); For (j = 0; j <I; j ++) for (q = head; q; q = Q-> next) if (Q-> num = A [J]) printf ("% s", Q-> name ); printf ("/N") ;}} void readfile () // read the file again {int num, stime, tTime, etime; int score, term; char C, name [20], kind [10]; file * fp = fopen ("E: // subjects.txt", "R"); While (! Feof (FP) {If (C = fgetc (FP) = '/N') break ;} printf ("course No. Course name course nature when teaching lab or on-board course class term/N"); While (! Feof (FP) {fscanf (FP, "% d % S % d/N", & num, name, kind, & stime, & tTime, & etime, & score, & term ); printf ("% 5d % 12 S % 9 S % 9d % 9d % 11d % 11d % 7D/N", num, name, kind, stime, tTime, etime, score, term);} fclose (FP );}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.