C++文件读写之对象的读写(三)

2014-11-24 12:30:27 · 作者: · 浏览: 2
;
50
51 char nam[20];
52 strcpy_s(nam, name);
53 strcpy_s(name, stu.name);
54 strcpy_s(stu.name, nam);
55
56 bool btmp = sex;
57 sex = stu.sex;
58 stu.sex = btmp;
59
60 score.swapScore(stu.score);
61 birthday.swapBirthday(stu.birthday);
62
63 float ftmp = credit;
64 credit = stu.credit;
65 stu.credit = ftmp;
66
67 btmp = isChanged;
68 isChanged = stu.isChanged;
69 stu.isChanged = btmp;
70
71 }
72
73 char SortMenu()
74 {
75 cout << "选择要进行排序的方式:";
76 cout << "1--学号" << endl;
77 cout << "2--姓名" << endl;
78 cout << "3--性别" << endl;
79 cout << "4--学分" << endl;
80 cout << "5--返回上一级" << endl;
81 getchar();
82 char ch = getchar();
83 return ch;
84 }
85
86 bool SortByCondition(Student stu[], const int &len, const char &conditon)//排序
87 {
88 char tmp = conditon;
89 int length = len;
90 switch (tmp)
91 {
92 case '1'://学号
93 {
94 for (int i = 0; i < length; i++)
95 {
96 for (int j = 0; j < length-i-1; j++)
97 {
98 if (strcmp((stu[j].getNum()), stu[j + 1].getNum()) > 0)
99 //if (stu[j].getName().compare(stu[j+1].getName()) > 0)
100 {
101 //compare(stu[j].getName(),stu[j+1].getName());
102 //stu[j].getName().compare(stu[j+1].getName());
103 stu[j].swapStudent(stu[j + 1]);
104 }
105 }
106 }
107 cout << "学号降序排列" << endl;
108 for (int i = 0; i < length; i++)
109 {
110 stu[i].OutPutInfo();
111 // if (i % 10 == 0)
112 // {
113 // cout << "按下任意键继续显示" << endl;
114 // getchar();
115 // }
116 }
117 getchar();
118 }
119 break;
120 case '2'://姓名
121 {
122 for (int i = 0; i < length; i++)
123 {
124 for (int j = 0; j < length - i - 1; j++)
125 {
126 if (strcmp(stu[j].getName(), stu[j + 1].getName()) < 0)
127 //if (stu[j].getNum().compare(stu[j+1].getNum()) > 0)
128 {
129 stu[j].swapStudent(stu[j + 1]);
130 }
131 }
132 }
133 cout << "姓名降序排列" << endl;
134
135 for (int i = 0; i < length; i++)
136 {
137 stu[i].OutPutInfo();
138 // if (i % 10 == 0)
139 // {
140 // cout << "按下任意键继续显示" << endl;
141 // getchar();
142 // }
143 }
144 getchar();
145 }
146 break;
147 case '3'://性别
148 {
149 for (int i = 0; i < length; i++)
150 {
151 for (int j = 0; j < length - i - 1; j++)
152 {
153 if (stu[j].getSex() < stu[j + 1].getSex())
154 {
155 stu[j].swapStudent(stu[j + 1]);
156 }
157 }
158 }
159 cout << "性别降序排列" << endl;
160 for (int i = 0; i < length; i++)
161 {
162 stu[i].OutPutInfo();
163 // if (i % 10 == 0)
164 // {
165 // cout << "按下任意键继续显示" << endl;
166 // getchar();
167 // }
168 }
169 getchar();
170 }
171 break;
172
173 case '4'://学分
174 {
175 for (int i = 0; i < length; i++)
176 {
177 for (int j = 0; j < length - i - 1; j++)
178 {
179 if (stu[j].GetCredit() < stu[j + 1].GetCredit())
180 {
181 stu[j].swapStudent(stu[j + 1]);
182 }
183 }
184 }
185 cout << "学分降序排列" << endl;
186 for (int i = 0; i < length; i++)
187 {
188 stu[i].OutPutInfo();
189 // if (i % 10 == 0)
190 // {
191 // cout << "按下任意键继续显示" << endl;
192 // getchar();
193 // }
194 }
195 getchar();
196 }
197 break;
198 default:
199 break;
2