structure subjective

1
2
3
4
5
6
7
8
9
10
11
12
13
struct Team
{
char name[20];
int members;
int score;
};
int main()
{
Team *footballTeam;
footballTeam = new Team[10];
// add all footballTeam information
return 0;
}



Write the code to enter 10 football teams information and store them in the dynamically created array footballTeam.

(ii) What problems may arise from the code above if no other code is added? Explain how this can be solved and provide suitable code to do this.


for first 1 we can use

1
2
3
4
5
6
for( int i = 0 ; i < 10 ; i ++ ){
     cout << "Enter team " << (i+1) << endl
          << "Enter Name : ";
     cin.getline( footballTeam[i].name , 20 )
      ....
}


for question 2 that what problems will be arise ?
how should provide the suitable code? mean?
To avoid memory leaks, memory allocated with new should always be released with a corresponding delete.

And new [] should have a corresponding delete [].
Topic archived. No new replies allowed.