C++ Program
1a. Purpose
Practice the creation and use of a Class
1b. Procedure
Write a class named Car that has the following member variables:
year. An int that holds the car’s model year.
make. A string object 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 member functions.
Constructor. The constructor should accept the car’s year and make as arguments and assign these values to the object’s year and make member variables. The constructor should initialize the speed member variable to 0.
Accessors. Appropriate accessor functions should be created to allow values to be retrieved from an object’s year, 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.
1c. submission
- A cpp fle
- Note: Make sure you have comments for each important statements as documentation
#include <iostream>
#include <string>
using namespace std;
class Car {
private:
string make;
int speed;
int yearModel;
public:
// constructor for Car
Car(int yearModel, string make) {
this->yearModel = yearModel;
this->make = make;
speed = 0;
}
// getter for make
string getMake() {
return make;
}
// getter for speed
int getSpeed() {
return speed;
}
// getter for year
int getYearModel() {
return yearModel;
}
// accelerate car
void accelerate() {
speed += 5;
}
// brake the car
void brake() {
speed -= 5;
}
};
int main() {
// Create a car object.
Car car(2019, "Ferrari");
// Accelerate five times.
int count;
for (count = 0; count < 5; count++) {
// Accelerate and display the speed.
cout << "Accelerating...\n";
car.accelerate();
cout << "Current speed: " << car.getSpeed() << endl;
}
// Brake five times.
for (count = 0; count < 5; count++) {
// Brake and display the speed.
cout << "Braking...\n";
car.brake();
cout << "Current speed: " << car.getSpeed() << endl;
}
cout << "Testing the " << car.getMake() << " made in " << car.getYearModel() << endl;
return 0;
}
C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a...
Second time posting please answer this question!!! Thankyou!! Please do it in visual studio C # and post copy of form.cs and designer.cs. Will give vgood review!!! In this module you learned about Classes and Multiforms. You will be completing one program for this module Write a class named Car that has the following member variables: year - An int that holds the car’s model year. make - A string object that holds the make of the car. speed -...
Car Class Background: Write a class named Car that will be used to store information and control the acceleration and brake of a car. Functionality: 1. Write a class named "Car” that has the following member variables: • year Model - 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 2. In addition the class should have the following member...
python Design a class named Car that has the following fields: yearModel: The yearModel field is an Integer that holds the car’s year model. make: The make field references 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 arguments. These values should be...
Java Program Write a class named Car that has the following fields: yearModel- The yearModel field is an int that holds the car’s year model. make- The make field is a String object that holds the make of the car, such as “Ford”, “Chevrolet”, etc. speed- This speed field is an int that holds the car’s current speed. In addition, the class should have the following methods: Constructor- The constructor should accept the car’s year model and make as arguments....
In Python Programming: Write a class named Car that has the following data attributes: _ _year_model (for the car’s year model) _ _make (for the make of the car) _ _speed (for the car’s current speed) The Car class should have an _ _init_ _ method that accepts the car’s year model and make as arguments. These values should be assigned to the object’s _ _year_model and _ _make data attributes. It should also assign 0 to the _ _speed...
java Write a class named Car that has the following fields: • yearModel: The yearModel field is an int that holds the car's year model. • make: The make field is a String object that holds the make of the car. • speed: The speed field is an int that holds the car's current speed. In addition, the class should have the following methods: • Constructor: The constructor should accept the car's year model and make as arguments. These values...
Car class Question Design a class named car that has the following fields: YearModel: The yearModel field is an integer that holds the car's year model. Make: The make field references 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 arguments. The values...
(C++)This is the problem that I'm supposed to write a
program for:
This is the layout that we are supposed to fill out for the
project:
If anything is unclear, comment and I'll try to
clarify. Thank you!
Objective Reading Dala Files Project This is a variation of ng challenge 133 de Write a class named Car that has the following pelvate member variables. model Year An ie car's uodd year. make A string that bolds the make of the...
Write a program to define a virtual car. Car has these features: number of wheels, max speed, current speed, isMoving, remainingFuel, distanceTravelled. The car can move when the programmer decides to accelerate. With each acceleration current speed increases by 10. Fuel decreases depending on the speed of the car and follows this formula: fuel= fuel-(speed/2). Your program should display “Out of fuel” when there is no remaining fuel. Fuel starts form 100. Use a constructor to initialize the car object....
C++ Programing In this exercise, you will design a class memberType. The class has the following data members: memberName. A string that holds the name of a person memberID. A string that holds the member identification number numBooks. An int that holds the number of books bought purchaseAmt. A double that holds the amount spent on books In addition, the class should have the following constructor and other member functions. Constructor. The constructor should accept the person’s name and member...