C++mid102_1

 avatar
user_3763047219
c_cpp
a year ago
534 B
0
Indexable
Never
#include <iostream>
#include <string>
using namespace std;

class Person{
public:
    Person(){}//5
    Person(string n, int a);
    void Print() const;
private:
    const string name; //6
    int age;
};//2;

//3 ::
//4 void
Person::Person(string n, int a):name(n){//6 name
    age = a;
}

void Person::Print()const {
    cout<<name<<"is"<<age<<"years old."<<endl;
}

int main(){
    Person p1("John",15);
    const Person p2("Mary",13);
    Person p3;
    p1.Print();
    p2.Print();
    p3.Print();
}