Ponieważ jest to mój pierwszy post na tym forum, to zacznę od przywitania się z wami, cześć wszystkim. Uczę się c++ od niedawna, bo około czterech tygodni, od kilku dni ćwiczę swoje umiejętności na hackerrank. Przechodząc do rzeczy, link do zadania, z którym mam problem zamieszczam poniżej, próbowałem już chyba wszystkiego i nie mam pojęcia w czym problem. Rozumiem, że z jakiegoś powodu metody nie wczytują danych, ale nie wiem dlaczego. Ogólnie cały kod nie jest zbyt chlubny, ale po części jest to zależne od ustawień startowych zadania(da się coś zrobić prościej, ale chodzi o poćwiczenie sposobu). Byłbym wdzięczny za każdą pomoc, szukałem rozwiązania gdzie indziej i nic nie znalazłem niestety.
https://www.hackerrank.com/challenges/c-tutorial-class
#include <iostream>
#include <sstream>
using namespace std;
class Student
{
int agee, standardd;
string first_namee, last_namee;
public:
void set_age(int age)
{
age = agee;
};
int get_age()
{
return agee;
};
void set_standard(int standard)
{
standard = standardd;
};
int get_standard()
{
return standardd;
};
void set_first_name(string first_name)
{
first_name = first_namee;
};
string get_first_name()
{
return first_namee;
};
void set_last_name(string last_name)
{
last_name = last_namee;
};
string get_last_name()
{
return last_namee;
};
string to_string()
{
string napis;
stringstream ss;
ss << agee << "," << first_namee << "," << last_namee << "," << standardd;
napis = ss.str();
return napis;
};
};
int main()
{
int age, standard;
string first_name, last_name;
cin >> age >> first_name >> last_name >> standard;
Student st;
st.set_age(age);
st.set_standard(standard);
st.set_first_name(first_name);
st.set_last_name(last_name);
cout << st.get_age() << "\n";
cout << st.get_last_name() << ", " << st.get_first_name() << "\n";
cout << st.get_standard() << "\n";
cout << "\n";
cout << st.to_string();
return 0;
}
Wynik tego kodu jest następujący: