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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/*
Name: blank
Lab Number: <17828>
Lab: <W>
Due: Midnight, 13 Feb-2014
Assignment 1 - Functions
Assuming: The user wil use scores between 0 and 10
The user will enter number when asked
--------------------Pseudocode------------------------
main()
getYear() gets the year
cin.ignore() clears the buffer
getName() gets diver name
menu() displays the menu
userChoice() get dive and difficulty
enterScores() get three scores; increment dive #
calcTotal() sum the points for 3 dives
displayHeader() output header to screen
displayInfo() output first diver data
displayInfo() output second diver data
------------------------------------------------------
*/
#include <iostream>
#include <string>
#include <iomanip>
const int WID1 = 8;
using namespace std;
//prototypes
string getName(string which_one);
//gets diver name
int getYear(int);
//gets the year
void menu(int);
//displays the menu
double userChoice(char, double);
//get dive and difficulty
double enterScores(double, double, double, int&);
//get three scores; increment dive #
double calcTotal(double, double, double, double);
//sum the points for 3 dives
void displayHeader(string, int);
//output header to screen
void displayInfo(char, double, double, double, double, double, double);
//output diver data
int main()
{
int dive_number = 1, year;
double total1, total2,
difficulty1, difficulty2,
score11, score12, score13,
score21, score22, score23,
average1, average2;
string divername;
char dive1, dive2;
average1 = ( score11 + score12 + score13 ) / 3;
average2 = ( score21 + score22 + score23 ) / 3;
getYear(year);
getName(divername);
menu(year);
userChoice(dive1, difficulty1);
enterScores(score11, score12, score13, dive_number);
total1 = calcTotal(score11, score12, score13, difficulty1);
menu(year);
userChoice(dive2, difficulty2);
enterScores(score21, score22, score23, dive_number);
total2 = calcTotal(score21, score22, score23, difficulty2);
displayHeader(divername, year);
displayInfo(dive1, difficulty1, score11, score12, score13, total1, average1);
displayInfo(dive2, difficulty2, score21, score22, score23, total2, average2);
cout << endl<< endl;
return 0;
}
//start headers
//header for getName
//This will get the name from the user
string getName(string which_one)
{
string divername;
cout << "Enter the Diver's name: "<< which_one;
getline(cin, divername);
return divername;
}
//header for getYear
//This will get the year from the user
int getYear(int which_one)
{
int year;
cout << "What is the current year? " << year;
cin >> year;
return year;
}
//header for menu
//This function will display the ASU Diving Menu
void menu(int year)
{
cout << endl;
cout << setw(25) << "Menu\n";
cout << setw(35) << "ASU Diving Competition - " << year << "\n";
cout << setw(41) << "---------------------------------\n";
cout << setw(19) << "Dive" << setw(22) << "Difficulty\n";
cout << "\n" << setw(WID1) << "A. " << "Forward Jump Pike" << setw(14) << "1.0";
cout << "\n" << setw(WID1) << "B. " << "Forward Dive Straight" << setw(10) << "1.6";
cout << "\n" << setw(WID1) << "C. " << "Forward 2.5 Tuck" << setw(15) << "2.2";
cout << "\n" << setw(WID1) << "D. " << "Back 3.5 Truck" <<setw(18) << "3.4";
cout << "\n" << setw(WID1) << "E. " << "Inward 0.5 Twist Straight" << setw(6) << "1.9";
cout << setw(41) << "\n---------------------------------\n";
}
//header for userChoice
//This will get the dive and difficulty of the dive
double userChoice(char & dive, double & difficulty)
{
char dive;
double difficulty;
cout << "Enter the dive being judged (A - E): ";
cin >> dive;
cout << "Enter the dive difficulty: ";
cin >> difficulty;
cout << endl << endl;
}
//header for enterScores
//This will get the scores and increment the dive number
double enterScores(double & score_1, double & score_2, double & score_3, int & dive_number)
{
cout << "Enter the score 1 for dive" << dive_number << " : ";
cin >> score_1;
cout << "Enter the score 2 for dive" << dive_number << " : ";
cin >> score_2;
cout << "Enter the score 3 for dive" << dive_number << " : ";
cin >> score_3;
dive_number++;
}
//header for calcTotal
//This wil calculate the total score of the 3 dives
double calcTotal(double a, double b, double c, double difficulty)
{ return (a + b + c) * difficulty; }
//header for displayHeader
// This function displays the header for the diving score grid for the diver
void displayHeader(string divername, int year)
{
cout << endl << endl << endl;
cout << setw(33) << "ASU Diving Competition - " << year<< "\n";
cout << setw(26) << "Diving Scores for " << divername << endl;
cout << setw(45) << "------------------------------------------\n";
cout << setw(6) << "Dive" << setw(12)
<< "Difficulty" << setw(WID1+1) << "Score 1"
<< setw(WID1+1) << "Score 2" << setw(WID1+1) << "Score 3"
<< setw(WID1+1) << "Total" << setw(11) << "Average\n";
}
//header for displayInfo
//This function will display the diver info
void displayInfo(char dive, double difficulty, double score1, double score2, double score3, double total, double average)
{
cout << setw(7) << dive << setw(14)
<< difficulty << setw(WID1+2) << score1
<< setw(WID1+2) << score2 << setw(WID1+2) << score3
<< setw(WID1+1) << total << setw(12) << average;
}
|