Question

In: Computer Science

Complete the following C++ tasks: a. Design a class named BaseballGame that has fields for two...

Complete the following C++ tasks:

a. Design a class named BaseballGame that has fields for two team names and a final score for each team. Include methods to set and get the values for each data field. Create the class diagram and write the pseudocode that defines the class.

b. Design an application that declares three BaseballGame objects and sets and displays their values.

c. Design an application that declares an array of 12 BaseballGame objects. Prompt the user for data for each object, and display all the values. Then pass each object to a method that displays the name of the winning team or "Tie" if the score is a tie.

Solutions

Expert Solution

DO GIVE THUMPS UP....

ANS (a):HERE IS YOUR ANSWER FOR QUESTION 1

CLASS DIAGRAM FOR THE ABOVE PROBLEM IS GIVEN BELOW.

ANS (b) & ANS (C): I HAVE WRITTEN BOTH THE APPLICATION IN ONE CODE .

I TOOK OBJECT OF 4 TEAM INSTEAD OF 12, IF WANT TO CHANGE THE SIZE OF ARRAY, JUST CHANGE IT TO 12 IN FOR LOOP AND OBJECT OF ARRAYS.

CODE :

#include <iostream>
#include<string.h>

using namespace std;
//CLASS NAME
class BaseBallGame{
   //INITIALIZATION OF MEMBERS AND METHODS
   public:
       string teamName;
       int finalScore;
   public:
       //SET AND GETTER METHOD OF TAKING AND PRINTING THE OUTPUT
       void setter(string team, int score){
           teamName = team;
           finalScore = score;
       }
       //GET METHOD
       void getter(){
           cout<<"Team Name: "<<teamName<<endl;
           cout<<"Fina score: "<<finalScore<<endl;
       }
};

int main(){
  
   //declared three BaseballGame objects and sets and displays their values
   BaseBallGame game1;
   BaseBallGame game2;
   BaseBallGame game3;
   cout<<"OUTPUT FOR APPLICATION NO 2"<<endl;
   game1.setter("Los ANgels", 12);
   game1.getter();
   game2.setter("Golden State Warriors", 14);
   game2.getter();
   game3.setter("Bostan Celtics", 22);
   game3.getter();
  
   /*declares an array of 12 BaseballGame objects.
   Prompt the user for data for each object, and display all the values.
   Then pass each object to a method that displays the name of the winning team
   or "Tie" if the score is a tie.*/
   cout<<"================================="<<endl;
   cout<<"OUTPUT FOR APPLICATION NO 3"<<endl;
   cout<<"================================="<<endl;
   string team_name;
   int score;
   /*I TOOK OBJECT OF 4 TEAM INSTEAD OF 12, IF WANT TO CHANGE THE SIZE OF ARRAY, JUST CHANGE IT TO 12 IN FOR LOOP AND OBJECT OF ARRAYS.*/
   BaseBallGame gme[4];
   for(int i=0;i<4;i++){
       cout<<"Enter the name of your team and their score:"<<endl;
       cin>>team_name>>score;
       gme[i].setter(team_name, score);  
   }
  
   cout<<"================================="<<endl;
   cout<<"Teams and their Scores "<<endl;
   for(int i=0;i<4;i++){
       cout<<"Team number "<<i+1<<endl;;
       gme[i].getter();
   }
  
   cout<<"================================="<<endl;
   for(int i=0;i<3;i++){
       for(int j=i+1;j<4;j++){
           if(gme[i].finalScore>gme[j].finalScore){
               cout<<"WINNER TEAM : "<<gme[i].teamName<<" against "<<gme[j].teamName<<endl;
           }
           else if(gme[i].finalScore==gme[j].finalScore){
               cout<<"Match TIE TEAM: "<<gme[i].teamName<<" against "<<gme[j].teamName<<endl;
           }
       }
   }
   return 0;
}

OUTPUT :

OUTPUT FOR APPLICATION NO 2

