物件102-1
user_6817964
c_cpp
3 years ago
506 B
6
Indexable
#include <iostream>
#include <string>
using namespace std;
class Person{
public:
Person(string n, int a);
Person(){}
void Print() const;
private:
const string name;
int age;
};
Person::Person(string n, int a):name(n){
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();
}
Editor is loading...