Untitled
unknown
c_cpp
10 months ago
845 B
6
Indexable
#include <iostream> #include <string> struct PersonNew { std::string name; int age; }; class Person { public: Person() { name = ""; age = 0; } Person( std::string n, int a ) { name = n; age = a; } void setInfo( std::string n, int a ) { name = n; age = a; } void showInfo() { std::cout << "Imie: " << name << "\nAge: " << age << "\n\n"; } private: std::string name; int age; }; int main() { Person person1 = Person(); Person person2 = Person( "Justyna", 18 ); person1.showInfo(); person2.showInfo(); person1.setInfo( "Karol", 19 ); person1.showInfo(); PersonNew person3{ "Jan", 42 }; std::cout << person3.name; return 0; }
Editor is loading...
Leave a Comment