Class StringAnalyzer 를 프로그래밍 하시오.
class constructor는 인수로 string을 받아들이며,
class method인 int getStrLength( )는 string의 길이를 반환하고,
class method인 char getCharAt(int idx)는 string의 idx 위치에 있는 문자를 반환한다.
만약, idx가 유효한 범위를 넘어갈 경우에는 무조건 대문자 'A'를 반환해야 한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <iostream> #include <string> using namespace std; //------------------------------------ // 이 곳에 Class StringAnalyzer를 정의하시오. //------------------------------------ int main() { string str; int k; getline(cin, str); cin >> k; StringAnalyzer sa(str); cout << sa.getStrLength() << endl; cout << sa.getCharAt(k); return 0; } |