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 0 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 5 to the speed member variable each time it is called.
brake. The brake function should subtract 5 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"
//Car.h
//DO NOT MODIFY THIS SECTION
#ifndef CAR_H
#define CAR_H
#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: 1965, Buick
Current speed: 5
Current speed: 10
Current speed: 15
Current speed: 20
Current speed: 25
Current speed: 20
Current speed: 15
Current speed: 10
Current speed: 5
Current speed: 0
5] 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 20 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"
//Coin.h
//DO NOT MODIFY THIS SECTION
#ifndef CLASSNAME_H
#define CLASSNAME_H
#include
class Coin{
private:
std::string sideup;
public:
Coin()//constructor
{ toss(); }
std::string getSideUp()//accesor
{ return sideup; }
void toss();
};
#endif // CLASSNAME_H
Output:
heads
heads
heads
heads
heads
tails
heads
tails
heads
heads
heads
tails
heads
tails
tails
heads
tails
heads
tails
tails
heads
Heads: 12
Tails: 8

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!