// Create a class for a car
#include <iostream>
#include <string>
class Car
{
private:
std::string color;
std::string type;
float weight;
// '*' is a pointer to a float
public:
int nb_wheels;
float *wheels; // one float per wheel
public:
// Constructor
Car(std::string the_type, std::string color, float weight, int nb_wheels = 4)
{
type = the_type;
this->color = color;
this->weight = weight;
this->nb_wheels = nb_wheels;
this->wheels = new float[nb_wheels];
}
Car()
{
this->color = "Red";
this->type = "Sedan";
this->weight = 2000; // lb
}
// Destructor (~)
~Car()
{
delete [] wheels;
}
// create a function
void drive()
{
std::cout << "Driving" << std::endl;
}
void brake()
{
std::cout << "Braking" << std::endl;
}
void internal_lights()
{
std::cout << "Internal lights on" << std::endl;
}
float getWeight() { return weight; }
std::string getType() { return type; }
std::string getColor() { return color; }
void setWeight(float weight) { this->weight = weight; }
void setType(std::string type) { this->type = type; }
void setColor(std::string color) { this->color = color; }
};
int main()
{
std::cout << "Hello, World!" << std::endl;
Car toyota;
Car nissan("Nissan", "blue", 1200.);
std::cout << "Toyota color: " << toyota.getColor() << std::endl;
std::cout << "Nissan type: " << nissan.getType() << std::endl;
std::cout << "Nissan color: " << nissan.getColor() << std::endl;
std::cout << "Nissan weight: " << nissan.getWeight() << std::endl;
nissan.setWeight(5000);
std::cout
<< "Nissan weight: " << nissan.getWeight() << std::endl;
// std::cout << "Toyota weight: " << toyota.weight << std::endl;
toyota.drive();
// toyota.brake();
return 0;
}