AP2_(1).cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>
using namespace std;
 
class Person {
    int id;
    double weight;
    string name;
public:
    Person() { id = 1; weight = 20.5; name = "Grace"; }
    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() {
    Person grace, ashley(2"Ashley"), helen(3"Helen"32.5);
    grace.show();
    ashley.show();
    helen.show();
}
cs

AP2_(2).cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;
 
class Person {
    int id;
    double weight;
    string name;
public:
    Person(int id = 1string name = "Grace"double weight = 20.5) { this->id = id; this->name = name; this->weight = weight; }
    void show() { cout << id << ' ' << weight << ' ' << name << endl; }
};
 
int main() {
    Person grace, ashley(2"Ashley"), helen(3"Helen"32.5);
    grace.show();
    ashley.show();
    helen.show();
}
cs


+ Recent posts