-
Notifications
You must be signed in to change notification settings - Fork 33
/
sport.cpp
115 lines (85 loc) · 3.32 KB
/
sport.cpp
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
//*****************************************************************************************************
// Sport Class Implementation File
//
// This class implementation file defines the methods (member functions) of the Sport class.
//
// Other files required:
// 1. sport.h - header file for Sport class
//
//*****************************************************************************************************
#include "sport.h"
#include <iostream>
#include <iomanip>
#include <string>
//*****************************************************************************************************
Sport::Sport(const std::string &n) {
setName(n);
numTeams = 0;
teamNames = nullptr;
}
//*****************************************************************************************************
Sport::~Sport() {
delete[] teamNames; // deallocate memory in destructor
std::cout << "\nSport object destroyed\n";
}
//*****************************************************************************************************
void Sport::display() const {
Date d1 = getDate(); // sport.h includes Date.h so Date class is available to Sport class
std::cout << "\t\t" << std::setfill('.') << std::setw(30) << std::left
<< "Sport Name "
<< " " << getName()
<< "\n\t\t" << std::setw(30) << "Scheduled Date (M/D/YY) "
<< " ";
d1.displayDate();
std::cout << "\n\n\t\t" << std::setfill('.') << std::setw(30) << std::left
<< "Number of Teams "
<< " " << getNumTeams() << std::endl;
for (int i = 0; i < getNumTeams(); ++i)
std::cout << "\t\tTeam " << i + 1 << std::setw(24) << " "
<< " " << teamNames[i] << std::endl;
}
//*****************************************************************************************************
void Sport::populate() {
char entry;
std::cout << "\nEnter the name of the sport: ";
std::getline(std::cin, name);
setName(name);
std::cout << "Sport has a scheduled game? (Y/N)" << std::endl;
std::cin >> entry;
if (entry == 'Y' || entry == 'y') {
std::cout << "\nNext Scheduled Game";
nextGame.inputDate();
setDate(nextGame);
} else {
std::cout << "\nDefault date will be set to January 1, 2000" << std::endl;
}
std::cout << "\nEnter the number of teams: ";
std::cin >> numTeams;
setNumTeams(numTeams);
teamNames = new std::string[numTeams];
std::cin.ignore();
for (int i = 0; i < numTeams; ++i) {
std::cout << "Enter the name of team " << i + 1 << ": ";
std::getline(std::cin, teamNames[i]);
}
}
//*****************************************************************************************************
void Sport::addTeam(const std::string &n) {
std::string *temp = new std::string[numTeams + 1];
for (int i = 0; i < numTeams; ++i)
temp[i] = teamNames[i];
temp[numTeams] = n;
delete[] teamNames;
teamNames = temp;
numTeams++;
}
//*****************************************************************************************************
/*
numTeams++;
string* tempTNames = new string[numTeams];
for (int i = 0; i < numTeams - 1; i++)
tempTNames[i] = teamNames[i];
tempTNames[numTeams - 1] = n;
teamNames = new string[numTeams];
teamNames = tempTNames;
*/