Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
845 B
3
Indexable
Never
#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;
}
Leave a Comment