The code below
# include
# include
# include
using namespace std;
//int n=0;
Struct Worker {
int num;
char name[20];
int age;
Float wage;
};
Void input (int n, Worker * w) {
for(int i=0; i
Cin> W [I] num;
Cout<& lt;" Name: ";
Cin> W [I]. Name;
Cout<& lt;" Age: ";
Cin> W [I] the age;
Cout<& lt;" Wage: ";
Cin> W [I]. Wage;
}
}
Void bubble_sort (int n, Worker * w) {
The Worker w1.
Bool change=true;
For (int I=n - 1; I>=1 & amp; & Change==true; I -) {
Change=false;
for(int j=0; JIf (w [j] num> W [j + 1] {num)
W1=w [j];
[j]=w w [j + 1);
W [j + 1)=w1;
Change=true;
}
}
}
}
Void write_file (char * filename, Worker * w) {
Fstream outfile (filename, the ios: : out | ios: : | in ios: : binary);
if(! Outfile) {
Cerr<& lt;" Open the file error!"
}
Outfile. Write ((char *) w, sizeof (w));
Outfile. Close ();
}
Void show (int n, Worker * w) {
for(int i=0; i
}
Void read_file (char * filename, int n) {
Fstream ifile (filename, the ios: : out | ios: : | in ios: : binary);
if(! Ifile) {
Cout<& lt;" The open ifle error!"
}
The Worker * w2=new Worker [n].
for(int i=0; i
Cout<& lt;" Num: "& lt;
Ifile. Close ();
The delete [] w2;
}
The Worker * add (int & amp; Num, Worker * w) {
Int num1.
If (w==NULL | | num==0) {
Cout<& lt;" You have not creat a list!"
}
Cout<& lt;" Both please input number of extra workers: ";
Cin> Num1.
The Worker * w1=new Worker [num + num1];
for(int i=0; i
}
If (i>=num& & i
Cin> W1 [I] num;
Cout<& lt;" Name: ";
Cin> W1 [I]. Name;
Cout<& lt;" Age: ";
Cin> W1 [I] the age;
Cout<& lt;" Wage: ";
Cin> W1 [I]. Wage;
}
}
Num +=num1;
Return w1.
}
Int main () {
int n=0;
Int num=0;
The Worker * w=NULL;
Cout<& lt;" Worker_system "& lt;
Cout<& lt;" Do your choice: ";
Cin> n;
{if (n==6)
break;
}
The switch (n) {
Case 1:
//cout
Cout<& lt;" Do the import number of worker: ";
Cin> Num.
W=new Worker (num);
Input (num, w);
Write_file (" worker_sys. TXT ", w);
break;
}
The else {
Cout<& lt;" Already creat a list!"
}
Case 2:
W=add (num, w);
//cout
break;
Case 3:
If (num==0) {
//bubble_sort (num, w); break;
Cout<& lt;" You have not creat a list!"
}
The else {
Bubble_sort (num, w);
break;
}
Case 4: break;
Case 5:
If (num==0) {
Cout<& lt;" You have not creat a list!"
}
The else {
The read_file (" worker_sys. TXT ", num);
break;
}
//the read_file (" worker_sys. TXT ", num); break;
Default: cout<& lt;" The error "; break;
}
}
return 0;
}
CodePudding user response:
Where different didn't understandCodePudding user response: