car.h

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
using namespace std;
 
class Car
{
    int speed;
    int gear;
    string color;
public:
    int getSpeed();
    void setSpeed(int s);
};
cs


car.cpp

1
2
3
4
5
6
7
8
9
10
#include "car.h"
 
int Car::getSpeed()
{
    return speed;
}
void Car::setSpeed(int s)
{
    speed = s;
}
cs

 

 

 

main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "car.h"
using namespace std;
 
int main()
{
    Car myCar;
 
    myCar.setSpeed(80);
    cout << "현재 속도는 " << myCar.getSpeed() << endl;
 
    return 0;
}
 
 
cs

 

 

 

 

 

'⭐ Programming > C++' 카테고리의 다른 글

Pseudo code : Bull Cow Cartridge  (0) 2022.03.10
Pre-Increment/Decrement, Post-Increment/Decrement  (0) 2022.03.10
Visual Studio Code 단축키  (0) 2022.03.10
Ch 4.7 CircleRun  (0) 2022.03.09
Ch 3 Hangman  (0) 2022.03.09