Public feed #891906

Unnamed

public cpp v1 · immutable
Raw Edit
·published 2008-02-05 00:08 UTC
rendered paste body
#include <cstdlib>#include <iostream>#include <vector>using namespace std;struct Score{	string name;	int score;};vector <Score> highScores;void AddHighScore(string Nam, int Scor){	Score newScore;	newScore.name = Nam;	newScore.score = Scor;	for(int i = 0; i < highScores.size(); i++)	{		if(newScore.score > highScores[i].score)		{			highScores.insert(highScores.begin() + i, newScore);			return;		}	}	// If it gets here, it means it is smaller then every other score, so just add it to the bottom	highScores.push_back(newScore);}void RemoveScore(string Nam){	for(int i = 0; i < highScores.size(); i++)	{		if(strcmp(highScores[i].name.c_str(), Nam.c_str()) == 0)		{			highScores.erase(highScores.begin() + i);			return;		}	}}void PrintScores(){	for(int i = 0; i < highScores.size(); i++)	{		cout << "Name: " << highScores[i].name.c_str() << " Score: " << highScores[i].score << endl;	}}int main(int argc, char *argv[]){	AddHighScore("Mike", 1105);	AddHighScore("Rob", 750);	AddHighScore("Paul", 720);	AddHighScore("Anna", 660);	AddHighScore("Rose", 590);	AddHighScore("Jack", 510);	PrintScores();	cout << "\n\nAdding Jill with a score of 740.\n\n";	AddHighScore("Jill", 740);		cout << "Printing new High Scores table...\n\n";	PrintScores();	cout << "Removing Paul's high score...\n\n";	RemoveScore("Paul");	cout << "Printing final High Scores table...\n\n";	PrintScores();	system("PAUSE");	return EXIT_SUCCESS;}