Lesson 20 — Introduction to Objects (classes) and Constructors

[spoiler title=”Lesson Video”]
Direct Download of Video(For mobile / offline viewing)(right click > save target as)

[/spoiler]

[spoiler title=”Source Code”]

#include 

using namespace std;

//struct 
//class 

class car{
public:
  int windows;
  int wheels;
  double fuelEconomy; //Miles Per Gallon // Litres per Kilo

  void figureMPG(double milesDrivem, double gallonsOfGas){
    fuelEconomy = milesDrivem / gallonsOfGas;
  }
  car::car();
  car::car(int, int);
  car::car(int, int, double, double);

};

car::car(){
  wheels = 4;
  windows = 4;
}

car::car(int wheel, int window){
  wheels = wheel;
  windows = window;
}

car::car(int wheel, int window, double totalMiles, double maxGas){
  wheels = wheel;
  windows = window;
  figureMPG(totalMiles, maxGas);
}

int main(){
  car Sonata(6, 8, 350, 18);

  cout << "The Hyundai Sonata has " << Sonata.wheels << " wheels " << Sonata.windows << " Windows, and gets " << Sonata.fuelEconomy << " mpg" <

[/spoiler]