3 Projects Solution

Car Class
Write a class named Car that has the following member variables:
yearModel. An int that holds the cars year model.
make. A string that holds the make of the car.
Speed.An int that holds the cars current speed.
In addition, the class should have the following constructor and other member functions:
Constructor. The constructor should accept the cars year model and make as arguments. Thesew values should be assigned to the object’s yearModel and make member variables.
Accessor. Appropriate accessor functions to get the values stored in an object’s 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 brake function five times. After each call to the brake function, get the current speed of the car and display it.

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 thetoss 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 kepp count of the number of times heads is facing up, and display those when the loop is finished.

Trivia Game
In this programming challenge you will create a simple trivia game for two players. The program will work like this:
Starting with player 1, each player gets a turn answering five trivia questions.(There should be a total of 10 trivia questions) When a question is displayed, four possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer he or she earns a point.
After answers have been selected for all of the questions, the program displays the number of points earned by each player and declares the player with the highest number of points as the winner.
In this trivia game you will design a Question class to hold the data for a trivia question.
The question class should have member variables for the following data:
A trivia question
Possible answer #1
Possible answer #2
Possible answer #3
Possible answer #4
The number of the correct answer (1,2,3, or4)
The question class should have appropriate constructor(s), accessor, and mutator functions.
The program should create an array of 10 Question objects, one for each trivia question. Make up your own trivia questions on the subject or subjects of your choice for the objects.


Powered by