Advertisement
koodeta

Car.cpp

Apr 29th, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <string>
  4. #include <iostream>
  5. #include "Car.h"
  6.  
  7. using namespace std;
  8.  
  9. class Car{
  10.  
  11. private:
  12.     // Member variables
  13.     int yearModel;
  14.     string make;
  15.     int speed;
  16.  
  17. public:
  18.     // Mutator method prototypes
  19.     void setYearModel(int);
  20.     void setMake(string);
  21.     void setSpeed(int);
  22.     void accelerate(int);
  23.     void brake(int);
  24.     // Accessor method prototypes
  25.     int getYearModel() const;
  26.     string getMake() const;
  27.     int getSpeed() const;
  28. };
  29.  
  30. // Assigns the model year of the car to yearModel
  31. void Car::setYearModel(int yearModel){
  32.     yearModel = yearModel;
  33. }
  34.  
  35. // Assigns the name of the car to make
  36. void Car::setMake(string make){
  37.     make = make;
  38. }
  39.  
  40. // Assigns the speed value of the car to speed
  41. void Car::setSpeed(int speed){
  42.     speed = speed;
  43. }
  44.  
  45. // Adds 5 to speed
  46. void Car::accelerate(int speed){
  47.     speed += 5;
  48. }
  49.  
  50. // Subtracts 5 from speed
  51. void Car::brake(int speed){
  52.     speed -= 5;
  53. }
  54.  
  55. // Returns the model year
  56. int Car::getYearModel() const{
  57.     return yearModel;
  58. }
  59.  
  60. // Returns the name of the car
  61. string Car::getMake() const{
  62.     return make;
  63. }
  64.  
  65. int Car::getSpeed() const{
  66.     return speed;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement