Witam, mam tu kod na podstawie notatek z ćwiczeń i mam dwa krótkie pytania.
Czym jest "wpisz_nazwisko (char)" w tym kodzie. Działa jak konstruktor, ale konstruktorem nie jest, funkcją też nie. Niestety nie potrafiłem znaleźć odpowiedzi na to pytanie.
Druga rzecz to niestety program nie spełnia roli. Ja podaje nazwisko, a w programie wyświetla się tylko pierwsza litera tego nazwiska. Jaka może być przyczyna?
class Student
{
char nazwisko;
int ocena;
public:
Student();
~Student();
char podaj_nazwisko();
int podaj_ocene();
wpisz_nazwisko (char);
wpisz_ocene (int);
};
#include "student.h"
Student::Student()
{
}
Student::~Student()
{}
char Student::podaj_nazwisko()
{
return (nazwisko);
}
int Student::podaj_ocene()
{
return (ocena);
}
Student::wpisz_nazwisko(char u)
{
nazwisko=u;
}
Student::wpisz_ocene(int o)
{
ocena=o;
}
#include <iostream>
#include "student.h"
Student *tabl[100];
int licznik_st=1;
using namespace std;
int main()
{
cout<<"Program "<<endl;
char wybor;
do
{
Student *p=new Student;
tabl[licznik_st]=p;
cout<<"Napisz a"<<endl;
int a;
char b;
cin>>a;
cout<<"Napisz b";
cin>>b;
tabl[licznik_st] -> wpisz_ocene(a);
tabl [licznik_st] ->wpisz_nazwisko(b);
cout<<endl<<"Nazwisko studenta: "<<tabl[licznik_st] ->Student::podaj_nazwisko()<<endl;
cout<<endl<<"Ocena studenta to: "<<tabl[licznik_st] ->Student::podaj_ocene()<<endl;
//tutatj dla ocen
licznik_st++;
cout<<"zeby kontynuowac wybierz t"<<endl;
cin>>wybor;
}
while(wybor=='b');
}