Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <fstream>
  5. #include <string>
  6. #include <cmath>
  7. using namespace std;
  8.  
  9. void swap(double& v1, double& v2) {
  10. double temp;
  11. temp = v1;
  12. v1 = v2;
  13. v2 = temp;
  14. }
  15. //Exchange values in v1 and v2
  16.  
  17. void sort(double& v1, double& v2, double& v3) {
  18. if (v1 > v3) {
  19. swap(v1, v3);
  20. }
  21. if (v1 > v2) {
  22. swap(v1, v2);
  23. }
  24. if (v2 > v3) {
  25. swap(v2, v3);
  26. }
  27. }
  28. //reorder values such that v1 <= v2 <= v3
  29.  
  30. double final(double v1, double v2, double v3) {
  31. return (.5*v1) + v2 + (.5*v3);
  32. }
  33. //Return the weighted sum, 1/2v1 + v2 + 1/2 v3
  34.  
  35. string lastName(string fullName) {
  36. int commaPos = fullName.find(",");
  37. int nameLength = fullName.length();
  38. return fullName.substr(commaPos, nameLength);
  39. }
  40. //return the last name
  41.  
  42. string firstName(string fullName) {
  43. int commaPos = fullName.find(",");
  44. return fullName.substr(0, commaPos);
  45. }
  46. //return the first name
  47.  
  48. int main()
  49. {
  50. int count = 0;
  51. string name;
  52. double score1, score2, score3;
  53. ifstream fin;
  54.  
  55. cout << "Cooking Contest by Logan Crone" << endl << endl;
  56. cout << "Name" << setw(30) << "Score 1" << setw(10) << "Score 2" << setw(10) << "Score 3" << setw(15) << "Final Score";
  57.  
  58. while (!fin.eof()) { //while not end of report, do the following:
  59. fin >> setprecision(2); //Sets the precision to two decimals
  60. count++; //Increases the count variable
  61. fin >> name >> score1 >> score2 >> score3; //Reads in each set of text on the line and stores into appropriate variable
  62. sort(score1, score2, score3);
  63. cout << firstName(name) << lastName(name) << score1 << score2 << score3 << final(score1, score2, score3);
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement