C++

[C++] 명품 C++ 프로그래밍 실습문제 6장 2번

Hs’s Coding vlog 2023. 1. 7. 15:42

[C++] 명품 C++ 프로그래밍 실습문제 6장 2번

[C++]명품 C++ programming 실습문제 6장 2번

명품 C++ 프로그래밍실습문제/연습문제 /C++

//2-1
#include <iostream>
#include <string>
using namespace std;
class Person{
    double weight;
    int id;
    string name;
public:
    Person(){
        this->id =1;
        this->name ="grace";
        this->weight = 20.5;
    }
    Person(int id,string name){
        this->id =id;
        this->name =name;
        weight = 20.5;
    }
    Person( int id , string name, double weight ){
        this->id =id;
        this->name =name;
        this->weight = weight;
    }
    void show(){cout << id << ' ' << weight << ' ' <<name <<endl;}
};

int main(int argc, const char * argv[]) {
    Person grace,ashley(2,"Ashley"),helen(3,"Helen",32.5);
    
    grace.show();
    ashley.show();
    helen.show();
    
    return 0;
}

//2-2
#include <iostream>
#include <string>
using namespace std;
class Person{
    double weight;
    int id;
    string name;
public:

    Person( int id=1 , string name= "garce", double weight=20.5 ){
        this->id =id;
        this->name =name;
        this->weight = weight;
    }
    void show(){cout << id << ' ' << weight << ' ' <<name <<endl;}
};

int main(int argc, const char * argv[]) {
    Person grace,ashley(2,"Ashley"),helen(3,"Helen",32.5);
    
    grace.show();
    ashley.show();
    helen.show();
    
    return 0;
}