A student information management program written in C ++

Source: Internet
Author: User

# Include <iostream>

# Include <fstream>

# Include <string>

Using namespace STD;

Struct student

{

String SnO;

String sname;

String ssex;

String sclass;

Student * next;

 

};

Class linklist

{

Public:

Student * head;

Student * last;

 

 

Linklist ()

{

Head = NULL;

Last = NULL;

}

Void creat ();

Void insert ();

Void del ();

Void show ();

Void Lookup ();

Void Update ();

Void save ();

};

Void linklist: creat ()

{

Head = new student;

Last = new student;

Last-> next = NULL;

Last-> SnO = "ABCDE ";

Head-> SnO = "0 ";

Head-> next = last;

 

Ifstream infile ("Stu. dat", IOS: In );

If (! Infile) void;

Else

{

While (! Infile. EOF ())

{

Student * P1;

P1 = new student;

P1-> next = NULL;

Infile> P1-> SnO;

Infile> P1-> sname;

Infile> P1-> ssex;

Infile> P1-> sclass;

Student * P;

P = head;

While (P1-> SnO> P-> next-> SnO)

{

P = p-> next;

}

P1-> next = p-> next;

P-> next = p1;

 

}

Infile. Close ();

 

 

}

}

Void linklist: insert ()

{

// Ofstream OUTFILE ("Stu. dat ");

// If (! OUTFILE)

//{

// Cerr <"Open Error !! "<Endl;

// Exit (1 );

//}

Student * stu1;

Stu1 = new student;

Stu1-> next = NULL;

Cout <"Enter the student ID:" <Endl;

Cin> stu1-> SnO;

// OUTFILE <stu1-> SnO <Endl;

Cout <"Enter the student's name:" <Endl;

Cin> stu1-> sname;

// OUTFILE <stu1-> sname <Endl;

Cout <"Enter the student's Gender:" <Endl;

Cin> stu1-> ssex;

// OUTFILE <stu1-> ssex <Endl;

Cout <"Enter the student's class:" <Endl;

Cin> stu1-> sclass;

// OUTFILE <stu1-> sclass <Endl;

Student * P;

P = head;

While (stu1-> SnO> P-> next-> SnO)

{

P = p-> next;

}

Stu1-> next = p-> next;

P-> next = stu1;

 

 

// OUTFILE. Close ();

}

Void linklist: Lookup ()

{

Student * P;

P = head;

String P1;

Cout <"Enter 1 for search by student ID" <Endl;

Cout <"enter 2 for search by name" <Endl;

Cout <"Enter 3 for searching by class" <Endl;

Cout <"to cancel the operation, enter 4" <Endl;

 

Int;

Cin>;

If (A = 1)

{

Cout <"Enter the student ID:" <Endl;

Cin> P1;

While (p-> SnO! = "ABCDE ")

{

If (p1 = p-> SnO) break;

Else P = p-> next;

}

If (p-> SnO = "ABCDE ")

Cout <"no student !! "<Endl;

Else cout <p-> SnO <"" <p-> sname <"<p-> ssex <" <p-> sclass <endl;

}

If (A = 2)

{

Cout <"Enter name:" <Endl;

Cin> P1;

Int COUNT = 0;

While (p-> SnO! = "ABCDE ")

{

If (p-> sname = p1)

{

Cout <p-> SnO <"" <p-> sname <"<p-> ssex <" <p-> sclass <Endl;

Count ++;

 

}

P = p-> next;

}

If (COUNT = 0) cout <"No such person" <Endl;

}

If (A = 3)

{

Cout <"Enter the class:" <Endl;

Cin> P1;

Int COUNT = 0;

While (p-> SnO! = "ABCDE ")

{

If (p-> sclass = p1)

{

Cout <p-> SnO <"" <p-> sname <"<p-> ssex <" <p-> sclass <Endl;

Count ++;

 

}

P = p-> next;

}

If (COUNT = 0) cout <"No such person" <Endl;

}

}

Void linklist: del ()

{

String P1;

Cout <"Enter the student ID you want to delete :";

Cin> P1;

Student * P;

P = head;

While (p-> next! = NULL)

{

P = p-> next;

If (p-> next-> SnO = p1)

{

Int A = 0;

Cout <p-> next-> SnO <"" <p-> next-> sname <"<p-> next-> ssex <"" <p-> next-> sclass <Endl;

Cout <"Do you really want to delete this student? Enter the number 1 for confirmation and 0 for cancellation. <Endl;

Cin>;

If (A = 1)

{

Student * q;

Q = p-> next;

P-> next = p-> next;

Delete Q;

Break;

}

If (A = 0) break;

}

If (p-> next = NULL & P-> SnO! = P1)

Cout <"no student !! "<Endl;

}

}

