define the Team class (in files Team.h and Team.cpp). For class member function GetWinPercentage(), the formula is: teamWins / (teamWins + teamLosses) Note: Use casting to prevent integer division. Ex: If the input is: Ravens 13 3 where Ravens is the team's name, 13 is number of team wins, and 3 is the number of team losses, the output is: Congratulations, Team Ravens has a winning average! If the input is Angels 80 82, the output is: Team Angels has a losing average.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 

7.23 LAB: Winning team (classes)

 

Given main(), define the Team class (in files Team.h and Team.cpp). For class member function GetWinPercentage(), the formula is:
teamWins / (teamWins + teamLosses)

Note: Use casting to prevent integer division.

Ex: If the input is:

Ravens 13 3

where Ravens is the team's name, 13 is number of team wins, and 3 is the number of team losses, the output is:

Congratulations, Team Ravens has a winning average!

If the input is Angels 80 82, the output is:

Team Angels has a losing average.
### Lab Activity: Winning Team (Classes)

**Current File: Team.cpp**

#### Description

This programming task focuses on implementing a class for managing sports teams. The primary goal is to define and implement necessary functions that handle and manipulate team data.

#### Code Overview

```cpp
#include "Team.h"

// TODO: Implement mutator functions -
//       SetTeamName(), SetTeamWins(), SetTeamLosses()

// TODO: Implement accessor functions -
//       GetTeamName(), GetTeamWins(), GetTeamLosses()

// TODO: Implement GetWinPercentage()
```

#### Task Details

1. **Mutator Functions**:
   - **SetTeamName()**: Define a function to set the team name.
   - **SetTeamWins()**: Define a function to update the team's wins.
   - **SetTeamLosses()**: Define a function to update the team's losses.

2. **Accessor Functions**:
   - **GetTeamName()**: Create a function to retrieve the team name.
   - **GetTeamWins()**: Create a function to get the number of wins.
   - **GetTeamLosses()**: Create a function to get the number of losses.

3. **Win Percentage Calculation**:
   - **GetWinPercentage()**: Implement a function to calculate and return the winning percentage of the team based on wins and losses.

This lab activity is designed to help students practice class design and implementation, focusing on encapsulation and data handling in C++.
Transcribed Image Text:### Lab Activity: Winning Team (Classes) **Current File: Team.cpp** #### Description This programming task focuses on implementing a class for managing sports teams. The primary goal is to define and implement necessary functions that handle and manipulate team data. #### Code Overview ```cpp #include "Team.h" // TODO: Implement mutator functions - // SetTeamName(), SetTeamWins(), SetTeamLosses() // TODO: Implement accessor functions - // GetTeamName(), GetTeamWins(), GetTeamLosses() // TODO: Implement GetWinPercentage() ``` #### Task Details 1. **Mutator Functions**: - **SetTeamName()**: Define a function to set the team name. - **SetTeamWins()**: Define a function to update the team's wins. - **SetTeamLosses()**: Define a function to update the team's losses. 2. **Accessor Functions**: - **GetTeamName()**: Create a function to retrieve the team name. - **GetTeamWins()**: Create a function to get the number of wins. - **GetTeamLosses()**: Create a function to get the number of losses. 3. **Win Percentage Calculation**: - **GetWinPercentage()**: Implement a function to calculate and return the winning percentage of the team based on wins and losses. This lab activity is designed to help students practice class design and implementation, focusing on encapsulation and data handling in C++.
# 7.23.1: LAB: Winning Team (Classes)

**Current File: Team.h**

This code is a header file for a C++ class named `Team`. It outlines the structure for a class that models a sports team with basic attributes and functions. Below is a detailed explanation of the components:

```cpp
#ifndef TEAMH
#define TEAMH

#include <string>

class Team {
    // TODO: Declare private data members - teamName, teamWins, teamLosses

    // TODO: Declare mutator functions -
    // SetTeamName(), SetTeamWins(), SetTeamLosses()

    // TODO: Declare accessor functions -
    // GetTeamName(), GetTeamWins(), GetTeamLosses()

    // TODO: Declare GetWinPercentage()
};

#endif
```

### Code Explanation

1. **Header Guards**: 
   - `#ifndef TEAMH` and `#define TEAMH` prevent multiple inclusions of the header file in different parts of the program, avoiding potential errors.

2. **Include Statement**:
   - `#include <string>` is necessary for using the `std::string` type, which will store the team's name.

3. **Class Declaration**:
   - `class Team { ... };` defines a class named `Team`.

4. **TODO Sections**:
   - **Private Data Members**: Intended for storing the team's name, the number of wins, and the number of losses.
   - **Mutator Functions**: These functions will allow setting the values of the team's name, wins, and losses.
   - **Accessor Functions**: These will enable retrieving the values of the team's name, wins, and losses.
   - **GetWinPercentage()**: This function should calculate and return the winning percentage of the team based on wins and losses.

### Purpose
This header file is part of a lab activity designed to teach students how to create and work with classes in C++. The students are expected to implement the private data members and functions, which encapsulate the data and provide interfaces for interacting with the `Team` objects.
Transcribed Image Text:# 7.23.1: LAB: Winning Team (Classes) **Current File: Team.h** This code is a header file for a C++ class named `Team`. It outlines the structure for a class that models a sports team with basic attributes and functions. Below is a detailed explanation of the components: ```cpp #ifndef TEAMH #define TEAMH #include <string> class Team { // TODO: Declare private data members - teamName, teamWins, teamLosses // TODO: Declare mutator functions - // SetTeamName(), SetTeamWins(), SetTeamLosses() // TODO: Declare accessor functions - // GetTeamName(), GetTeamWins(), GetTeamLosses() // TODO: Declare GetWinPercentage() }; #endif ``` ### Code Explanation 1. **Header Guards**: - `#ifndef TEAMH` and `#define TEAMH` prevent multiple inclusions of the header file in different parts of the program, avoiding potential errors. 2. **Include Statement**: - `#include <string>` is necessary for using the `std::string` type, which will store the team's name. 3. **Class Declaration**: - `class Team { ... };` defines a class named `Team`. 4. **TODO Sections**: - **Private Data Members**: Intended for storing the team's name, the number of wins, and the number of losses. - **Mutator Functions**: These functions will allow setting the values of the team's name, wins, and losses. - **Accessor Functions**: These will enable retrieving the values of the team's name, wins, and losses. - **GetWinPercentage()**: This function should calculate and return the winning percentage of the team based on wins and losses. ### Purpose This header file is part of a lab activity designed to teach students how to create and work with classes in C++. The students are expected to implement the private data members and functions, which encapsulate the data and provide interfaces for interacting with the `Team` objects.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education