Home > Back-end >  C program design
C program design

Time:09-17

# include
# include
# include
//# include
//# include
# include
# include
using namespace std;
The class student
{
Private:
Char name [20].
Char sex [5].
Int number;
Int score [3].
Int total;
Int business;
Public:
Student (a);
Void the add ();
Void the output ();
Void the find ();
Void the modify ();
Void does ();
Void the sort ();
Void the save ();
Void the load ();
Student & amp; Operator=(student & amp; T);
Friend cost & amp; Operator> (istream& Scin, student& S1);
Friend ostream & amp; Operator<(ostream& Scout, student& S2);
};
Student stu [100].
Int n=0;
Student: : student ()
{
Strcpy (name, "");
Strcpy (sex, "");
Number=0;
For (int I; i<3; I++)
Score [I]=0;
Total=0;
Business=0;
}
Void student: : add ()
{
Char flag='Y'
While (toupper (flag)=='Y')
{
Cin> Stu [n].
N++;
Cout<" To continue to add? (y/n) "& lt; Cin> Flag;
If (toupper (flag)! )
='Y'{
If (toupper (flag)=='N')
break;
The else
{
Cout<" Error, please enter again: "& lt; Cin> Flag;
}
}
}
}
Void student: : the output ()
{
If (n!=0)
Cout<" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - "& lt; Cout<" Number \ t "& lt; <" The name \ t "& lt; <" Sex \ t "& lt; <" Math \ t "& lt; <" C + + \ t "& lt; <" English \ t "& lt; <" Total \ t "& lt; <" Business & lt;" Cout<" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "& lt; For (int t=0; T{
Cout}
}
Void student: : find ()
{
Int f3=0;
Char n1 [20].
Student temp.
Cout<" Please enter you will find the names of the people: "& lt; Cin> N1.
for(int j=0; j{
If (STRCMP (stu [j]. Name, n1)==0)
{
Temp=stu [j];
F3=1;
}
}
If (f3==0)
Cout<" I'm sorry to find student's result, without you "& lt; The else {
Cout<" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "& lt; Cout<" Number \ t "& lt; <" The name \ t "& lt; <" Sex \ t "& lt; <" Math \ t "& lt; <" C + + \ t "& lt; <" English \ t "& lt; <" Total \ t "& lt; <" Business & lt;" Cout<" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - "& lt; Cout<" "& lt; for(int i=0; i<3; I++)
{
Temp. Score [I];
Cout<" \ t ";
}
}
}
Void student: : modify ()
{
Int the f4=0;
Int t;
Char n2 [50];
Cout<" Input you want to modify the names of people: "& lt; Cin> N2.
for(int j=0; j{
If (STRCMP (stu [j]. Name, n2)==0)
{
T=j;
F4=1;
}
}
If (f4==0)
Cout<" I'm sorry, didn't you want to modify student achievement, "& lt; The else
{
Cout<" Please enter the student id: "& lt; Cin> Stu [t]. Number;
Cout<" Name: "& lt; Cin> Stu [t]. Name;
Cout<" Gender: "& lt; Cin> Stu [t]. Sex;
Cout<" Results: higher mathematics "& lt; Cin> Stu [t]. Score [0];
Cout<" C + + grade: "& lt; Cin> Stu [t]. Score [1].
Cout<" English: "& lt; Cin> Stu [t]. Score [2];
Stu [t]. Total=0;
for(int i=0; i<3; I++)
Stu [t]. Total +=stu [t] score [I];
Stu [t]. Business=stu [t]. Total/3;
Cout<" Modify success!" }
}
Void student: does ()
{
Char n3 [20].
Bool f5=0;
Char c;
Do {
Cout<" Please input you want to delete the names of the students: "& lt; Cin> N3.
for(int i=0; i{
If (STRCMP (n3, stu [I] name)==0)
{
F5=1;
N -;
Do {
Stu [I]=stu [I + 1);
i++;
} while (i<=n);
}
}
If (f5==0)
Cout<" You want to delete the object would not have been there!" Cout<" To continue to delete? (y/n) "& lt; Cin> c;
If (toupper (c)!='Y' | | toupper (c)!='N')
{
Cout<" Input error! Please enter a Y or N: "& lt; Cin> c;
}
} while (toupper (c)=='Y');
}
Void student: : sort ()
{
Int I, j, k;
Student s3.
for(i=0; i{
K=I;
For (j=I + 1; j{
If (stu [j] average> Stu [I] business)
K=j;
If (k!=I)
{
S3=stu [I];
Stu [I]=stu [k].
Stu [k]=s3;
}
}
}
Cout<" Sort \ n \ n success! \ n \ n "& lt; }
Void student: : save ()
{
Char filename1 [20].
Cout<" Please enter the file name: "& lt; Cin> Filename1;
Ofstream fout (filename1, the ios: : app);
if(! Fout)
Cerr<" File cannot be opened!" The else
{
for(int i=0; iFout<" "& lt;
  • Related