Array losing values

Hello I am having problems with a class level array losing all of its values. The array list loses all of its values when going into ProcessMatchResults. Any help on how to fix this would be greatly appreciated. I had to remove class player and class ratingadjustmentlevel to fit but they shouldn't be needed.

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
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
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;

int numPlayers;


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

   // 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:
	int num2;
    int chartIndex;
    int decreaseFlip;
    int p1index;
    int p2index;
    int p1rating; 
    int p2rating,loser;
    int difference,w;
	
   // 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)
   {
	   num2 = numPlayers;
	   if(numPlayers>= MAX_PLAYERS)
	   {
		   return LIST_FULL;
	   }
	   else if (Find(p) != NOT_FOUND)
	   {
		   return IN_LIST;
	   }
	   else
	   {
		   list[num2]= p;
           //list[numPlayers].Read();
		   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 players is ";
      cout << numPlayers << "." << endl;
      cout << setiosflags(ios::left);
      cout << setw(8) << "RATING" << setw(17) << "LAST NAME"; 
      cout << 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 )
   {
	   chartIndex = LIST_FULL;
       decreaseFlip = NOT_FOUND;
       p1index = Find(p1);
       p2index = Find(p2);
       p1rating = list[p1index].GetRating();
       p2rating = list[p2index].GetRating();
       difference = p1rating - p2rating;
	  for(w = 0; w < MAX_LEVELS; w ++)
      {
         if(abs(difference) > chart[w].GetDiff())
            chartIndex ++;
      }
      if(difference >= 0)
         adjAmt = chart[chartIndex].GetAdjAmtNotUpset();
      else
         adjAmt = chart[chartIndex].GetAdjAmtUpset();
      p1.UpdateRating(adjAmt);
      loser = adjAmt * decreaseFlip;
      p2.UpdateRating(loser);
	  cout << "Performed play operation - for winner: " << p1.GetLast();
	  cout << " over the loser: " << p2.GetLast() << endl;
	  cout << "Ratings are adjusted by " << adjAmt <<endl;
	  cout <<"Winner : "<< p1.GetFirst() << " " << p1.GetLast()<< " has adjusted rating of "
			<< list[p1index].GetRating() << endl;
	  cout <<"Loser : "<< p2.GetFirst() << " " << p2.GetLast() << " has adjusted rating of "
		  << list[p2index].GetRating() <<endl;
	   //not done

   }
};  //PlayerList

class Tournament
{
private:
   RatingAdjustmentLevel chart[MAX_LEVELS];
   PlayerList            allPlayers;
   
   
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()
   {
	   char entered;
	   int outcome, adjAmount=0;
       string lastName, firstName;
       Player entry, entry2;
	   Player*newPlayer2 = new Player;
	   //int numPlayers;
	   while (cin)
	   {
       cin >> entered;
	   if (entered == 'A')
	   {
		   entry.Read();
		   outcome = allPlayers.Add(entry);
            if(outcome == LIST_FULL)
               cout<< "Cannot perform add operation - the list is FULL!";
            else if(outcome == IN_LIST)
			{
               cout<< "Cannot perform add operation - ";
               cout<< entry.GetFirst() <<" " << entry.GetLast();
               cout<< " is already in the list!" << endl;
			}
			else
               cout<< "Performed add operation - for ";
               cout<< entry.GetFirst()<<" " << entry.GetLast() << ".";
			   numPlayers++;
            cout<< endl;
	   }
	   else if (entered == 'D')
	   {
		  //Drops player from list
		  entry.ReadName();
		  firstName =entry.GetFirst();
		  lastName =entry.GetLast();
		  //allPlayers.Remove(Player & ???);
		  //newPlayer2 -> ReadName();
		  if (allPlayers.Remove(entry) == true)
		  {
			  cout<< "Performed delete operation - for ";
			  cout<< entry.GetFirst() <<" " << entry.GetLast() << ".";
			  cout<< endl;
			  numPlayers--;
		  }
		  else if (allPlayers.Remove(entry) == false)
		  {
			  cout<< "Cannot perform delete operation - ";
			  cout<< entry.GetFirst() << " "<< entry.GetLast(); 
			  cout<< " is NOT in the list! "<<endl;
		  }
	   }

	  else if (entered == 'P') 
	   {
		   //plays new match
		  entry.ReadName();
		  entry2.ReadName();
		  allPlayers.ProcessMatchResult(chart,entry,entry2,adjAmount);
	   }
	   }
	   
   }
};   // Tournament

int main()
{
   RatingAdjustmentLevel* newAdjLevel = new RatingAdjustmentLevel;
   Player* newPlayer = new Player;
   Tournament* newTournament = new Tournament;
   PlayerList* newPlayerList = new PlayerList;
   newTournament -> ReadRatingAdjustmentLevelChart();
   cout << endl,
   cout<< "The following is an echo of the original players' list."<< endl;
   cout <<endl;
   newPlayerList -> Read();
   newPlayerList -> Print();
   cout << endl <<"Processing transactions..." <<endl;
   newTournament ->ProcessAllTransactions();
   cout<< endl<< "The following is the current players' list." <<endl;
   newPlayerList ->Print();
   return 0;
}
Topic archived. No new replies allowed.