Home > Back-end >  The great god is proficient in c? How to modify the program so I can save the input information to a
The great god is proficient in c? How to modify the program so I can save the input information to a

Time:11-13

#include
#include
#include
using namespace std;
Struct student {
char name[20];
Char address [40].
Char phonenum [30].
Char postcode [20].
Student * next;
};
//define the data structure
Void mainscreen (student * p);
Void title ();
Void the save (student * head)
{
The FILE * fp.
Student * point;
Point=head;
If ((fp=fopen (" data. Dat ", "wb"))==NULL)
{
Cout<& lt;" Can not open the file "& lt; exit(0);
}
While (point)
{
Fwrite (point 1, sizeof (struct student), fp);
Point=point - & gt; Next;
}
fclose(fp);
}
Void read_ (student * head)//file data read function
{
The FILE * p=fopen (" data. Dat ", "rb");
Fread (head, sizeof (struct student), 1, p);
/* while (head)
{
Cout<& lt;" % s \ n ", the head - & gt; Name);
Cout<& lt;" % s \ n ", the head - & gt; Address);
Cout<& lt;" % s \ n ", the head - & gt; Phonenum);
The head=head - & gt; Next;
}
*/
}
Void assert_student (student * head)
{
system("cls");
The title ();
The static student * p, * q;
If (head==NULL)
{
Head=q=(struct student *) malloc (sizeof (student));
P=(struct student *) malloc (sizeof (student));
The head - & gt; next=p;
Cout<& lt;" The current directory uninitialized, please input the name of the first object: ";
Cin> p-> The name;
Cout<& lt;" Please input object home address: ";
Cin> p-> The address;
Cout<& lt;" Please enter the phone number of the object: ";
Cin> p-> Phonenum;
Cout<& lt;" Please enter the object's zip code: ";
Cin> p-> Postcode;
Q - & gt; next=p;
Q=p;
Q - & gt; next=NULL;
system("cls");
The title ();
}
Else if (the head!=NULL)
{
P=(struct student *) malloc (sizeof (student));
Cout<& lt;" Please enter the names of the objects: ";
Cin> p-> The name;
Cout<& lt;" Please input object home address: ";
Cin> p-> The address;
Cout<& lt;" Please enter the phone number of the object: ";
Cin> p-> Phonenum;
Cout<& lt;" Please enter the object's zip code: ";
Cin> p-> Postcode;
Q - & gt; next=p;
Q=p;
Q - & gt; next=NULL;
system("cls");
The title ();
}
The mainscreen (head);
}
Void delete_student (student * head)
{
Int flag=1;
system("cls");
Char de_stu [20].
Cout<& lt;" Please input to logout message name: ";
Cin> De_stu;
Student * q * front;
Front=(struct student *) malloc (sizeof (student));
Q=head - & gt; Next;
While (q!=NULL)
{
If (STRCMP (q - & gt; Name, de_stu)==0)
{
Cout<& lt;" Need to cancel the information has been identified, are logged off... "& lt; Q=front - & gt; Next;
The front - & gt; Next=q - & gt; Next;
Cout<& lt;" The data has been cancelled successfully, return to the main page... "& lt; Flag=0;
break;
}
Q=q - & gt; Next;
}
If (flag==1)
Cout<& lt;" To find the information does not exist "& lt; The mainscreen (head);
}
Void change_student (student * head)
{
system("cls");
The title ();
Int flag=1;
Student * q;
Char name_stu [20].
Cout<& lt;" Please enter your information to modify the name: ";
Cin> Name_stu;
Q=head - & gt; Next;
While (q!=NULL)
{
If (STRCMP (q - & gt; Name, name_stu)==0)
{
Cout<& lt;" Please start modify personal information: "& lt; Cout<& lt;" Name: ";
Cin> Q - & gt; The name;
Cout<& lt;" Home address: ";
Cin> Q - & gt; The address;
Cout<& lt;" Phone number: ";
Cin> Q - & gt; Phonenum;
Cout<& lt;" Zip: ";
Cin> Q - & gt; Postcode;
Cout<& lt;" Personal information changes done!" Flag=0;
break;
}
Q=q - & gt; Next;
}
If (flag==1)
Cout<& lt;" To find the information does not exist "& lt; The mainscreen (head);
}
Void search_student (student * head)
{
system("cls");
The title ();
Int flag=1;
Char name_stu [20].
Cout<& lt;" Please input you want to find the name: ";
Cin> Name_stu;
Student * q;
Q=head - & gt; Next;
While (q!=NULL)
{
If (STRCMP (q - & gt; Name, name_stu)==0)
{
Cout<& lt;" Name: "& lt; & lt;" ";
Cout<& lt;" Home address: "& lt; & lt;" ";
Cout<& lt;" Phone number: "& lt; & lt;" "& lt; Cout<& lt;" Zip: "& lt; & lt;" "& lt; CoutCoutCoutCoutFlag=0;
break;
}
Q=q - & gt; Next;
}
If (flag==1)
Cout<& lt;" To find the information does not exist "& lt; The mainscreen (head);
}
Void show_student (student * head)
{
system("cls");
The title ();
Student * q;
Q=head - & gt; Next;
While (q!=NULL)
{
Cout<& lt;" Name: "& lt; & lt;" ";
Cout<& lt;" Home address: "& lt; & lt;" ";
Cout<& lt;" Phone number: "& lt; & lt;" "& lt; Cout<& lt;" Zip: "& lt; & lt;" "& lt; CoutCoutCoutCoutQ=q - & gt; Next;
}
The mainscreen (head);
}
Void title ()
{
Char a=3; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related