C++ Program
1. Create 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. Your application 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. (main.cpp, BaseballGame.h,BaseballGame.cpp)
2. Create a class named PhoneCall with four fields: two strings that hold the 10- digit phone numbers that originated and received the call, and two numeric fields that hold the length of the call in minutes and the cost of the call. Include a constructor that sets the phone numbers to Xs and the numeric fields to 0. Include get and set methods for the phone number and call length fields, but do not include a set method for the cost field.When the call length is set, calculate the cost of the call at three cents per minute for the first 10 minutes, and two cents per subsequent minute. Your application declares three PhoneCalls. Set the length of one PhoneCall to 10 minutes, another to 11 minutes, and allow the third object to use the default value supplied by the constructor. Then, display each PhoneCall’s values.(main.cpp,PhoneCall.h,PhoneCall.cpp)
PLEASE ANSWER ALL
#include <iostream>
#include <string>
using namespace std;
//.h file
class BaseballGame{
private:
string team1Name;
string team2Name;
int team1Score;
int team2Score;
public:
BaseballGame();
// mutator
void setTeam1Name(string);
void setTeam2Name(string );
void setTeam1Score(int );
void setTeam2Score(int );
//accessors
string getTeam1Name();
string getTeam2Name();
int getTeam1Score();
int getTeam2Score();
//display
void display();
//find winner
void findWinner(BaseballGame b);
};
//.cpp file
BaseballGame::BaseballGame(){
team1Score=0;
team2Score=0;
}
//mutators
void BaseballGame::setTeam1Name(string t1){team1Name=t1;}
void BaseballGame::setTeam2Name(string t2){team2Name=t2;}
void BaseballGame::setTeam1Score(int s1){team1Score=s1;}
void BaseballGame::setTeam2Score(int s2){team2Score=s2;}
//accessors
string BaseballGame::getTeam1Name(){return team1Name;}
string BaseballGame::getTeam2Name(){return team2Name;}
int BaseballGame::getTeam1Score(){return team1Score;}
int BaseballGame::getTeam2Score(){return team2Score;}
//display
void BaseballGame::display(){
cout<<":::::::::::::::::::::::::::"<<endl;
cout<<"Team 1 Name: "<<team1Name<<endl;
cout<<"Team 1 Final Score:
"<<team1Score<<endl;
cout<<"Team 2 Name: "<<team2Name<<endl;
cout<<"Team 2 Final Score:
"<<team2Score<<endl;
cout<<":::::::::::::::::::::::::::"<<endl;
}
//find max
void BaseballGame::findWinner(BaseballGame b){
if(b.getTeam1Score()<b.getTeam2Score()){
cout<<b.getTeam2Name()<<" WINS"<<" SCORE:
"<<b.getTeam2Score()<<endl;
cout<<b.getTeam1Name()<<" LOST"<<" SCORE:
"<<b.getTeam1Score()<<endl;;
}
else if(b.getTeam1Score()==b.getTeam2Score()){
cout<<"It's a tie between "<<b.getTeam1Name()<<"
& "<<b.getTeam2Name()<<endl;
cout<<"Both scored:
"<<b.getTeam1Score()<<endl;
}
else{
cout<<b.getTeam1Name()<<" WINS"<<" SCORE:
"<<b.getTeam1Score()<<endl;
cout<<b.getTeam2Name()<<" LOST"<<" SCORE:
"<<b.getTeam2Score()<<endl;
}
}
int main()
{ string str1,str2;
int size=12;
cout<<"Enter size: ";
cin>>size; // just inputting to check
int j=1;
BaseballGame *b= new BaseballGame[size];
int score1,score2;
for(int i=0;i<size;i++){
j=1;
cout<<endl<<"Input Game "<<i+1<<"
Information"<<endl;
cout<<"Enter Team "<<j<<" Name: ";
cin.ignore();
getline(cin,str1);
b[i].setTeam1Name(str1);
cout<<"Enter Team "<<j<<" Score: ";
cin>>score1;
b[i].setTeam1Score(score1);
j++;
cout<<endl;
cout<<"Enter Team "<<j<<" Name: ";
cin.ignore();
getline(cin,str2);
b[i].setTeam2Name(str2);
cout<<"Enter Team "<<j<<" Score: ";
cin>>score2;
b[i].setTeam2Score(score2);
cout<<endl;
}
for(int i=0;i<size;i++){
cout<<endl<<"Game "<<i+1<<"
Information"<<endl;
b[i].display(); // display data for all games
}
for(int i=0;i<size;i++){
cout<<" Result of Game "<<i+1<<endl;
b[i].findWinner(b[i]); // find winner of every game
cout<<endl<<endl;
}
return 0;
}
NOTE:
YOU CAN RUN IT WITH ANY SIZE I ONLY CHECKED THE CONDITIONS BY 3 CHECKS
OUTPUT:

