Question
Solve in C++ for Team.h and Team.cpp

Given main(). define the Team class (in files Team.h and Team.cpp). For class member function GetWinPercentage, the formula i
Current file: Team.h 1 include <iostream> using namespace std; 3. class Team 4 public: string name; 7 int wins; 8 int losses
Current file: Team.cpp 1 #include Team.h 3 TODO: Implement mutator functions 4 // Set TeamName(), SetTeamwins, SetTeamLosses
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hello here is the answer to the above question. Hope it helps.

Main.cpp

#include <bits/stdc++.h>
#include"Team.cpp"
using namespace std;
int main(int argc, const char *argv[])
{
Team team;
string name;
int wins;
int losses;
cin>>name;
cin>>wins;
cin>>losses;
team.SetTeamName(name);
team.SetTeamWins(wins);
team.SetTeamLosses(losses);
if(team.GetWinPercentage()>=0.5)
{
cout<<"Congratulations, Team "<<team.GetTeamName()<<" has a winning average!"<<endl;
}
else{
cout<<"Team "<<team.GetTeamName()<<" has a losing average."<<endl;
}
return 0;
}

Team.h

#include<iostream>
#include<string>
using namespace std;
class Team{
public:
string name;
int wins;
int losses;
void SetTeamName(string team_name);
void SetTeamWins(int team_wins);
void SetTeamLosses(int team_losses);
string GetTeamName();
int GetTeamWins();
int GetTeamLosses();
double GetWinPercentage();
};

Team.cpp

#include "Team.h"
#include<iostream>
#include<string>
using namespace std;

//In this file, all the functions declared in the Team.h are being defined.
void Team::SetTeamName(string team_name)
{
this->name = team_name;
}
void Team::SetTeamWins(int team_wins)
{
this->wins = team_wins;
}
void Team::SetTeamLosses(int team_losses)
{
this->losses = team_losses;
}
string Team::GetTeamName()
{
return this->name;
}
int Team::GetTeamWins()
{
return this->wins;
}
int Team::GetTeamLosses()
{
return this->losses;
}
double Team::GetWinPercentage()
{
return (wins)/((float)(wins+losses));
}

OUTPUT:

Ca. Main Ravens 13 3 Congratulations, Team Ravens has a winning average! Press any key to continue .

01. Main Angels 80 82 Team Angels has a losing average. Press any key to continue.

Add a comment
Answer #2

main.cpp

#include <iostream>
#include <string>
#include "Team.h"
using namespace std;

int main(int argc, const char* argv[]) {
   string name;
   int wins;
   int losses;
   Team team;
   cin >> name;
   cin >> wins;
   cin >> losses;
   
   team.SetTeamName(name);
   team.SetTeamWins(wins);
   team.SetTeamLosses(losses);
   
   if (team.GetWinPercentage() >= 0.5) {
      cout << "Congratulations, Team " << team.GetTeamName() <<
              " has a winning average!" << endl;
   }
   else {
      cout << "Team " << team.GetTeamName() << " has a losing average." << endl;
   }
}


Team.h

#include <string>
#ifndef TEAMH
#define TEAMH
using namespace std;
using std::string;

class Team {
   // TODO: Declare private data members - teamName, teamWins, teamLosses
   private:
      string teamName;
      int teamWins;
      int teamLosses;
      
   // TODO: Declare mutator functions - 
   //       SetTeamName(), SetTeamWins(), SetTeamLosses()
   public: 
      void SetTeamName(string name);
      void SetTeamWins(int wins);
      void SetTeamLosses(int losses);
      
   // TODO: Declare accessor functions - 
   //       GetTeamName(), GetTeamWins(), GetTeamLosses()
      string GetTeamName() const;
      int GetTeamWins() const;
      int GetTeamLosses() const; 
      
   // TODO: Declare GetWinPercentage()
      double GetWinPercentage();
};
#endif


Team.cpp

#include <iostream>
#include <string>
#include "Team.h"
using namespace std;
using std::string;

// TODO: Implement mutator functions - 
//       SetTeamName(), SetTeamWins(), SetTeamLosses()
   void Team::SetTeamName(string name) {
      teamName = name;
   }
   
   void Team::SetTeamWins(int wins) {
      teamWins = wins;
   }
   
   void Team::SetTeamLosses(int losses) {
      teamLosses = losses;
   }
   
