Skip to content
Permalink
Browse files
fixed indentation and solutions password
  • Loading branch information
David committed Jan 31, 2019
1 parent 04b968a commit 45ab308ea98721141df4c31c4d060575c47d3139
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
@@ -5,20 +5,20 @@ using namespace std;

int main()
{
Car carA( "Peugeot", "306" );
Car carB( "Porsche", "911" );
Car carC( "Bugatti", "Vayron" );
Car carA( "Peugeot", "306" );
Car carB( "Porsche", "911" );
Car carC( "Bugatti", "Vayron" );

// getting the attribute of a specific instance
cout << "carA: " << carA.make << endl; // Peugeot
cout << "carC: " << carC.make << endl; // Bugatti
// getting the attribute of a specific instance
cout << "carA: " << carA.make << endl; // Peugeot
cout << "carC: " << carC.make << endl; // Bugatti

// calling a non-static member function
carB.sell( 20000 );
// calling a non-static member function
carB.sell( 20000 );

// calling a static member function, either works
cout << "Stock1: " << carA.getStockCount() << endl; // 2
cout << "Stock2: " << Car::getStockCount() << endl; // 2
// calling a static member function, either works
cout << "Stock1: " << carA.getStockCount() << endl; // 2
cout << "Stock2: " << Car::getStockCount() << endl; // 2

return 0;
return 0;
}
@@ -4,24 +4,24 @@ using namespace std;
class Car
{
public:
static int inStock; // class attribute
string make, model; // object attributes
int salePrice;
static int inStock; // class attribute
string make, model; // object attributes
int salePrice;

Car( string _make, string _model ) // constructor method
{ make = _make;
model = _model;
salePrice = 0;
inStock = inStock + 1;
}
Car( string _make, string _model ) // constructor method
{ make = _make;
model = _model;
salePrice = 0;
inStock = inStock + 1;
}

void sell( int price ) // object method
{ salePrice = price;
inStock = inStock - 1;
}
void sell( int price ) // object method
{ salePrice = price;
inStock = inStock - 1;
}

static int getStockCount() // class method
{ return inStock;
}
static int getStockCount() // class method
{ return inStock;
}
};
int Car::inStock = 0; // static variable initialisation.
BIN +0 Bytes (100%) Solutions/solutions.zip
Binary file not shown.

0 comments on commit 45ab308

Please sign in to comment.