#include <iostream>
#include <string>
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
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}