Question: Car Class Write a class named Car that has the following member variables: yearModel. An int that holds the car's year model. make. A string
Car Class
Write a class named Car that has the following member variables:
yearModel. An int that holds the car's year model.
make. A string that holds the make of the car.
speed. An int that holds the car's current speed.
In addition, the class should have the following constructor and other member functions.
Constructor. The constructor should accept the car's year model and make as arguments. These values should be assigned to the object's yearModel and make member variables. The constructor should also assign to the speed member variables.
Accessors. Appropriate accessor functions to get the values stored in an objects yearModel, make, and speed member variables.
accelerate. The accelerate function should add to the speed member variable each time it is called.
brake. The brake function should subtract from the speed member variable each time it is called.
Demonstrate the class in a program that creates a Car object, and then calls the accelerate function five times. After each call to the accelerate function, get the current speed of the car and display it Then, call the brake function five times. After each call to the brake function, get the current speed of the car and display it
USE THE NEXT TEMPLATE MANDATORY FOR THE CLASS DEFINITION "Car.h
Carh
DO NOT MODIFY THIS SECTION
#ifndef CARH
#define CARH
#include
class Car
private:
int year;
std::string make;
int speed;
public:
Car int y std::string m ;
int getYear;
ADD YOUR CODE FROM HERE
Output:
Data from this car: Buick
Current speed:
Current speed:
Current speed:
Current speed:
Current speed:
Current speed:
Current speed:
Current speed:
Current speed:
Current speed:
Coin Toss Simulator
Write a class named Coin. The Coin class should have the following member variable:
A string named sideUp. The sideUp member variable will hold either heads or tails indicating the side of the coin that is facing up
The Coin class should have the following member functions:
A default constructor that randomly determines the side of the coin that is facing up heads or tails and initializes the sideUp member variable accordingly.
A void member function named toss that simulates the tossing of the coin. When the toss member function is called, it randomly determines the side of the coin that is facing up heads or tails and sets the sideUp member variable accordingly.
A member function named getSideUp that returns the value of the sideUp member variable.
Write a program that demonstrates the Coin class. The program should create an instance of the class and display the side that is initially facing up Then, use a loop to toss the coin times. Each time the coin is tossed, display the side that is facing up The program should keep count of the number of times heads are facing up and the number of times tails are facing up and display those values after the loop finishes.
USE THE NEXT TEMPLATE MANDATORY FOR THE CLASS DEFINITION "Coin.h
Coinh
DO NOT MODIFY THIS SECTION
#ifndef CLASSNAMEH
#define CLASSNAMEH
#include
class Coin
private:
std::string sideup;
public:
Coinconstructor
toss;
std::string getSideUpaccesor
return sideup;
void toss;
;
#endif CLASSNAMEH
Output:
heads
heads
heads
heads
heads
tails
heads
tails
heads
heads
heads
tails
heads
tails
tails
heads
tails
heads
tails
tails
heads
Heads:
Tails:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
