1008

최민수·2023년 10월 18일
0

struct Man{
//public:
//private:
int age;
double weight;

};
#include
int main()
{
Man han;
han.age = 10;
han.weight = 20.5;
std::cout << han.age << "" << han.weight << std::endl;

}


정리
private
public

노란색 밑줄 - 기본접근 속성이라 생략가능


#include
class Man{
//public:
private:
int age;
double weight;
public:
int getAge() {
return age;
}
void setAge(int a) { //return값이 없으니 void사용
age = a;
}

};
int main()
{
Man han;
han.setAge(5);
//han.age = 10;
//han.weight = 20.5;
std::cout << han.getAge() << std::endl;

}
시험에서 가장 많이 틀림
class 다이어그램



#include
class Man {
//public:
private:
int age;
double weight;
public:
int getAge();
void setAge(int a);//return값이 없으니 void사용}
double getWeight();
void setWeight(double w);
};
int Man::getAge() {
return age;
}
void Man::setAge(int a) { //return값이 없으니 void사용
age = a;
}
double Man::getWeight() {
return weight;
}
void Man::setWeight(double w) {
weight = w;
}
};
int main()
{
Man han;
han.setAge(5);
//han.age = 10;
//han.weight = 20.5;
std::cout << han.getAge() << std::endl;

}
Man에 소속 시킴 Man::



시험 필수 문제 ***

profile
컴퓨터소프트웨어학과

0개의 댓글

관련 채용 정보