![joneskc0629](/avatars/22239.jpg)
joneskc0629
22.02.2020 •
Engineering
Write a class named Car that has the following member variables: year : An int tht holds the cars 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 assignments and assign these values to object's year and make member variables. The contructor 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 display it.
Solved
Show answers
More tips
- L Leisure and Entertainment The Best Film of 2010: A Look Back at the Academy Awards...
- H Health and Medicine Simple and Effective: How to Get Rid of Cracked Heels...
- L Leisure and Entertainment What to Bring on a Hike? Essential Items to Pack for a Safe and Enjoyable Adventure...
- L Leisure and Entertainment Couchsurfing: A New Way to Travel...
- S Style and Beauty Autotanning: Harmful or Safe?...
- F Food and Cooking 10 Ideas for a Wedding Anniversary Gift...
- H Health and Medicine How to Reduce Sweating in the Heat and Beyond: Say Goodbye to Excessive Sweat...
- F Food and Cooking Do Aphrodisiacs Really Work? Separating Fact from Fiction...
- H Health and Medicine What to Eat to Lose Weight?...
- A Animals and plants How to Teach Your Parrot to Talk?...
Answers on questions: Engineering
- M Mathematics Atile mosaic in the shape of a right triangle is used as the corner for a rectangular pathway. the hypotenuse of the mosaic is 5ft. one side of the mosaic is twice as long as...
- B Business Allen, who is Beth’s guardian, convinces her to buy a certain parcel of land from Chris at a greatly inflated price. Allen may be liable for . a. puffery b. duress c. fraud...
- H History Compare and contrast the arrival, spread, and influences of christianity and islam in east africa?...
- P Physics Analyze the results of your experiment. Did your data support your hypothesis? Explain. If you conducted tests with more than one type of seed, explain any differences or similarities...
Ответ:
#include <iostream>
#include <cstring>
#include <cctype>
#include <conio.h>
using namespace std;
class Car
{
private:
int YearModel;
int Speed;
string Make;
public:
Car(int, string);
Car();
string getMake();
int getModel();
int getSpeed();
void Accelerate();
void Brake();
};
Car::Car()
{cout<<"Enter car year: ";
cin>>YearModel;
cout<<"Enter car make: ";
cin>>Make;
Speed=0;
}
Car::Car(int YearofModel, string Makeby)
{
YearModel = YearofModel;
Make = Makeby;
Speed = Spd;
}
//To get who makes the car.
string Car::getMake()
{
return Make;
}
//To get the year of the car.
int Car::getModel()
{
return YearModel;
}
//To holds the car actual speed.
int Car::getSpeed()
{
return Speed;
}
//To increase speed by 5.
void Car::Accelerate()
{
Speed = Speed +5;
cout<<"The "<<YearModel<<" "<<Make<<" is accelerating. The speed is now "<<Speed<<" mph."<<endl;
}
//To drop the speed of the car by 5.
void Car::Brake()
{
Speed = Speed -5;
cout<<"The "<<YearModel<<" "<<Make<<" is braking. The speed is now "<<Speed<<" mph."<<endl;
}
int main()
{
int Speed = 0; //Start Cars speed at zero.
int index;
int total=0;
Car mine;
mine.Accelerate();
mine.Brake();
cout<<"Your Caprice's speed is: "<<Speed<<endl;
Car first( 1990, "Chevy", Speed);
total+=Speed;
//Display the menu and get a valid selection
for(index=0;index<6;index++)
{
first.Accelerate();
// here u have to change Speed to //first.getSpeed()
}
for(index=0;index<6;index++)
{
first.Brake();
// here u have to change Speed to //first.getSpeed()
}
_getch();
return 0;
}
Ответ:
Physical or behavioral
Explanation: