#include <string>
#include <vector>
using namespace std;
string solution(string phone_number) {
string answer = phone_number;
for (int i = 0; i < answer.size() - 4; i++) {
answer[i] = '*';
}
return answer;
}
코드카타 전화번호 가리기코드
class의 정의
class Student
{
//동작 정의(이를 멤버함수라고 합니다)
double getAvg();
int getMaxNum();
//데이터 정의(이를 멤버변수라고 합니다.)
int kor[3];
int eng[3];
int math[3];
};
멤버함수 구현(클래스 내부)
#include <iostream>
#include <algorithm> //max 함수 사용
#include <string>
using namespace std;
class Student
{
//동작 정의(이를 멤버함수라고 합니다)
double getAvg()
{
return (kor + eng + math ) / 3.0;
}
int getMax()
{
return max(max(kor, eng), math);
}
//데이터 정의(이를 멤버변수라고 합니다.)
int kor;
int eng;
int math;
};
멤버함수 구현(클래스 내부)
#include <iostream>
#include <algorithm> //max 함수 사용
#include <string>
using namespace std;
class Student
{
//동작 정의(이를 멤버함수라고 합니다)
double getAvg();
int getMaxNum();
//데이터 정의(이를 멤버변수라고 합니다.)
int kor;
int eng;
int math;
};
double Student::getAvg()
{
return (kor + eng + math) / 3.0;
}
int Student::getMaxNum()
{
return max(max(kor, eng), math);
// 다른 방법 return max({ kor, eng, math });
}
접근제어
private에 접근제어
#include <iostream>
#include <algorithm> //max 함수 사용
#include <string>
using namespace std;
class Student
{
//동작 정의(이를 멤버함수라고 합니다)
double getAvg();
int getMaxScore();
//데이터 정의(이를 멤버변수라고 합니다.)
int kor;
int eng;
int math;
};
double Student::getAvg()
{
return (kor + eng + math) / 3.0;
}
int Student::getMaxScore()
{
return max(max(kor, eng), math);
}
int main()
{
Student s;
s.getAvg();
return 0;
}
public,private으로 접근제어
#include <iostream>
#include <algorithm> //max 함수 사용
#include <string>
using namespace std;
class Student
{
public:
//동작 정의(이를 멤버함수라고 합니다)
double getAvg();
int getMaxScore();
private:
//데이터 정의(이를 멤버변수라고 합니다.)
int kor;
int eng;
int math;
};
double Student::getAvg()
{
return (kor + eng + math) / 3.0;
}
int Student::getMaxScore()
{
return max(max(kor, eng), math);
}
int main()
{
Student s;
s.getAvg();
return 0;
}
클래스의 멤버 함수나 멤버 변수에 접근할 때는 객체 뒤에 멤버 접근 연산자 .을 사용합니다.
또한, 클래스는 접근 지정자를 사용하여 멤버의 접근 권한을 제어할 수 있습니다.
getter와 setter를 적용한 clss
#include <iostream>
#include <algorithm> //max 함수 사용
#include <string>
using namespace std;
class Student
{
public:
//동작 정의(이를 멤버함수라고 합니다)
double getAvg();
int getMaxScore();
void setMathScore(int math)
{
this->math = math;
}
void setEngScore(int eng)
{
this->eng = eng;
}
void setKorScore(int kor)
{
this->kor = kor;
}
int getMathScore() { return math; }
int getEngScore() { return eng; }
int getKorScore() { return kor; }
private:
//데이터 정의(이를 멤버변수라고 합니다.)
int kor;
int eng;
int math;
};
double Student::getAvg()
{
return (kor + eng + math) / 3.0;
}
int Student::getMaxScore()
{
return max(max(kor, eng), math);
}
int main()
{
Student s;
s.setEngScore(32);
s.setKorScore(52);
s.setMathScore(74);
//평균 최대점수 출력
cout << s.getAvg() << endl;
cout << s.getMaxScore() << endl;
return 0;
}
그후 과제2가 끝난 팀원들과 팀프로젝트 기획과 실습을 하였습니다
'본캠프' 카테고리의 다른 글
| 5/18 (코드카타, 팀프로젝트, 강의) (0) | 2026.05.11 |
|---|---|
| 5/7 (코드카타) (0) | 2026.05.07 |
| 텍스트던전rpg 분석 (0) | 2026.05.06 |
| 5/6 (개인프로젝트,과제2도전step8) (0) | 2026.05.06 |
| 4/30(코드카타) (0) | 2026.04.30 |