Void linklist: Update ()

{

Int COUNT = 0;

String P1;

Student * P;

P = head;

Cout <"Enter the student ID you want to modify:" <Endl;

Cin> P1;

While (p-> next! = NULL)

{

If (p-> SnO = p1)

{

Count ++;

Int;

Cout <p-> SnO <"" <p-> sname <"<p-> ssex <" <p-> sclass <Endl;

Cout <"Enter 1 to modify the student ID" <Endl;

Cout <"enter 2 for name modification" <Endl;

Cout <"change gender to 3" <Endl;

Cout <"Enter 4 for modifying the class" <Endl;

Cout <"to cancel the operation, enter 0" <Endl;

Cin>;

If (A = 1)

{

String B;

Cout <"enter a new student ID :";

Cin> B;

P-> SnO = B;

}

Else if (a = 2)

{

String B;

Cout <"enter a new name :";

Cin> B;

P-> sname = B;

}

Else if (a = 3)

{

String B;

Cout <"enter a new gender :";

Cin> B;

P-> ssex = B;

}

Else if (a = 4)

{

String B;

Cout <"enter a new class :";

Cin> B;

P-> sclass = B;

}

 

Else cout <"input error !! "<Endl;

Break;

}

P = p-> next;

}

If (COUNT = 0) cout <"NONE" <Endl;

}

Void linklist: Show ()

{

Student * P;

P = head;

Int COUNT = 0;

 

While (p-> next! = Last)

{

Cout <p-> next-> SnO <"" <p-> next-> sname <"<p-> next-> ssex <"" <p-> next-> sclass <Endl;

P = p-> next;

Count ++;

 

}

If (COUNT = 1) cout <"no data" <Endl;

}

Void linklist: Save ()

{

Cout <"storing data ............ "<Endl;

Cout <"do not close the window" <Endl;

Student * P;

P = head;

Ofstream OUTFILE ("Stu. dat", IOS: Out );

If (! OUTFILE)

{

Cerr <"failed to open the file. The file cannot be stored !! "<Endl;

Exit (1 );

}

While (p-> next! = Last)

{

OUTFILE <p-> next-> SnO <"";

OUTFILE <p-> next-> sname <"";

OUTFILE <p-> next-> ssex <"";

OUTFILE <p-> next-> sclass <"";

P = p-> next;

 

}

OUTFILE. Close ();

}

 

Int main ()

{

 

Linklist L;

L. creat ();

Int T1 = 0;

While (T1 = 0)

{

Int T2;

Cout <"Enter 1 for new student information;" <Endl;

Cout <"enter 2 for modifying student information;" <Endl;

Cout <"Enter 3 for student information search;" <Endl;

Cout <"Enter 4 for deleting student information;" <Endl;

Cout <"enter 5 for viewing all student information;" <Endl;

Enter 6 for cout <"exit;" <Endl;

Cin> T2;

If (t2 = 1)

{

While (t2 = 1)

{

L. insert ();

Enter 0 for the cout <"back to the main menu;" <Endl;

Enter 1 for cout <"continue operation;" <Endl;

Cin> T2;

If (t2 = 0) T1 = 0;

}

}

Else if (t2 = 2)

{

While (t2 = 2)

{

L. Update ();

Enter 0 for the cout <"back to the main menu;" <Endl;

Enter 1 for cout <"continue operation;" <Endl;

Cin> T2;

If (t2 = 0) T1 = 0;

}

}

Else if (t2 = 3)

{

While (t2 = 3)

{

 

L. Lookup ();

Enter 0 for the cout <"back to the main menu;" <Endl;

Enter 1 for cout <"continue operation;" <Endl;

Cin> T2;

}

}

Else if (t2 = 4)

{

While (t2 = 4)

{

 

L. Del ();

Enter 0 for the cout <"back to the main menu;" <Endl;

Cout <"Exit, enter 1;" <Endl;

Cin> T2;

If (t2 = 0) T1 = 0;

 

}

}

Else if (t2 = 5)

{

While (t2 = 5)

{

 

L. Show ();

Enter 0 for the cout <"back to the main menu;" <Endl;

Enter 1 for cout <"continue operation;" <Endl;

Cin> T2;

If (t2 = 0) T1 = 0;

}

}

Else if (t2 = 6)

{

Break;

}

Else

Cout <"input error !! "<Endl;

 

 

 

}

L. Save ();

Cout <"Storage completed" <Endl;

Return 0;

 

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.