Simple_Class(2)

 avatar
Alexmegawin
c_cpp
2 years ago
1.0 kB
2
Indexable
Never
#include <iostream>
using namespace std;

class child 
{
private:
	string name;
	string surname;
	int age;
public:
	child() {
		cout << "who is he/she?\n";
	}
	child(string name_, string surname_, int age_) {
		set_inf(name_, surname_, age_);
	}

	void set_inf(string name_, string surname_, int age_) {
		name = name_;
		surname = surname_;
		age = age_;
	}

	void get_inf() {
		cout << "He/She is " << name << " " << surname << ". He/She is " << age << "yo.\n";
	}
};

int main(){
	/*string name, surname;
	int age;
	cout << "output:\n";
	child Unknown;
	child Aleksandr_rastorguev_15 = child("Aleksandr", "Rastorguev", 15);
	child Dmiriy_Apasov_15 = child("Dmitriy", "Apasov", 15);
	cout << "Enter your name: ";
	cin >> name;
	cout << "Enter your surname: ";
	cin >> surname;
	cout << "Enter your age: ";
	cin >> age;
	child someone = child(name, surname, age);*/
	child child_info = child("Aleksandr", "Rastorguev", 15);
	child *p = &child_info;
	child_info.get_inf();
	p->get_inf();

	return 0;
}