================================
Team Name: Los ANgels
Fina score: 12
Team Name: Golden State Warriors
Fina score: 14
Team Name: Bostan Celtics
Fina score: 22
=================================
OUTPUT FOR APPLICATION NO 3
=================================
Enter the name of your team and their score:
team1
12
Enter the name of your team and their score:
team2
13
Enter the name of your team and their score:
team3
13
Enter the name of your team and their score:
team4
11
=================================
Teams and their Scores
Team number 1
Team Name: team1
Fina score: 12
Team number 2
Team Name: team2
Fina score: 13
Team number 3
Team Name: team3
Fina score: 13
Team number 4
Team Name: team4
Fina score: 11
=================================
WINNER TEAM : team1 against team4
Match TIE TEAM: team2 against team3
WINNER TEAM : team2 against team4
WINNER TEAM : team3 against team4

--------------------------------

SCREENSHOT OF CODE AND OUTPUT:

IF YOU HAVE ANY PROBLEM REGARDING CODE AND CLASS DIAGRAM, DO COMMENT IN THE COMMENT SECTION, HIT A LIKE.


Related Solutions

Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Create a class named “Car” which has the following fields. The fields correspond to the columns...
Create a class named “Car” which has the following fields. The fields correspond to the columns in the text file except the last one. i. Vehicle_Name : String ii. Engine_Number : String iii. Vehicle_Price : double iv. Profit : double v. Total_Price : double (Total_Price = Vehicle_Price + Vehicle_Price* Profit/100) 2. Write a Java program to read the content of the text file. Each row has the attributes of one Car Object (except Total_Price). 3. After reading the instances of...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields:...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields: position x, position y, and the direction (east, south, west, and north). Assume that positive x points to the east and positive y points to the south, and initially x = 0, y = 0, direction = "east". Create a no-arg constructor and another constructor which sets the three data fields. Create the accessors and mutators for the three data fields. Create a method...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields:...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields: position x, position y, and the direction (east, south, west, and north). Assume that positive x points to the east and positive y points to the south, and initially x = 0, y = 0, direction = "east". Create a no-arg constructor and another constructor which sets the three data fields. Create the accessors and mutators for the three data fields. Create a method...
Design a class named Robot. The Robot class has three private data fields: position x, position...
Design a class named Robot. The Robot class has three private data fields: position x, position y, and the direction (east, south, west, and north). Assume that positive x points to the east and positive y points to the south, and initially x = 0, y = 0, direction = "east". Create a no-arg constructor and another constructor which sets the three data fields. Create the accessors and mutators for the three data fields. Create a method named forward that...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields:...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields: position x, position y, and the direction (east, south, west, and north). Assume that positive x points to the east and positive y points to the south, and initially x = 0, y = 0, direction = "east". Create a no-arg constructor and another constructor which sets the three data fields. Create the accessors and mutators for the three data fields. Create a method...
Design a class named Pet, which should have the following fields: Name – The name field...
Design a class named Pet, which should have the following fields: Name – The name field holds the name of a pet. Type – The type field holds the type of animal that is the pet. Example values are “Dog”, “Cat”, and “Bird”. Age – The age field holds the pet’s age. The Pet class should also have the following methods: setName – The setName method stores a value in the name field. setType – The setType method stores a...
Write a java program using the following information Design a LandTract class that has two fields...
Write a java program using the following information Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:  a constructor that accepts arguments for the two fields  a method that returns the tract’s area(i.e. length * width)  an equals method that accepts a LandTract object as an argument. If the argument object holds the same data (i.e. length and...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and...
c++ E2b: Design a class named Rectangle to represent a rectangle. The class contains:
using c++E2b: Design a class named Rectangle to represent a rectangle. The class contains:(1) Two double data members named width and height which specifies the width and height of the rectangle .(2) A no-arg constructor that creates a rectangle with width 1 and height 1.(3) A constructor that creates a rectangle with the specified width and height .(4) A function named getArea() that returns the area of this rectangle .(5) A function named getPerimeter() that returns the perimeter of this...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT