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
|
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstddef>
#include<string>
using namespace std;
class golf_info
{
public:
string last_name;
string first_name;
char middle_int;
int score[9];
int total;
int over;
void get_name(string& first_name, string& last_name, char middle_int);
void get_score(int score[]);
void calc_score(int total, int over);
void show_score();
};
int main ()
{
golf_info player;
string first_name;
string last_name;
char middle_int;
int number_used;
int total;
int over;
int score[9];
player.get_name(first_name, last_name, middle_int);
player.get_score(score);
player.calc_score(total, over);
player.show_score();
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
return 0;
}
void golf_info::get_name(string& first_name, string& last_name, char middle_int)
{
cout << "What is player's first name?" << endl;
cin >> first_name;
cout << "What is player's middle initial?" << endl;
cin >> middle_int;
cout << "What is player's last name?" << endl;
cin >> last_name;
}
void golf_info::get_score(int score[])
{
score[] = {3, 4, 4, 5, 6, 4, 7, 4, 6};
}
void golf_info::calc_score(int total, int over)
{
int i;
for (i=0; i<5; i++)
{
total = 0;
total+=score[i];
}
over = total - 36;
}
void golf_info::show_score()
{
cout << "Last name: " << last_name << endl;
cout << "Middle initial: " << middle_int << endl;
cout << "First name: " << first_name << endl;
cout << "Scores: " << score << endl;
cout << "Total: " << total << endl;
cout << "Over: " << over << endl;
}
|