QUESTION NO 2:
#include <iostream>
#include <string>
using namespace std;
//.h file
class PhoneCall{
private:
string dailer;
string reciever;
int callLength;
int callCost;
public:
PhoneCall();
PhoneCall(string ,string );
//mutators
void setDailer(string );
void setReciever(string);
void setCallLength(int);
//getters
string getDailer();
string getReciever();
int getCallLength();
int getCallCost();
void display();
};
//.cpp file
PhoneCall::PhoneCall(){
callCost=0;
callLength=0;
}
PhoneCall::PhoneCall(string X,string Y){
dailer=X;
reciever=Y;
callCost=0;
callLength=0;
}
void PhoneCall::setDailer(string X){dailer=X;}
void PhoneCall::setReciever(string Y){reciever=Y;}
void PhoneCall::setCallLength(int l){
callLength=l;
}
string PhoneCall::getDailer(){
return dailer;
}
string PhoneCall::getReciever(){
return reciever;
}
int PhoneCall::getCallLength(){
return callLength;
}
int PhoneCall::getCallCost(){
if (callLength > 10) { // if length is greater than 10
callCost = (10 * 3)+callCost; // for first 10 minutes
callCost = ((callLength - 10)* 2 + callCost); // for the rest of
the minutes
return callCost;
}
else {
callCost = callLength*3; // if length is 10
return callCost;
}
}
void PhoneCall::display(){
cout<<"::::::::::::::::::::: CALL INFORMATION
:::::::::::::::::::::::::::"<<endl;
cout<<"Dialer Number: " <<dailer<<endl;
cout<<"Reciever Number: "<<reciever<<endl;
cout<<"Call Length: "<<callLength<<endl;
cout<<"Call Cost: "<<getCallCost()<<endl;
cout<<"::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"<<endl;
cout<<endl;
}
//main file
int main()
{
string s1;
getline(cin,s1);
while(s1.length()!=10){
cout<<"Length should be 10"<<endl;
getline(cin,s1); //if length is not 10
}
string s2;
getline(cin,s2);
while(s2.length()!=10){
cout<<"Length should be 10"<<endl;
getline(cin,s2); //if length is not 10
}
PhoneCall p1(s1, s2);
p1.setDailer(s1);
p1.setReciever(s2);
p1.setCallLength(10);
getline(cin,s1);
while(s1.length()!=10){
cout<<"Length should be 10"<<endl;
getline(cin,s1); //if length is not 10
}
getline(cin,s2);
while(s2.length()!=10){
cout<<"Length should be 10"<<endl;
getline(cin,s2); //if length is not 10
}
PhoneCall p2(s1,s2);
p2.setDailer(s1);
p2.setReciever(s2);
p2.setCallLength(11);
getline(cin,s1);
while(s1.length()!=10){
cout<<"Length should be 10"<<endl;
getline(cin,s1); //if length is not 10
}
getline(cin,s2);
while(s2.length()!=10){
cout<<"Length should be 10"<<endl;
getline(cin,s2); //if length is not 10
}
PhoneCall p3(s1,s2);
p3.setDailer(s1);
p3.setReciever(s2);
cout<<endl;
p1.display();
cout<<endl;
p2.display();
cout<<endl;
p3.display();
return 0;
}
OUTPUT:

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP
C++ Program 1. Create a class named BaseballGame that has fields for two team names and...
a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name. "XXX", the apartment number to O, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy...
Create a class named BaseballGame that contains data fields for two team names and scores for each team in each of nine innings. names should be an array of two strings and scores should be a two-dimensional array of type int; the first dimension indexes the team (0 or 1) and the second dimension indexes the inning. Create get and set methods for each field. The get and set methods for the scores should require a parameter that indicates which...
Create a class to hold data about a high school sports team. The Team class holds data fields for high school name (such as Roosevelt High), sport (such as Girls’ Basketball), and team name (such as Dolphins). Include a constructor that takes parameters for each field, and include get methods that return the values of the fields. Also include a public final static String named MOTTO and initialize it to Sportsmanship!. Create a class named Game. Include two Team fields...
Create a base class named Book. Data fields include title and author; functions include those that can set and display the fields. Derive two classes from the Book class: Fiction, which also contains a numeric grade reading level, and NonFiction, which contains a variable to hold the number of pages. The functions that set and display data field values for the subclasses should call the appropriate parent class functions to set and display the common fields, and include specific code...
Create a class named BankAccount with data fields for a count number and a balance. Include a constructor that takes arguments for each field. The constructor sets the balance to 0 if it is below the required $200.00 minimum for an account. Include a method that displays the account details, including an explanation if the balance was reduced to 0. Write the class TestAccount in which you instantiate two BankAccount objects, prompt a user for values of the account number...
Create a class Team to hold data about a college sports team. The Team class holds data fields for college name (such as Hampton College), sport (such as Soccer), and team name (such as Tigers). Include a constructor that takes parameters for each field, and get methods that return the values of the fields. Also include a public final static String named MOTTO and initialize it to Sportsmanship! Save the class in Team.java. Create a UML class diagram as well.
Include outputs. Write a C# console application named Tape that includes fields for length and width in inches and properties for each field. Also include a ToString() method that returns a string constructed from the return value of the object's GetType() method and the values of the length and width fields. Derive two subclasses - VideoCassetteTape and AdhesiveTape. The VideoCassetteTape class includes an integer field to hold playing time in minutes - a value from 1 to 180 - and...
In Python - Design a class named Time. The class contains: -Data fields hour, minute, and second that represent a time. -A no-arg constructor that creates a Time object for the current time.(the values of the data fields will respresent the current time.) -A constructor that constructs a Time object with a specified hour, minute, and second, respectively. -A constructor that constructs a Time object with a specified elapsed time since midnight, Jan 1, 1970, in milliseconds. (The values of...
Write a class named PhoneBookEntry that has fields for a person's name and phone number.The class should have a constructor and appropriate accessor and mutator methods. Thenwrite a program that creates at least five PhoneBookEntry objects and stores them in anArrayLitt. Use a loop to display the contents of each object in the ArrayList.
Graded Exercise Create a class named Student. A Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...