Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <string>
- #include <cmath>
- using namespace std;
- void swap(double& v1, double& v2) {
- double temp;
- temp = v1;
- v1 = v2;
- v2 = temp;
- }
- //Exchange values in v1 and v2
- void sort(double& v1, double& v2, double& v3) {
- if (v1 > v3) {
- swap(v1, v3);
- }
- if (v1 > v2) {
- swap(v1, v2);
- }
- if (v2 > v3) {
- swap(v2, v3);
- }
- }
- //reorder values such that v1 <= v2 <= v3
- double final(double v1, double v2, double v3) {
- return (.5*v1) + v2 + (.5*v3);
- }
- //Return the weighted sum, 1/2v1 + v2 + 1/2 v3
- string lastName(string fullName) {
- int commaPos = fullName.find(",");
- int nameLength = fullName.length();
- return fullName.substr(commaPos, nameLength);
- }
- //return the last name
- string firstName(string fullName) {
- int commaPos = fullName.find(",");
- return fullName.substr(0, commaPos);
- }
- //return the first name
- int main()
- {
- int count = 0;
- string name;
- double score1, score2, score3;
- ifstream fin;
- cout << "Cooking Contest by Logan Crone" << endl << endl;
- cout << "Name" << setw(30) << "Score 1" << setw(10) << "Score 2" << setw(10) << "Score 3" << setw(15) << "Final Score";
- while (!fin.eof()) { //while not end of report, do the following:
- fin >> setprecision(2); //Sets the precision to two decimals
- count++; //Increases the count variable
- fin >> name >> score1 >> score2 >> score3; //Reads in each set of text on the line and stores into appropriate variable
- sort(score1, score2, score3);
- cout << firstName(name) << lastName(name) << score1 << score2 << score3 << final(score1, score2, score3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement