/** Copyright (c) 2012, School of Computer Science, Yantai University * All Rights Reserved. * file name: test. CPP * Author: Qiu xuewei * Completion Date: July 15, December 12, 2012 * version: V1.0 * input Description: none * Problem description: (1) output the list of students sorted by score; (2) output the transcript sorted by the name of the student (the sorting object is a string ). (1) Use the array char name [] [20] to represent the names of multiple students; (2) use the strcmp and strcpy functions for comparison and replication. * Program output: * Problem Analysis: * Algorithm Design: omitted */# include <iostream> # include <string> using namespace STD; const int num = 8; int main () {Int J, I; char temp [20]; char name [num] [20] = {"Lulu", "yongyon", "Weiwei", "qiangqiang ", "Chenchen", "pengpeng", "jinjin", "Yingying"}; Double score [num] = {77,100, 89,}, T; for (j = 0; j <num-1; j ++) for (I = 0; I <num-j-1; I ++) {If (score [I] <score [I + 1]) {T = score [I]; score [I] = score [I + 1]; score [I + 1] = T; strcpy (temp, name [I]); strcpy (name [I], name [I + 1]); strcpy (name [I + 1], temp) ;}} cout <"output by score:" <Endl; for (I = 0; I <num; I ++) cout <name [I] <"\ t" <score [I] <Endl; return 0 ;}
Experience:
Comrades, the exam must pass!