Facebook
From Bsbs, 1 Month ago, written in Plain Text.
This paste is a reply to Jeehhe from Hwhh - go back
Embed
Viewing differences between Jeehhe and Re: Jeehhe
https://dysk.agh.edu.pl/s/GXJYcRjWbc6qJD7?dir=undefined&path;=/&fbclid=IwAR0KI4d00slOteSeiASHflHoOGZZTV-L0QjrwJ5-2uUBvA8CG8qPOTjEXAA&openfile=8971117#include 
#include 

using namespace std;

class Person
{
private:
    string imie;
    string nazwisko;
    string pesel;

public:
    // Konstruktor parametryczny z domyślnymi wartościami
    Person(string imie = "", string nazwisko = "", string pesel = "")
        : imie(imie), nazwisko(nazwisko), pesel(pesel) {}

    string get_imie() const {
        return imie;
    }

    string get_nazwisko() const {
        return nazwisko;
    }

    string get_pesel() const {
        return pesel;
    }

    string to_string() const {
        return "Osoba: " + imie + " " + nazwisko + ", Pesel: " + pesel;
    }
};

class Student : public Person
{
private:
    string nr_indeksu;
    string kierunek_studiow;

public:
    // Konstruktor parametryczny dla klasy Student, wywołujący konstruktor klasy bazowej Person
    Student(string imie, string nazwisko, string pesel, string nr_indeksu, string kierunek_studiow)
        : Person(imie, nazwisko, pesel), nr_indeksu(nr_indeksu), kierunek_studiow(kierunek_studiow) {}

    // Nadpisanie metody to_string() dla klasy Student
    string to_string() const {
        return "Student: " + get_imie() + " " + get_nazwisko() + ", Pesel: " + get_pesel() +
               ", Nr indeksu: " + nr_indeksu + ", Kierunek studiow: " + kierunek_studiow;
    }
};

int main()
{
    // Przykładowe użycie klasy Student
    Student student("Jan", "Kowalski", "12345678901", "S12345", "Informatyka");

    // Wyświetlenie informacji o studencie za pomocą metody to_string() klasy Student
    cout << student.to_string() << endl;

    return 0;
}
W tej poprawionej wersji kodu:

Poprawiono konstruktor klasy Person, aby poprawnie inicjować pola imie, nazwisko i pesel.
Metody get_imie(), get_nazwisko() i get_pesel() zostały poprawnie zdefiniowane jako const

Message ChatGPT…

ChatGPT