U E D R , A S I H C RSS

새싹교실/2012/AClass/2-6회차

No difference found



  • Person 기본 코드



#include <iostream>

using namespace std;

class Person{
private:
	int walkingDistance;
	int speed;
public:
	Person();
	Person(int parameter);
	int walk();
	int powerWalk(int speed);
	void print();
};

int main()
{
	Person A;
	Person B=Person(10);
	
	int i;
	for(i=0;i<10;i++){
		A.powerWalk(3);
		A.walk();
		B.walk();
	}
	A.print();
	B.print();
	return 0;
}

Person::Person() //default 생성자.
{
	walkingDistance=100;
	speed=1;
}
Person::Person(int parameter)
{
	walkingDistance=parameter;
	speed=1;
}

int Person::walk()
{
	walkingDistance += speed*10;
	return 0;
}
int Person::powerWalk(int speed)
{
	walkingDistance+=speed*10;
	
	return 0;
}

void Person::print()
{
	cout<<walkingDistance<<endl;
}


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:44
Processing time 0.0309 sec