Question

8.18 BallGame Lab Create the following class. You will NOT need setters and getters for this...

8.18 BallGame Lab

Create the following class. You will NOT need setters and getters for this as all of the attributes are public. There will however be 1 constructor as indicated.

class BallGame
 {
 public:
                string homeTeam;
                string awayTeam;
                int homeScore;
                int awayScore;
                BallGame(string hmTeam, string awTeam, int hmSc, int awSc);
                bool didHomeTeamWin();
 };

You must implement the constructor and the didHomeTeamWin() method. The method must return whether the home team has the larger score. (Note, a tie is not a win)

In main: Allocate memory for three separate BallGame instances and point to that memory with 3 separate pointer variables, game1, game2, and game3. Make each pointer represent the following data. Your constructor MUST accept the data in the order home team name, away team name, home team score, away team score:

 "Mystics", "Fire", 100,92
 "Capitals", "Lightning", 2,3
 "Ravens", "Colts",35,35

Homework Answers

Answer #1

#include<iostream>
using namespace std;

class BallGame{
    public:
                string homeTeam;
                string awayTeam;
                int homeScore;
                int awayScore;
                BallGame(string hmTeam, string awTeam, int hmSc, int awSc);
                bool didHomeTeamWin();
};
//constructor
BallGame::BallGame(string hT,string aT,int hS,int aS){
    homeTeam=hT;
    awayTeam=aT;
    homeScore=hS;
    awayScore=aS;
}
//function to check home team win or not
bool BallGame::didHomeTeamWin(){
   if(homeScore>awayScore)
       return true;
   else
       return false;
}
int main(){
   //defining BallGame objects
   BallGame g1( "Mystics", "Fire", 100,92);
   BallGame g2( "Capitals", "Lightning", 2,3);
   BallGame g3( "Ravens", "Colts",35,35);
  
   //creating pointers to BallGame objects
   BallGame *game1,*game2,*game3;
   game1=&g1;
   game2=&g2;
   game3=&g3;
  
  
   //verifying home team wins or not
   if(game1->didHomeTeamWin()){
       cout<<"Home team ("<<game1->homeTeam<<") wins game1\n";
   }else{
       cout<<"Home team ("<<game1->homeTeam<<") did not win game1\n";
   }
   if(game2->didHomeTeamWin()){
       cout<<"Home team ("<<game2->homeTeam<<") wins game2\n";
   }else{
       cout<<"Home team ("<<game2->homeTeam<<") did not win game2\n";
   }
  
   if(game3->didHomeTeamWin()){
       cout<<"Home team ("<<game3->homeTeam<<") wins game3\n";
   }else{
       cout<<"Home team ("<<game3->homeTeam<<") did not win game3\n";
   }
   
   return 0;
}

//#############################################################

OUTPUT
###########

Know the answer?
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
Similar Questions
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are...
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are resolved using separate chaining. The hash table will store objects of the class Data. You will decide on the size of the table, keeping in mind that the size of the table must be a prime number. A table of size between 5000-10000, should work well. You must design your hash function so that it produces few collisions. A bad hash function that induces...
For this assignment, you'll create a Player class that captures information about players on a sports...
For this assignment, you'll create a Player class that captures information about players on a sports team. We'll keep it generic for this assignment, but taking what you learn with this assignment, you could create a class tailored to your favorite sport. Then, imagine using such a class to track the stats during a game. Player Class Requirements Your class should bet set up as follows: Named Player Is public to allow access from other object and assemblies Has a...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...
Write the following problem in Java Create a class Dog, add name, breed, age, color as...
Write the following problem in Java Create a class Dog, add name, breed, age, color as the attributes. You need to choose the right types for those attributes. Create a constructor that requires no arguments. In this constructor, initialize name, breed, age, and color as you wish. Define a getter and a setter for each attribute. Define a method toString to return a String type, the returned string should have this information: “Hi, my name is Lucky. I am a...
C++ 5a)We have the following class: class Banana { private:      string s;      int y;...
C++ 5a)We have the following class: class Banana { private:      string s;      int y; public: bool theMemberFunc (string); void setterForS(string); // setter for s string getterForS(); // getter for s }; Instantiate a static object of Banana named co. a)int Banana; b)co.Banana = new; c)Banana = new class; d)Banana co; 5b)Code a call to function aNonclassFunction passing co. a)aNonclassFunction (co); b)aNonclassFunction (* co); c)aNonclassFunction (aGoodClass.co); d)aNonclassFunction (aGoodClass); 5c)Code the function definition for aNonclassFunction, picking up co. aNonclassFunction has...
In Java please 10.9 Lab 6 In BlueJ, create a project called Lab6 Create a class...
In Java please 10.9 Lab 6 In BlueJ, create a project called Lab6 Create a class called LineSegment –Note: test changes as you go Copy the code for LineSegment given below into the class. Take a few minutes to understand what the class does. Besides the mutators and accessors, it has a method called print, that prints the end points of the line segment in the form: (x, y) to (x, y) You will have to write two methods in...
C++ pls finish code! Lab: Singly-Linked List (Student class) Review and finish the following files (read...
C++ pls finish code! Lab: Singly-Linked List (Student class) Review and finish the following files (read code and all comments carefully): Student.h StudentList.h StudentList.cpp main.cpp This program: Creates a sorted linked list (student name and gpa) . The list is sorted in ascending order by name. Displays the list Read and understand this program, then do the following: finish writing Student.h and other files fix errors in StudentList.cpp Student.h: #ifndef STUDENT_H #define STUDENT_H //using namespace std; //<==== This statement //...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with the default values denoted by dataType name : defaultValue - String animal : empty string - int lapsRan : 0 - boolean resting : false - boolean eating : false - double energy : 100.00 For the animal property implement both getter/setter methods. For all other properties implement ONLY a getter method Now implement the following constructors: 1. Constructor 1 – accepts a String...
Create a class hierarchy to be used in a university setting. The classes are as follows:...
Create a class hierarchy to be used in a university setting. The classes are as follows:  The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT