Operating System Course assignments (Data Structure implementation-Assignment 1: Student Status management procedures)

Source: Internet
Author: User
Assignment 1: Student Status management procedures

Student Status Management usually uses a database-based management information system (MIS) system. However, we do not need to use the database technology, but use the data structure struct and linked list to complete the management tasks.

Job description

The data structure is used to indicate the student and record the student information. The student information includes student ID SnO, name sname, age sage, Major sprof, and class sclass. Please design a reasonable data structure to accommodate this information.

Complete basic common operations such as adding, modifying, deleting, and querying students.

Use a linked list to represent the queue of the student's class.

Background

1. Data Structure.

2. linked list.


CodeThe implementation is as follows:

It is hard to write simple code.

The more I think about it, the less I think about it. After all, it is a pseudo interface.


The code framework is as follows:

# Include <cstdio> # include <cstring> # include <cstdlib> using namespace STD; class student {PRIVATE: Char SnO [15]; int Sage; char sclass [15]; char sname [15]; char sprof [15]; Student * Next; typedef student * Stu; public: Student () {// constructor, initialize linked list} void insert (student & Stu) {// insert operation} bool search (char cur_sno [], Stu & res_pre) {// search operation} bool Delete (char delete_sno []) {// delete operation} void modify (student & Stu) {// modify operation // input modify student Save the information to Stu (the specific implementation of the insert part is actually in modify_info)} // The above is the chain table insertion and deletion, find the modified basic operation/* student */void input_stu_info (student & Stu) {// enter the student information (except the primary code SnO) function} void back_or_not (int n) {// whether to return the function on the main interface} void check_back_root (char STR []) {// handle the exception when the main menu cannot be returned.} Int input () {// input processing, string reading, and simple troubleshooting} void frame () {// interface} // The above is a float cloud... /* --------------------------------------------------------------- */void add_info () {// Add the student record implementation function // enter the student ID information and call the Champions League insert () insert} void modify_info () {// modify the student record implementation function // enter the student ID information and call the Champions League modify () modification} void delete_info () {// Delete the student record implementation function // enter the student ID information, call the Champions League Delete () delete} void search_info () {// find the student record implementation function // enter the student ID information and call Search () for search} void print_all () {// output all student records implementation function} // The above is student status managementProgram Implementation of the five main functions/* --------------------------------------------------------------- */}; int main () {student stulist; stulist. Frame (); Return 0 ;}

 

The code is implemented as follows:

# Include <cstdio> # include <cstring> # include <cstdlib> using namespace STD; class student {PRIVATE: Char SnO [15]; int Sage; char sclass [15]; char sname [15]; char sprof [15]; Student * Next; typedef student * Stu; public: Student () {memset (SNO, 0, sizeof (SNO )); memset (sname, 0, sizeof (sclass); memset (sname, 0, sizeof (sname); memset (sprof, 0, sizeof (sprof )); next = NULL;} void insert (student & Stu) {Stu P = This; whi Le (p-> next & strcmp (p-> next-> SnO, Stu. snO) <0) {P = p-> next;} Stu TMP = p-> next; P-> next = & Stu; P = p-> next; p-> next = TMP;} bool search (char cur_sno [], Stu & res_pre) {Stu P = This; while (p-> next) {If (strcmp (p-> next-> SnO, cur_sno) = 0) {res_pre = P; // res pre-pointer to save the result // printf ("% s -- \ n", res_pre-> next-> SnO); Return true ;} P = p-> next;} return false;} bool Delete (char delete_sno []) {Stu res_pre = this; if (S Earch (delete_sno, res_pre) {Stu res = res_pre-> next; res_pre-> next = res-> next; Delete (RES ); puts ("\ t deletion succeeded"); Return true;} else {puts ("\ t this student does not exist. Please check and enter it again! "); Return false ;}} void modify (student & Stu) {printf (" \ t student % s student status information to be modified: ", Stu. snO); puts ("\ t name \ t age \ t major \ t class "); printf ("\ t % s \ t % d \ t % s \ n", Stu. sname, Stu. sage, Stu. sprof, Stu. sclass); printf ("\ t enter the modified student information (in the above order): \ n"); input_stu_info (Stu );} /* required */void input_stu_info (student & Stu) {printf ("\ t"); scanf ("% s", Stu. sname); check_bac K_root (Stu. sname); printf ("\ t"); int check_age = input (); If (check_age> = 0 & check_age <= 100) {Stu. sage = check_age;} printf ("\ t"); scanf ("% s", Stu. sprof); check_back_root (Stu. sprof); printf ("\ t"); scanf ("% s", Stu. sclass); check_back_root (Stu. sclass); printf ("\ n");} void back_or_not (int n) {puts ("too many minutes before continuing the current operation press 0, to return to the main interface, press 1 ═ \ n "); int check_in = input (); While (! (Check_in> = 0 & check_in <= 1) {printf ("the number you selected is incorrect. Please reselect:"); check_in = input ();} // input Exception Handling if (check_in = 0) {Switch (n) {Case 1: add_info (); break; Case 2: modify_info (); break; Case 3: delete_info (); break; Case 4: search_info (); break; default: break;} else {frame () ;}} void check_back_root (char STR []) {If (strcmp (STR, "250") = 0) {frame () ;}} int input () {// input processing, simple troubleshooting of int I, k = 0; char stmp [110 ], STR [110]; scanf ("% s", STR); check_back_root (STR); for (I = 0; STR [I]; I ++) {If (! (STR [I]> = '0' & STR [I] <= '9') {return-1 ;} else {stmp [k ++] = STR [I] ;}} int r = 1, sum = 0; for (I = k-1; I> = 0; I --, R * = 10) {sum + = (STR [I]-'0') * R;} return sum;} void frame () {system ("CLS "); puts ("Student ****** * ******************** renew "); puts ("bytes consumed"); puts ("bytes author info -- class: abcdefgh name: XXX Stu. no: 33333333 bytes "); puts" ); Puts ("average student records"); puts ("average 1: Add student records; Limit 2: Modify student records"); puts ("average student records "); puts" ); puts ("average student records"); puts ("average 3: deleting student records limit 4: querying student records limit"); puts ("average student records "); puts" ); puts ("cannot return notice: Any exceptions that cannot be returned"); puts ("limit 5: show all student records (in this case, no student information is 250) outputs "); puts (" ║ input 250 return to Main Menu outputs "); puts" ); // The timestamp, mainly because of the font here. Just copy it .. Printf ("Enter the number:"); int check_in = input (); While (! (Check_in >=1 & check_in <= 6) {printf ("the number you selected is incorrect. Please reselect:"); check_in = input ();} // input Exception Handling switch (check_in) {// establish association Case 1: add_info (); Case 2: modify_info (); break; Case 3: delete_info (); break; case 4: search_info (); break; Case 5: print_all (); break; default: break;}/* required */void add_info () {system ("CLS"); puts ("example ************************ add Learning Generate record information *********************** outputs \ n "); puts (" notice: for any exceptions that cannot be returned, enter 250 to return to the Main Menu \ n "); puts (" \ t to enter the following sequence (student ID as the main code) \ n "); puts ("\ t student ID \ t name \ t age \ t major \ t class \ n"); Student Stu, * res_pre = This; char stmp [110], STR [110]; bool flag, OK = false; int I, K = 0; while (! OK) {printf ("\ t"); scanf ("% s", STR); check_back_root (STR); flag = false; while (! Flag) {flag = true; k = 0; for (I = 0; STR [I]; I ++) {If (! (STR [I]> = '0' & STR [I] <= '9') {flag = false; break ;} else {stmp [k ++] = STR [I] ;}} stmp [k] = 0; If (search (STR, res_pre )) {puts ("\ t student ID cannot be repeated. The student ID record already exists. Check the student ID and enter it again. ") ;}Else {OK = true ;}} strcpy (STU. Sno, stmp); input_stu_info (Stu); insert (Stu); puts (" Congratulation! Record added! \ N "); back_or_not (1);} void modify_info () {char STR [110]; Stu res_pre = This; System (" CLS "); puts ("Student ********************** modify student record information ************ * *********** limit \ n "); puts ("Notice: Enter the 250 return Main Menu \ n" for any exceptions that cannot be returned); printf ("\ t enter the student ID to be modified: \ n \ t "); scanf (" % s ", STR); check_back_root (STR); While (! Search (STR, res_pre) {puts ("\ t the student information you entered does not exist. Check the information and enter"); printf ("\ t "); scanf ("% s", STR); check_back_root (STR);} modify (* (res_pre-> next); puts ("Congratulation! Modification successful! \ N "); back_or_not (2);} void delete_info () {system (" CLS "); char STR [110]; puts ("Student ********** * *********** limit \ n "); puts ("Notice: Enter the 250 return Main Menu \ n" for any exceptions that cannot be returned); printf ("\ t enter the student ID to be deleted: \ n \ t "); scanf (" % s ", STR); check_back_root (STR); While (! Delete (STR) {// puts ("\ t this record does not exist. Check the record and re-enter:"); printf ("\ t") already exists in Delete "); scanf ("% s", STR); check_back_root (STR);} back_or_not (3);} void search_info () {system ("CLS"); char STR [110]; stu res_pre = this; puts ("Student ********** * *********** limit \ n "); puts ("Notice: Enter the 250 return Main Menu \ n" for any exceptions that cannot be returned); printf ("\ t enter the student ID to query information: \ n \ t "); scanf (" % s ", STR); check_back_root (STR); While (! Search (STR, res_pre) {puts ("\ t does not exist. Check the record and enter"); printf ("\ t "); scanf ("% s", STR); check_back_root (STR);} student Stu = * (res_pre-> next); printf ("the query result is as follows :"); puts ("\ t student ID \ t name \ t age \ t major \ t class \ n "); printf ("\ t % s \ t % d \ t % s \ n", Stu. sno, Stu. sname, Stu. sage, Stu. sprof, Stu. sclass); back_or_not (4);} void print_all () {system ("CLS"); Stu P = This; Student Stu; puts ("Student ********************** output information of all student records ********** ******* * *** Outputs \ n "); puts (" Notice: For any exceptions that cannot be returned, enter 250 return to Main Menu \ n "); If (! P-> next) {puts ("\ t record is blank! ");} Puts (" \ t student ID \ t name \ t age \ t major \ t class \ n "); For (; P-> next; P = p-> next) {Stu = * P-> next; printf ("\ t % s \ t % d \ t % s \ n", Stu. sno, Stu. sname, Stu. sage, Stu. sprof, Stu. sclass);} system ("pause"); frame (); System ("CLS") ;};int main () {student stulist; stulist. frame (); Return 0 ;}


OriginalArticleIf it is reproduced, please note: transferred from ¥ forgot % windHttp://www.cnblogs.com/slave_wc}

Address: Operating System Course assignments (Assignment 1: Student Status Management Program)

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.