Question

Show the compilation of Programming Challenge below in separate header and implementation files and show a...

Show the compilation of Programming Challenge below in separate header and implementation files and show a UML diagram of this class.

#include “Car.h”

Int main()

{

Car car(2015, “Volkswagon”);

Cout<<”Car’s Make: “ << car.getMake() <<endl;

Cout<< “Car’s Year:” << car.getYear() <<endl;

Cout<< “Car’s Speed : “ <<car.getSpeed()<<endl;

Cout<< endl;

For(int I =0; I < 5; i++)

{

Car.acceleration();

Cout<< “Speed after accelerate: “ << car.getSpeed() << endl;

}

For(int I = 0; i < 5; i++)

{

Car.brake();

Cout << “Speed after brake: “ << car.getSpeed() << endl;

}

Cout << endl;

Return 0;

}

Class Car

Using namespace std;

{

Private:

Int year;

String make;

Int speed;

Public:

Car(int aYear, string aMake);

Int getYear();

String getMake();

Int getSpeed();

Void accelerate();

Void brake();

};

Car::Car(int aYear, string aMake)

{

Year = aYear;

Make = aMake;

Speed =0;

}

Int Car::getYear()

{

Return year;

}

String Car::getMake()

{

Return make;

}

Int car::getSpeed()

{

Return speed;

}

Void Car:: accelerate()

{

Speed = speed + 5;

}

Void Car::brake()

{

If(speed>5)

Speed = speed -5;

Else

Speed = 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include "Car.h"
using namespace std;

int main()
{
Car car(2015, "Volkswagon");

cout<<"Car's Make: " << car.getMake() <<endl;

cout<< "Car's Year:" << car.getYear() <<endl;

cout<< "Car's Speed : " <<car.getSpeed()<<endl;

cout<< endl;

for(int i =0; i < 5; i++)
{
car.accelerate();
cout<< "Speed after accelerate: " << car.getSpeed() << endl;
}

for(int i = 0; i < 5; i++)
{
car.brake();
cout << "Speed after brake: " << car.getSpeed() << endl;
}
cout << endl;
return 0;

}

File Edit Selection Find View Goto Tools Project Preferences Help main.cpp 1 2 3 #include <iostream» #include Carh using n

#ifndef CAR_H
#define CAR_H
#include<iostream>
using namespace std;

class Car
{
private:
int year;
string make;
int speed;
public:
Car(int aYear, string aMake);
int getYear();
string getMake();
int getSpeed();
void accelerate();
void brake();
};

#endif // CAR_H

File Edit Selection Find View Goto Tools Project Preferences Help Car.h #ifndef CAR H 2 #define CARH 3 #include< iostream> 4

#include "Car.h"

Car::Car(int aYear, string aMake)
{
year = aYear;
make = aMake;
speed =0;
}
int Car::getYear()
{
return year;
}
string Car::getMake()
{
return make;
}
int Car::getSpeed()
{
return speed;
}

void Car:: accelerate()
{
speed = speed + 5;
}

void Car::brake()
{
if(speed>5)
speed = speed -5;
else
speed = 0;
}

File Edit Selection Find View Goto Tools Project Preferences Help Carh Carcpp 1 #include Car h 3 Car::Car(int aYear, strinOutput:

Cars Make: Volkswagon Cars Year 2015 Cars Speede Speed after accelerate: 5 Speed after accelerate: 10 Speed after accelera

UML

Car year: int make: string speed: int Carlyear: int, make:string) +getYear0:int +getMake0:string +getSpeed): int + accelerate

.

Please give this solution a thumbs up if you find it helpful and comment if you have any doubts in it.

Add a comment
Know the answer?
Add Answer to:
Show the compilation of Programming Challenge below in separate header and implementation files and show a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Codes: (car.h ; car.cpp ; carDemo.cpp) /* ----------------------- Car ----------------------- - make: string - year :...

    Codes: (car.h ; car.cpp ; carDemo.cpp) /* ----------------------- Car ----------------------- - make: string - year : int ----------------------- + Car() + setMake(m: string) : void + getMake() : string + setYear(y: int) : void + getYear() : int ---------------------- */ #ifndef CAR_H #define CAR_H #include <iostream> using namespace std; class Car { private: string make; int year; public: Car(); Car(string); Car(int); Car(string, int); void setMake (string); string getMake() {return make;} void setYear (int); int getYear() {return year;} }; #endif #include...

  • Can someone help me with my Java code error! Domain package challenge5race; import java.util.Random; public class...

    Can someone help me with my Java code error! Domain package challenge5race; import java.util.Random; public class Car {    private int year; private String model; private String make; int speed; public Car(int year, String model, String make, int speed) { this.year = year; this.model = model; this.make = make; this.speed = speed; } public Car() { } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String getModel() { return model; }...

  • Language = C++ How to complete this code? C++ Objects, Structs and Linked Lists. Program Design:...

    Language = C++ How to complete this code? C++ Objects, Structs and Linked Lists. Program Design: You will create a class and then use the provided test program to make sure it works. This means that your class and methods must match the names used in the test program. Also, you need to break your class implementation into multiple files. You should have a car.h that defines the car class, a list.h, and a list.cpp. The link is a struct...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

  • In Python Programming: Write a class named Car that has the following data attributes: _ _year_model...

    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...

  • C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a...

    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...

  • Please provide a multi lined pseudo code for the program below.....also it is giving me a...

    Please provide a multi lined pseudo code for the program below.....also it is giving me a build error? Could you possibly tell me how to fix the error too? #include <iostream> #include <string> using namespace std; class ship { public: string name; int year; ship(string n, int y) { name = n; year = y; } int getYear() { return year; } string getName() { return name; } void setYear(int y) { year = y; } void setName(string n) {...

  • //Vehicle.h #pragma once #include<iostream> #include"Warranty.h" #include<string> using namespace std; class Vehicle{ protected:    string make; int year;   ...

    //Vehicle.h #pragma once #include<iostream> #include"Warranty.h" #include<string> using namespace std; class Vehicle{ protected:    string make; int year;    double mpg;    Warranty warranty;    static int numOfVehicles; public:    Vehicle();    Vehicle(string s, int y, double m, Warranty warranty);    Vehicle(Vehicle& v);    ~Vehicle();    string getMake();    int getYear();    double getGasMileage();    void setMake(string s);    void setYear(int y);    void setYear(string y);    void setGasMileage(double m);    void setGasMileage(string m);    void displayVehicle();    static int getNumVehicles();    Warranty getWarranty();    void setWarranty(Warranty& ); }; //Vehicle.cpp #include "Vehicle.h" #include <string> Vehicle::Vehicle() {    make = "unknown";    year =...

  • This is assignment and code from this site but it will not compile....can you help? home...

    This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...

  • ​c++ program that takes user input from the console and store the data into a linked list.

    c++ program that takes user input from the console and store the data into a linked list. The input made of 4 objects associated to a car: model, make, mileage and year. My program should take the how many inputs the user want to make, followed by the inputs themselves. After the input, my program should print the data inside the linked list. So far, the issue is that my program print some of the input, but not all. Input sample:3HondaSentra89002017ToyotaCamri1098271999NissanSentra87261987current...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT