The class definition for an Automobile class the (curr auto (type) (character ar
ID: 3841255 • Letter: T
Question
The class definition for an Automobile class the (curr auto (type) (character array of 20 elements), current speed the following maximum speed max th are inte It also have public member functions: e This function is the default constructor. The maximum speed is 80 start 0 This function prints the message "Automobile is started. stop0 This function prints the message "Automobile is stopped. and assigns the value 0 to current speed. accelerate0: This function is passed an integer s mph. It then tests (curr speed mph). If this value is greater than max speed, it prints "This automobile cannot go that fast." otherwise, it adds mph to curr speed, and assigns it to curr speed. Then it prints "Accelerating to" value of current speed (i.e., curr speed) "mph decelerate(): This function is passed an integer speed mph. It then tests curr speed mph). If this value is less than 0, it prints "Cannot decelerate to less than 0." Otherwise, it subtracts mph from curr speed, and assigns it to curr speed. Then it prints Decelerating to" value of current speed (ie., curr speed) "mph." steer0 This function prints the message "Steering car. left blink0: This function prints: "Left blinker is on right blink0: This function p "Right blinker is on turn righto: This function prints: "Making right turn. This function prints: "Making left turn. turn lefto: type(0: This function returns the auto type. get curspeed0: This function returns the current speed get maxspeed(0: This function returns t speed set allo This function is passed a type, curr speed, and max speed and assigns these arguments to the private data members of the class a. Write the class definition for the Automobile in the file auto.h b. Write the method definitions for the Automobile class in the file auto.cpp write a program (the driver to do the following e create an object of the Automobile class. Use it to invoke each method at least once. For example, first create the object my car. start my car. Accelerate by 10 mph, then again by 30mph. Steer the car. Put the left blinker on. Decelerate by 10 mph, make a left turn. Accelerate by 10mph steer the car. Accelerate by 30 mph, and then steer the car. Accelerate by 30 mph, then again by 10 mph. and then steer the car. Put the right blinker onExplanation / Answer
auto.h
Class automobile
{
private:
auto type[20]
int curr_speed;
int max_speed;
public:
automobile();
void start();
void stop();
void accelerate (int speed);
void decelerate (int speed);
void steer();
void left_blink();
void right_blink();
void turn_right();
void turn_left();
char * get_type();
int get_carspeed();
int get_maxspeed();
void set_all(char *type, int Cspeed , int Mspeed);
};
Auto.cpp
#include "auto.h"
#include<iostream.h>
using namespace std;
automobile::automobile()
{
max_speed=80;
curr_speed=0;
type = "";
}
void automobile::start()
{
cout<<"automobile is started"<<endl;
}
void automobile::stop()
{
cout<<"automobile is stopped"<<endl;
}
void automobile:: accerelerate(int speed)
{
if(speed + cur_speed>max_speed)
{
cout<<"this automobile cant go that fast";
}
else
{
this.curr_speed=speed+this.curr_speed;
cout<<"decelarating to value of current speed"<<curr.speed<<endl;
}
}
Void automobile::declarate(int speed)
{
if(curr_speed_mph<0)
{
cout<<"cant declarate less than zero"<<endl;
}
else
{
curr_speed=curr_speed-speed;
cout<<"declaring to"<<curr_speed<<;
}
}
void automobile::steer()
{
cout<<"steering car"<<end;
}
void automobile::left_blink()
{
cout<<"left_blink is on"<<end;
}
void automobile::right_blink()
{
cout<<"right_blink is on"<<end;
}
void automobile::turn_right()
{
cout<<"turn_right is on"<<end;
}
void automobile::turn_left()
{
cout<<"turn_left is on"<<end;
}
void automobile::get_type()
{
return *this.type;
}
void automobile::get currspeed()
{
return *this.currspeed;
}
void automobile::get maxspeed()
{
return *this.maxspeed;
}
void automobile::set_all(char *type, int cspeed, int mspeed)
{
this.type=type;
this.curr_speed=cspeed;
this.max_speed=mspeed;
}
int main()
{
automobile my_car;
my_car.start();
my_car.accelerate(10);
my_car.accelerate(30);
my_car.steer();
my_car.decelerate(10);
my_car.left_turn();
my_car.stop();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.