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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
// Alexandra Kraft 12/02/2014
// Lab N - Olympic (or other) Diving
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;
void read_data(string country[], string Dname[], int age[], int size, double DD, double score[], double final_score[]);
double bubble_sort(double score[], double DD);
int main()
{
string Dname[6];
string country[6];
int age[6];
double final_score[6];
int size = 6;
double DD = 0;
double score[6];
cout << fixed << showpoint << setprecision(2);
read_data(country, Dname, age, size, DD, score, final_score);
system("pause");
return 0;
}
void read_data(string country[], string Dname[], int age[], int size, double DD, double score[], double final_score[])
{
ifstream dataIn;
dataIn.open("diving.txt");
if (dataIn.fail())
{
cout << "File does not exist." << endl;
system("pause");
exit(1);
}
int i, count;
double answer;
for (i = 0; i < size; i++) // diver
{
getline(dataIn, country[i]);
getline(dataIn, Dname[i]);
dataIn >> age[i];
double total = 0;
for (count = 0; count < 5; count++) // dive
{
dataIn >> DD;
dataIn >> score[0];
dataIn >> score[1];
dataIn >> score[2];
dataIn >> score[3];
dataIn >> score[4];
dataIn >> score[5];
dataIn >> score[6];
answer = bubble_sort(score, DD);
total = total + answer;
}
dataIn.get();
}
int counter;
for (counter = 0; counter < 6; counter++)
{
cout << "Rank " << counter + 1 << ": " << final_score[counter] << " " << Dname[counter] << " " << age[counter] << " " << country[counter] << endl;
}
dataIn.close();
}
double bubble_sort(double score[], double DD)
{
vector<double>judge(7);
judge[0] = score[0];
judge[1] = score[1];
judge[2] = score[2];
judge[3] = score[3];
judge[4] = score[4];
judge[5] = score[5];
judge[6] = score[6];
double temp;
int counter;
bool swap;
do
{
swap = false;
for (counter = 0; counter < 6; counter++)
{
if (judge[counter] < judge[counter + 1])
{
temp = judge[counter];
judge[counter] = judge[counter + 1];
judge[counter + 1] = temp;
swap = true;
}
}
} while (swap == true);
judge.pop_back();
judge.pop_back();
reverse(judge.begin(), judge.end());
judge.pop_back();
judge.pop_back();
double thisDive = (judge[0] + judge[1] + judge[2])*DD;
return thisDive;
}
|