Help

Hello Looking for some help to solve a problem I can't figure out. For example I'm given a command ('D') to remove a player (Lastname: Green, Firstname: Tommy) from the players list. I'm given class and functions I must use in the program and they're all in my program. I am not allowed to use any more private/public fields or methods in the four classes I'm given. Except I can use private methods in the Tournament class. variables have to be local. I know i have to create a find player function in the Tournamnet class in the private are, but I can't figure out how to compare the player last and first name the methods I'm given. I have a method that read players state, point, last, and first names. Thu when I have to remove a player. Im only given their last and first name. I feel I have to take the cin last and first name and use GetLastName() and GetFirstName(), and compare them to the cin last and first name. That's where Im at now. Any help with examples or explanations would be great. Thank you.

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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

const int  NOT_FOUND   = -1;
const int  MAX_PLAYERS = 25;
const int  MAX_LEVELS  = 11;
const int  LIST_FULL   = 0;
const int  IN_LIST     = 1;
const int  ADDED       = 2;

class RatingAdjustmentLevel
{
private:
   int ratingDiff;
   int adjAmtNotUpset;
   int adjAmtUpset;

public:
   // Reads the three fields.
   void Read()
   {
      cin >> ratingDiff >> adjAmtNotUpset >> adjAmtUpset;
   }

   // Returns the value of ratingDiff.
   int  GetDiff() const
   {
      return ratingDiff;
   }

   // Returns the value of adjAmtNotUpset.
   int GetAdjAmtNotUpset() const
   {
      return adjAmtNotUpset;
   }

   // Returns the value of adjAmtUpset.
   int GetAdjAmtUpset() const
   {
      return adjAmtUpset;
   }

}; // RatingAdjustmentLevel

class Player
{
private:
   string state;
   int rating;
   string last;
   string first;

public:
   // Reads the four fields.
   void Read()
   {
         cin >> state >> rating >> last >> first;
   }

   // Returns the first name.
   string GetFirst() const
   {
      return first;
   }

   // Returns the last name.
   string GetLast() const
   {
      return last;
   }

   // Returns the rating.
   int GetRating() const
   {
      return rating;
   }

   // Displays rating, last name, first name and state.
   // See output description for the exact output format.
   void Print() const
   {
      cout << setiosflags(ios::left);
      cout << setw(8) << rating 
           << setw(17) << last 
           << setw(18) << first 
           << setw(5) << state << endl;
   }

   // Returns true if the first and last names of Player p are 
   // respectively, equal to the first and last name of this
   // object, itself.
   // params: in 
   bool Equals( const Player& p ) const
   {
      if (p.GetFirst() == first && p.GetLast() == last)
         return true;
      else
         return false;
   }

   // Updates the rating by adding points to rating.
   void UpdateRating( int points )
   {
      rating += points;
   }

};  // Player

class PlayerList
{
private:
   Player list[MAX_PLAYERS];
   int    numPlayers;

   // Returns the index of array element of list 
   // that has the same first name and last name as p.
   // It returns -1 otherwise.
   // params: in 
   int Find( const Player& p ) const
   {
      for (int i = 0; i < numPlayers; i++)
         if (list[i].Equals(p) == true)
            return i;
      return NOT_FOUND;
   }

   public:
   // Reads numPlayers and that number of players into list.
   void Read()
   {
      cin >> numPlayers;
      for (int i = 0; i < numPlayers; i++)
         list[i].Read();
   }

   // Returns LIST_FULL if list is full, IN_LIST if p is in list already,
   // and ADDED otherwise after adding p to the end of list.
   // params: in 
   int Add(const Player& p)
   {
      if (numPlayers >= MAX_PLAYERS)
         return LIST_FULL;
      else if (Find(p) != NOT_FOUND)
         return IN_LIST;
      else
      {
         list[numPlayers].Read();
         numPlayers++;
         return ADDED;
      }
   }

   // Returns false if p is not in list, and true otherwise after removing
   // p from list and moving players in list after p up one position.
   // params: in 
   bool Remove( const Player& p )
   {
      int index = Find(p);
      if (index == NOT_FOUND)
         return false;
      else
      {
         for (int i = index; i < numPlayers; i++)
         {
            list[i] = list[i + 1];
         }
         numPlayers --;
         return true;
      }
   }

   // Displays all players in list.
   // See output description for the exact output format.
   void Print() const
   {
      cout << "The current number of table tennis player is "
           << numPlayers << "." << endl;
      cout << setiosflags(ios::left);
      cout << setw(8) << "RATING" 
           << setw(17) << "LAST NAME" 
           << setw(18) << "FIRST NAME" 
           << setw(5) << "STATE" << endl;
      for (int i = 0; i < numPlayers; i++)
      {
         list[i].Print();
      }
   }

   // Updates the ratings of p1 (winner) and p2 (loser) in list according to chart[].
   // When the method is called, p1 and p2 only have the player's name and 
   // adjAmt may not have the correct value;
   // after the method is executed, p1 and p2 should have all player's data,
   // including the updated rating, and adjAmt should have the correct value
   // that is used to update the two players' ratings.
   // params: in, in, inout, inout, out 
   void ProcessMatchResult( const RatingAdjustmentLevel chart[],
                            Player& p1, Player& p2, int& adjAmt )
   {
      int chartIndex = 0;
      int decreaseFlip = -1;
      int p1index = Find(p1);
      int p2index = Find(p2);
      int p1rating = list[p1index].GetRating();
      int p2rating = list[p2index].GetRating();
      //May be able to remove some of this
      int difference = p1rating - p2rating;
      for(int i = 0; i < MAX_LEVELS; i ++)
      {
         if(abs(difference) > chart[i].GetDiff())
            chartIndex ++;
      }
      if(difference >= 0)
         adjAmt = chart[chartIndex].GetAdjAmtNotUpset();
      else
         adjAmt = chart[chartIndex].GetAdjAmtUpset();
      p1.UpdateRating(adjAmt);
      int loser = adjAmt * decreaseFlip;
      p2.UpdateRating(loser);
      //Printing Statement here (??)
   }
      
};  //PlayerList

class Tournament
{
private:
   RatingAdjustmentLevel chart[MAX_LEVELS];
   PlayerList            allPlayers;
   
   void NametoPlayer()
   {
      string Last, First;
      cin >> Last >> First;
      // ??????
   }
public:
   // Reads the rating adjustment chart.
   void ReadRatingAdjustmentLevelChart()
   {
      for(int i = 0; i < MAX_LEVELS; i ++)
         chart[i].Read();
   }

   // Reads the players' list to allPlayers.
   void ReadPlayerList()
   {
      allPlayers.Read();
   }

   // Displays all players in allPlayers.
   void PrintPlayerList() const
   {
      allPlayers.Print();
   }

   // Processes all transactions until the end of file.
   void ProcessAllTransactions()
   {
      while(cin)
      {
         char action;
         int result;
         string lastName, firstName;
         Player entry, entry2;
         cin >> action;
         if(action == 'A')
         {
            entry.Read();
            result = allPlayers.Add(entry);
            if(result == LIST_FULL)
               cout << "Cannot perform add operation - the list is FULL!";
            else if(result == IN_LIST)
               cout << "Cannot perform add operation - "
                    << entry.GetFirst() << entry.GetLast
                    << " is already in the list!" << endl;
            else
               cout << "Performed add operation - for "
                    << entry.GetFirst << entry.GetLast << ".";
            cout << endl;
         }
         else if(action == 'D')
         {
            //get input into entry
            //run entry through Remove
            //Printing statement??
         }
         else if(action == 'P')
         {
            //Magically read names into two classses
            //Call ProcessMatchResult
            //Printing statement???
         }
      }
   }
};   // Tournament


int main()
{
   return 0;
}
Topic archived. No new replies allowed.