Skip to content
Snippets Groups Projects
Commit e91858fa authored by Rudi Buss's avatar Rudi Buss
Browse files

Update Solution Exercise 2 - Car.cpp

parent 8a978688
No related branches found
No related tags found
No related merge requests found
#include<iostream>
#include <iostream>
using namespace std;
class Car
{
private:
string brand;
int mileage;
static int number_rides;
public:
Car(string b, int m) : brand(b), mileage(m) { }
~Car()
{
cout << endl << "Object has been deleted. " << endl;
}
void drive(int driven) //Declaration and Definition of the function query_data
{
mileage += driven;
number_rides ++;
}
void show_data()
{
cout << brand << ", actual mileage: " << mileage << endl;
cout << "Number of rides: " << number_rides << endl;
}
class Car {
private:
string brand;
int mileage;
static int number_rides;
public:
Car(string b, int m) : brand(b), mileage(m) {}
~Car() { cout << endl << "Object has been deleted. " << endl; }
void drive(int driven) // Declaration and Definition of the function query_data
{
mileage += driven;
number_rides++;
}
void show_data() {
cout << brand << ", actual mileage: " << mileage << endl;
cout << "Number of rides: " << number_rides << endl;
}
};
int Car:: number_rides = 0;
int main()
{
Car bmw("BMW",1500);
bmw.drive(70);
bmw.show_data();
bmw.drive(80);
bmw.show_data();
bmw.drive(250);
bmw.show_data();
cout << endl << endl;
return 0;
}
int Car::number_rides = 0;
int main() {
Car bmw("BMW", 1500);
bmw.drive(70);
bmw.show_data();
bmw.drive(80);
bmw.show_data();
bmw.drive(250);
bmw.show_data();
cout << endl << endl;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment