display name and score. names sorted by score in descending order
Feb 11, 2010 at 12:21pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
struct studentStruct {
int scores[5];
string studName[5];
} studInfo;
int main(){
int i,y,t;
cout << "Please enter the last name of the student and the score of the student, separated by a space" << endl;
cout << " For example: Doe 88" << endl;
vector<studentStruct*> vec;
studentStruct * studInfo = new studentStruct;
for (i=0;i<5;i++)
cin >> studInfo->studName[i] >> studInfo->scores[i];
vec.push_back(studInfo);
for (i=0;i<5;i++)
{
for (int y=0;y<4;y++)
{
if (studInfo->scores[y]<studInfo->scores[y+1])
{
t=studInfo->scores[y];
studInfo->scores[y]=studInfo->scores[y+1];
studInfo->scores[y+1]=t;
}
}
}
for (i=0;i<5;i++)
cout << vec.at(0)->scores[i] << " " << vec.at(0)->studName[i] << endl;
delete studInfo;
system("pause" );
return 0;
}
i cant sort the names by their score..pls help...pls..
Feb 11, 2010 at 6:28pm UTC
Help with what? YOu aren't even trying to do what you say that you can't do. First what would the strategy be? Are you doing to average the scores and sort on the average? The only thing that i see is that you are attempting to create one single student object and sort the scores within that array. You can't sort by student names because there is nothing to sort. There is only one student.
Topic archived. No new replies allowed.