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

In java, design a class named Motorcycle that has the following fields: • year – The...
In java, design a class named Motorcycle that has the following fields: • year – The year field is an int that holds the motorcycle’s year • make – The make field references a String object that holds the make of the motorcycle. • speed – The speed field is an int that holds the motorcycle’s current speed The class should have the following constructor and other methods: • Constructor – the constructor should accept the motorcycle’s year and make...
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...
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...
Problem Statement Design a class named Car that has the following fields: year: The year field...
Problem Statement Design a class named Car that has the following fields: year: The year field is an integer that holds the car’s year. make: the make field is a String that holds the make of the car. speed: the speed field is an integer that holds the car’s current speed. In addition, the class should have the following constructor and other methods: Constructor: the constructor should accept the car’s year >model and make as parameters. These values should be...
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...
In java, (include javadoc comments for each method) design a class named Contacts that has fields...
In java, (include javadoc comments for each method) design a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contacts objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT