어서와 C++는 처음이지!11장_ PROGRAMMING EXERCISE1. Point 클래스를 상속박아서 ThreeDPoint 클래스를 정의해보자. ThreeDPoint 클래스는 3차원 공간 상의 점을 나타내고 int z; 멤버 변수를 추가로 가진다.class Point{int x,y;};...int main(){ThreeDPoint p(10,10,10);p.print();}1-1 위의 프로그램을 컴파일 할 수 있도록 생성자, 접근자, 설정자 등의 함수를 추가하라.[출력 결과][코드]#include #include using namespace std;class Point{ //Point 클래스int x,y;public:Point(int x, int y){this->x = x; this->y = y;} //Point 생성자int getX(){return x;} //접근자int getY(){return y;}};class ThreeDPoint : public Point{ //Point 클래스를 상속받은 ThreeDPoint 클래스int z;public:ThreeDPoint(int x, int y, int z):Point(x,y){ // ThreeDPoint 생성자this->z = z;}void print(){ // 멤버 변수들 출력cout
2. 사용자가 몇 개의 이름을 입력할 것인지를 물은 후에 동적 배열을 생성하여 사용자로부터 받은 이름을 저장하는 프로그램을 작성하라. new를 이용하여 string의 동적 배열을 생성한다. 이 동적 배열에 이름들을 저장한다.<중 략>[코드]#include <iostream>#include <string>using namespace std;class Name{ string name;public : void setName(string name){this->name = name;} string getName(){return name;} };int main(){ int num; string s; cout<<"얼마나 많은 이름을 입력 하시겠습니까? "; cin>>num; Name *n = new Name[num]; for(int i=0; i<num; i++){ cout<<"이름 입력 #"<<i+1<<" : "; cin>>s; n[i].setName(s); } cout<<endl; cout<<"다음은 이름 목록입니다."<<endl; for(int i=0; i<num; i++){ cout<<"이름 #"<<i+1<<":"<<n[i].getName()<<endl; } delete[] n; return 0;}