Chlapci, prosím vás kuknite sa mi na to...
#include <iostream>
using namespace std;
const int SLEN=30;
struct student
{
char fullname[SLEN];
char hobby[SLEN];
int ooplevel;
};
int getinfo(student pa[],int n);
void display1(student st);
void display2(const student * ps);
void display3(const student pa[], int n);
int main()
{
cout << "Zadaj velkost triedy: ";
int class_size;
if (!(cin >> class_size)) cin.clear();
while (cin.get() != '\n')
continue;
student * ptr_stu= new student[class_size];
int entered = getinfo(ptr_stu,class_size);
for (int i = 0; i<entered;i++)
{
display1(ptr_stu[i]);
display2(&ptr_stu[i]);
cout <<"::::::::::::::::::::\n";
}
system("PAUSE");
display3(ptr_stu, entered);
delete [] ptr_stu;
cout << "HOtovo!\n";
cin.get();
system("PAUSE");
return 0;
}
int getinfo(student pa[],int n)
{
int i=0;
while (i++<n)
{
cout << "Zadaj meno " << i << "studenta: ";
cin.getline(pa[i].fullname,SLEN);
cout << "Zadaj jeho hobby: ";
cin.get(pa[i].hobby,SLEN);
cout << "Zadaj ooplevel: ";
cin >> pa[i].ooplevel;
cin.get();
}
return i;
}
void display1(student st)
{
cout << "Meno : " << st.fullname << endl;
cout << "Hobby : " << st.hobby << endl;
cout << "Ooplevel : " << st.ooplevel << endl;
}
void display2(const student*ps)
{
cout << "Meno : " << (*ps).fullname << endl;
cout << "Hobby : " << (*ps).hobby << endl;
cout << "Ooplevel : " << (*ps).ooplevel << endl;
}
void display3(const student pa[],int n)
{
for (int i=0;i<n;i++)
{
cout << "Meno : " << pa[i].fullname << endl;
cout << "Hobby : " << pa[i].hobby << endl;
cout << "Ooplevel : " << pa[i].ooplevel << endl;
}
}
je to pre mňa nepochopiteľné...pauzujem to a ono si to robí čo chce...len to prebleskne a keď to debugujem dajak mi to píše bludy...pri kompilovaní mi chybu nenájde..
Fórum › C / C++
Struktury,Fkcie,Ukazatele

je smutne, ze uz poradne neznam C++, ale porad se mi tam nejake veci nezdaji
sice neni chyba, ale to continue tam je uplne zbytecne, ma tam byt jen strednik
while (cin.get() != '\n') continue; => while (cin.get() != '\n');
(*ps).fullname je to same jako ps->fullname
main je v tele tridy?
nebo nemas u funkci student:: ? Tedy nemas udelane ze metody patri do tridy?
neco jako konstruktor, destructor?
Kdyz programujes, tak si delej ladici vystupy. Vypsat treba vsechny promene, ale samozrejme jen u tech kde vys co tam ma byt. Kdyz tam je neco co neocekavas, tak vys ze chyba je nekde kolem.
main je v tele tridy?
nebo nemas u funkci student:: ? Tedy nemas udelane ze metody patri do tridy?
sem se prehledl, nemas tam u metod/funkci student::, tedy funkce nemaji prislusnost k tride
a jeste, nemusis mit display1, display2, display3, staci jen u vsech stejny nazev display, je tam vlastnost C++, myslim ... eh nemuzu si vzpomenout:P
Sahal jsi na paměť, kterou jsi neměl alokovanou. Viz. smyčka while v getinfo().
#include <iostream>
using namespace std;
const int SLEN=30;
struct student
{
char fullname[SLEN];
char hobby[SLEN];
int ooplevel;
};
int getinfo(student pa[],int n);
void display1(student st);
void display2(const student * ps);
void display3(const student pa[], int n);
int main()
{
cout << "Zadaj velkost triedy: ";
int class_size;
if (!(cin >> class_size)) cin.clear();
while (cin.get() != '\n');
student * ptr_stu= new student[class_size];
int entered = getinfo(ptr_stu,class_size);
for (int i = 0; i<entered;i++)
{
display1(ptr_stu[i]);
display2(&ptr_stu[i]);
cout <<"::::::::::::::::::::\n";
}
system("PAUSE");
display3(ptr_stu, entered);
delete [] ptr_stu;
cout << "HOtovo!\n";
cin.get();
system("PAUSE");
return 0;
}
int getinfo(student pa[],int n)
{
int i;
for(i=0; i < n ; ++i)
{
cout << "Zadaj meno " << i+1 << "studenta: ";
cin.getline(pa[i].fullname,SLEN);
cout << "Zadaj jeho hobby: ";
cin.get(pa[i].hobby,SLEN);
cout << "Zadaj ooplevel: ";
cin >> pa[i].ooplevel;
cin.get();
}
return i;
}
void display1(student st)
{
cout << "Meno : " << st.fullname << endl;
cout << "Hobby : " << st.hobby << endl;
cout << "Ooplevel : " << st.ooplevel << endl;
}
void display2(const student*ps)
{
cout << "Meno : " << (*ps).fullname << endl;
cout << "Hobby : " << (*ps).hobby << endl;
cout << "Ooplevel : " << (*ps).ooplevel << endl;
}
void display3(const student pa[],int n)
{
for (int i=0;i<n;i++)
{
cout << "Meno : " << pa[i].fullname << endl;
cout << "Hobby : " << pa[i].hobby << endl;
cout << "Ooplevel : " << pa[i].ooplevel << endl;
}
}

Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
C# ukazatelé — založil Kubas129
Moderátoři diskuze