Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can't figure this one out!! # Part 1 - LAB (50%) In this workshop you have to Implement two modules (i.e., classes): ** Tournament **

Can't figure this one out!!

# Part 1 - LAB (50%)

In this workshop you have to

Implement two modules (i.e., classes): **Tournament** and **SoccerTeam**

## The SoccerTeam module

Develop this module in two files named **soccerTeam.h** and **soccerTeam.cpp**. Create a structure named **soccerTeam** and the structure should have the following member variables (attributes) and member functions (method):

First, define the following constant in the **soccerTeam** header file:

```

const int MAX_FOUL = 4; //maximum number of fouls

```

#### member variables(attributes)

The struct soccerTeam should have the following member variables:

```C++

char m_teamName[41];// a statically allocated Cstring with size 41. Remember, name could be

//maximum 40 characters long and 1 byte is for the null byte.

int m_noFouls;//number of fouls, it can be zero or more but cannot be a negative number

double m_fines;//it can be equal to and more than zero.

int m_golas;//can be zero or more

```

#### member functions(methods)

```c++

void setTeam(const SoccerTeam& team)

```

It will set the team name, fine and fouls of the team.

```c++

void setName(const char* tname)

```

If the received name pointer is valid and not null it will copy the received name to the data member **m_teamName**

```c++

void setFine(double fines, int foul)

```

It will receive the information about fines and no of foul. After checking the validity it will set the values to the appropriate data members. Fine and foul should be grater than and equal to zero. Otherwise, it will set the soccerTeam object to an empty state.

```C++

void setEmpty();

```

Sets the **soccerTeam** object to an Empty State. Do this by setting the **m_teamName** to an empty Cstring, **m_noFoul** and **m_fines** to a negative number and **m_goals** to **0**.

```C++

bool isEmpty() const;

```

Returns true if **m_teamName** is not null, **m_fines** and **m_noFouls** is grater than **0**.

```C++

void calFines();

```

If this function is called it will increases the fine by 20% of the old fine value.

```C++

int fouls() const ;

```

It will return the m_noFoul

#### A **soccerTeam** can be created in two different ways:

```C++

soccerTeam();

```

- By default a **soccerTeam** is set to the empty state (as in setEmpty())

###### Three argument constructor

```C++

SoccerTeam(const char* tname, double fines, int foul);

```

After checking the validity it will set the team`s name,fine and no of fouls to the appropriate data members or else it will set the team to the empty state. (reuse your setter fucntions)

```C++

std::ostream& display()const;

```

1) If a soccerTeam object is valid

a) prints **m_teamName** with width 30, left justified and fill with empty spaces.

b) prints **m_fines** with width 6 and after the decimal point 2 digits.

c) prints **m_noFoul** with width 6

d) prints **m_fines** with width 6

e) prints **m_golas** with width 10. If number of goals are greater than zero then it will print "w" besides the number.

2) otherwise prints, "Invalid Team".

3) At the end return the reference of the ostream object.

## The Tournament module

Develop this module in two files named **Tournament.h** and **Tournament.cpp**. Place your class definition in **Tournament.h** and your function definitions in **Tournament.cpp**. Create a class named **Tournament** and the class should have the following member variables (attributes) and member functions (method):

#### Private member variables(attributes)

The class should have the following private member variables:

```C++

char* m_name;//points to a dynamically allocated Cstring

int m_num;//size of the dynamically allocated array of soccer team. It should be more then

zero.

SoccerTeam* m_soccer=nullptr;//pointer to the dynamically allocated array of soccerTeam

```

#### Public member functions(methods)

```C++

void setTournament(const char* name, int noOfteam,const SoccerTeam* soccer);

```

- First, it will check the validity of all the received arguments. Tournament name should be valid and non-empty Cstring. Number of teams should be greater than zero.

- It will set **m_num** to the corresponding argument value.

- Then it will dynamically allocate memory for tournament name in the tournament name pointer attribute and then copies the content of the tournament name

argument into the newly allocated memory.

- It will dynamically allocate an array of soccer team pointed by **m_soccer** member variable. The length of this array will be **m_num**.

- Lastly, add all the teams to the dynamically allocated array of **m_soccer**.

- If any of the arguments are not valid it will set the Tournament to an empty state.

```C++

void setEmpty();

```

Sets the **Tournamnet** object to an Empty State. Do this by setting the **m_name** and **m_soccer** to null and **m_num** to **0**.

```C++

bool isEmpty() const;

```

Returns true if **m_name** and **m_soccer** is not null and **m_num** is grater than **0**.

```C++

Tournament& match(const SoccerTeam* ls);

```

This function will find out the winner between 2 soccer teams by having matches. It will loop through all the teams.

- First it will check which team is having more no of fouls.

- If first team is having less fouls then second team then, second team`s no of foul will increase by double and fine will be increased by 20%

- First team`s goal will be increased by 1.

- If seconds team`s no of foul exceed the MAX_FOUL then this team will become a invalid team. You can do this by setting the number to foul to an invalid value.

- At the end it will return the reference of the current object.

```C++

ostream& display() const;

```

1) If Tournament object is valid

a) prints "Tournament name: " then tournament name

b) prints "list of the teams" after that a newline

c) prints "Fines" with width 45 and fill with empty spaces.

d) prints "Fouls" with width 10 and fill with empty spaces.

e) prints "Goals" with width 10 and fill with empty spaces.

e) prints all the soccer teams information. For details see the sample output.

2) otherwise prints, "Invalid Tournament".

3) At the end return the reference of the ostream object.

## Sample output

```C++

Tournament name : Soccer Tournament

list of the teams

Fines Fouls Goals

Team[1] : Scarborough Soccer Team 0.00 0 1w

Team[2] : North York Soccer Team 120.00 2 0

```

###### construction and destruction

A **Tournament** can be created in two different ways:

```C++

Tournament();

```

- By default a **Tournament** is initiated by setting all the member variable values to default values. You can do this by setting **m_name**, **m_soccer** to nullptr and **m_num** to a value like **0**.

###### Three argument constructor

```C++

Tournamnet(const char* name, int noOfteam,const SoccerTeam* soccer);

```

It works exactly like the setTournamnet()

```C++

~Tournament();

```

Deallocate the memory allocated by **m_name** and **m_soccer**.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions