728x90
#include <iostream>
using namespace std;

class Car {

public:

	bool poweron;
	string colour;
	int wheel;
	int speed;
	bool wiperon;

	//생성자 호출 함수(객체가 만들어질때 초기화 시키는 함수)
	//반드시 클래스명과 같아야함

	Car() {
		poweron = true;
		colour = "red";
		wheel = 4;
		speed = 100;
		wiperon = false;
	}

	Car(bool po, string col, int whe, int spe, bool wip) {
		poweron = po;
		colour = col;
		wheel = whe;
		speed = spe;
		wiperon = wip;
	}


	void power() {
		poweron = !poweron;
	}

	void speedup() {
		speed++;
	}

	void speeddown() {
		speed--;
	}

	void wiper() {
		wiperon = !wiperon;
	}

};

int main() {
	Car mycar;

	mycar.poweron = true;
	mycar.colour = "red";
	mycar.wheel = 4;
	mycar.speed = 100;
	mycar.wiperon = true;

	cout << "mycar's status: " << mycar.poweron << endl;
	cout << "mycar's colour: " << mycar.colour << endl;
	cout << "mycar's wheel: " << mycar.wheel << endl;
	cout << "speed: " << mycar.speed << endl;
	cout << "wiper: " << mycar.wiperon << endl;
	cout << "-------------------------" << endl;

	Car mycar1;

	cout << "mycar1's status: " << mycar1.poweron << endl;
	cout << "mycar1's colour: " << mycar1.colour << endl;
	cout << "mycar1's wheel: " << mycar1.wheel << endl;
	cout << "mycar1's speed: " << mycar1.speed << endl;
	cout << "mycar1's wiper: " << mycar1.wiperon << endl;
	cout << "-------------------------" << endl;

	Car mycar2(true, "blue", 4, 200, false);
	cout << "mycar2's status: " << mycar2.poweron << endl;
	cout << "mycar2's colour: " << mycar2.colour << endl;
	cout << "mycar2's wheel: " << mycar2.wheel << endl;
	cout << "mycar2's speed: " << mycar2.speed << endl;
	cout << "mycar2's wiper: " << mycar2.wiperon << endl;
	cout << "-------------------------" << endl;

}
728x90

'언어는 과-학인가요? > C++' 카테고리의 다른 글

Foodgame c++  (0) 2020.11.14
orangebox  (0) 2020.11.14
Protected, Private, Public 함수 : 이동시키기  (0) 2020.10.31
상속  (0) 2020.10.31
생성자와 소멸자 (constructor and destructor)  (0) 2020.10.24

+ Recent posts