// TODO: Implement accessor functions - 
//       GetTeamName(), GetTeamWins(), GetTeamLosses()
   string Team::GetTeamName() const {
      return teamName;
   }
   
   int Team::GetTeamWins() const {
      return teamWins;
   }
   
   int Team::GetTeamLosses() const {
      return teamLosses;
   }
   
// TODO: Implement GetWinPercentage()
   double Team::GetWinPercentage() {
      double winAverage;
      winAverage = (static_cast<double>(teamWins) / static_cast<double>(teamWins + teamLosses) );
      
      return winAverage;
   }

      



source: I got a 100%
answered by: helper
Add a comment
Know the answer?
Add Answer to:
Solve in C++ for Team.h and Team.cpp Given main(). define the Team class (in files Team.h...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Solve in C++ for Car.h and Car.cpp 8.21 LAB: Car value (classes) Given main, complete the...

    Solve in C++ for Car.h and Car.cpp 8.21 LAB: Car value (classes) Given main, complete the Car class (in files Car hand Car.cpp) with member functions to set and get the purchase price of a car (SetPurchase Price().GetPurchase Price)and to output the car's information (Printinfo). Ex If the input is 2011 18000 2018 where 2011 is the car's model year, 18000 is the purchase price, and 2018 is the current year, the output is Car's information Model year: 2011 Purchase...

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

  • This is a simple C++ class using inheritance, I have trouble getting the program to work....

    This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class). The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is...

  • C++ programming question, please help! Thank you so much in advance!!! In this exercise, you will...

    C++ programming question, please help! Thank you so much in advance!!! In this exercise, you will work with 2 classes to be used in a RPG videogame. The first class is the class Character. The Character class has two string type properties: name and race. The Character class also has the following methods: a constructor Character(string Name, string Race), that will set the values for the name and the race variables set/get functions for the two attributes a function print(),...

  • C++ Language I have a class named movie which allows a movie object to take the...

    C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...

  • Given the following class definition in the file Classroom.h, which XXX and YYY complete the corresponding.cpp...

    Given the following class definition in the file Classroom.h, which XXX and YYY complete the corresponding.cpp file? #ifndef CLASSROOM_H #define CLASSROOM_H class Classroom public: void SetNumber(int n); void Printo const; private: int num; }; Tendif #include <iostream using namespace std; XXX void Class Room:: Set Number(int n) { nun: cout << "Number of Class Rooms: << num << endl; include "Classroom.hr vold Classroom: Print( const sinclude "Classroom.cpp" vold Classroom. Print() const #include "Classroom.h" void Class Room::Print) const #include "Classroom.cpp" void...

  • Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string;...

    Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string; class Account { public: Account(); Account(string, double); void deposit(double); bool withdraw(double); string getName() const; double getBalance() const; private: string name; double balance; }; #endif ////////////////////////////////////////////// //AccountManager.hpp #ifndef _ACCOUNT_MANAGER_HPP_ #define _ACCOUNT_MANAGER_HPP_ #include "Account.hpp" #include <string> using std::string; class AccountManager { public: AccountManager(); AccountManager(const AccountManager&); //copy constructor void open(string); void close(string); void depositByName(string,double); bool withdrawByName(string,double); double getBalanceByName(string); Account getAccountByName(string); void openSuperVipAccount(Account&); void closeSuperVipAccount(); bool getBalanceOfSuperVipAccount(double&) const;...

  • This is for my c++ class and I would really appreciate the help, Thank you! Complete...

    This is for my c++ class and I would really appreciate the help, Thank you! Complete the definitions of the functions for the ConcessionStand class in the ConcessionStand.cpp file. The class definition and function prototypes are in the provided ConcessionStand.h header file. A testing program is in the provided main.cpp file. You don’t need to change anything in ConcessionStand.h or main.cpp, unless you want to play with different options in the main.cpp program. ___________________ Main.cpp ____________________ #include "ConcessionStand.h" #include <iostream>...

  • 10.18 LAB: Plant information (vector) Given a base Plant class and a derived Flower class, complete...

    10.18 LAB: Plant information (vector) Given a base Plant class and a derived Flower class, complete main() to create a vector called myGarden. The vector should be able to store objects that belong to the Plant class or the Flower class. Create a function called PrintVector(), that uses the PrintInfo() functions defined in the respective classes and prints each element in myGarden. The program should read plants or flowers from input (ending with -1), adding each Plant or Flower to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT