Compile problem

I can't compile this code, where is a problem?


#include<string>
#include<iostream>
#include<fstream>

using namespace std;

struct osoba
{

string imie, nazwisko, plec;
int wiek;

};

osoba dodaj_osobe()
{
osoba dodaj;

cout << "Podaj imie \n";
cin >> dodaj.imie;

cout << "Podaj nazwisko \n";
cin >> dodaj.nazwisko;

cout << "Podaj wiek \n";
cin >> dodaj.wiek;

cout << "Podaj plec \n";
cin >> dodaj.plec;

return dodaj;
}

void wyswietl(osoba view)
{

cout << view.imie << " " << view.nazwisko << " " << view.plec << " " << view.wiek <<endl;

}


struct lista
{

float wartosc;
lista* next;

};

lista* head=NULL;

void add_to_list (float a)
{
if (head==NULL)
{
lista* nowyelement = new lista();
nowyelement->wartosc = a;
nowyelement->next = NULL;
head=nowyelement;
}
else
{
lista* iter=head;

while(iter->next!=NULL)
{

iter = iter->next;
}

lista* nowyelement = new lista();
nowyelement->wartosc = a;
nowyelement->next = NULL;
iter->next=nowyelement;

}

}

void delete_from_list(lista* a)
{

if (a==head)
{
lista *todelete = head;
head = head->next;
delete todelete;
}
else
{
lista* iter = head;
while (iter->next!=a)
{
iter = iter->next;
}

iter->next = iter ->next->next;
delete a;

}

}
void delete_from_list(float a)
{

lista* iter = head;
while(iter->next->wartosc!=a)
{
iter= iter->next;
}

lista* todel=iter->next;
iter->next=iter->next->next;
delete todel;

}

void print_list()
{

lista* iter = head;
while (iter!= NULL)
{
cout << iter->wartosc << endl;
iter= iter->next;
}

}

struct stos
{

float war;
stos* poprzedni;

};

stos *wierzcholek = NULL;

void push(float element)
{

stos* nowywierzcholek = new stos();
nowywierzcholek->war = element;
nowywierzcholek->poprzedni= NULL;
nowywierzcholek->poprzedni=wierzcholek;
wierzcholek=nowywierzcholek;

}
float pop ()
{

if (wierzcholek==NULL)
{
return -1;
}
else
{

float dozwrotu=wierzcholek->war;
stos* todel = wierzcholek;
wierzcholek= wierzcholek->poprzedni;
delete todel;
return dozwrotu;

}

}
void print_stos()
{
stos* iter=wierzcholek;
while (iter!=NULL)
{
cout << iter->war <<endl;
iter= iter->poprzedni;
}


}

struct queue
{
queue* next;
float warqueue;

};

queue* pierwszy = NULL;

void push_queue (float b)
{

if (pierwszy==NULL)
{
queue* nowy_el = new queue ();
nowy_el->warqueue=b;
nowy_el->next=NULL;
pierwszy = nowy_el;
}

else
{
queue* iter = pierwszy;
while (iter->next!=NULL)
{
iter=iter->next;
}

queue* koniec = new queue ();
koniec->warqueue = b;
koniec->next=NULL;
iter->next= koniec;
}
}

float pop_queue()
{

if (pierwszy==NULL)
{
return -1;
}
else
{
queue* iter = pierwszy->next;
float wynik=pierwszy->warqueue;
delete pierwszy;
pierwszy= iter;
return wynik;

}
}

int main()
{
int nr_zadania;
cout << "podaj nr zadania\n";
cin >> nr_zadania;

switch(nr_zadania)
{
case 1:
{
osoba* first = new osoba();
first->imie = "Jan";
first->nazwisko = "Kowalski";
first->wiek = 20;
first->plec = "M";

osoba* second = new osoba();
second->imie="Martia";
second->nazwisko="Szczepanska";
second->wiek = 25;
second->plec="K";

osoba* third = new osoba();
third->imie="Czesio";
third->nazwisko="Mozil";
third->wiek= 30;
third->plec="M";

cout << first->imie << " " << first->nazwisko << " " << first->wiek << " " << first->plec << endl;
cout << second->imie << " " << second->nazwisko << " " << second->wiek << " " << second->plec << endl;
cout << third->imie << " " << third->nazwisko << " " << third->wiek << " " << third->plec << endl;

break;
}
case 2:
{

osoba dodaj = dodaj_osobe();
wyswietl(dodaj);

break;
}

case 3:
{
int n;
cout << " Podaj n \n";
cin >>n;

osoba *tab = new osoba[n];

for (int i = 0; i < n; i++)
{
tab[i] = dodaj_osobe();

}

for (int i = 0; i < n; i++)
{
wyswietl(tab[i]);
}

delete [] tab;
break;
}

case 4:
{
system("cls");
add_to_list(4.0);
add_to_list(3.5);
add_to_list(5.0);
delete_from_list(3.5);
print_list();

break;
}

case 5:
{
//count

break;
}
case 6:
{

push(1.0);
push(2.0);
push(3.0);

print_stos();

pop();
pop();

print_stos();

break;
}
case 7:
{
push_queue(1);
push_queue(2);
push_queue(3);

pop_queue();
}

case 8:
{
osoba* first = new osoba();
first->imie = "Jan";
first->nazwisko = "Kowalski";
first->wiek = 20;
first->plec = "M";

osoba* second = new osoba();
second->imie="Martia";
second->nazwisko="Szczepanska";
second->wiek = 25;
second->plec="K";

osoba* third = new osoba();
third->imie="Czesio";
third->nazwisko="Mozil";
third->wiek= 30;
third->plec="M";

cout << first->imie << " " << first->nazwisko << " " << first->wiek << " " << first->plec << endl;
cout << second->imie << " " << second->nazwisko << " " << second->wiek << " " << second->plec << endl;
cout << third->imie << " " << third->nazwisko << " " << third->wiek << " " << third->plec << endl;

fstream file;
file.open("wynik.txt", ios_base::out );

file << first->imie << " ";
file << first->nazwisko<< " ";
file << first->wiek<< " ";
file << first->plec<< " ";

file.close();

break;
}

case 9:
{

osoba* obiekt = new osoba();
fstream file;
file.open("wynik.txt");

file >> obiekt->imie;
file >> obiekt->nazwisko;
file >> obiekt->wiek;
file >> obiekt->plec;

cout << obiekt->imie <<endl;
cout << obiekt->nazwisko<<endl;
cout << obiekt->wiek<<endl;
cout << obiekt->plec<<endl;

break;
}

case 10:
{

ofstream file;
file.open("wynikbin", ios_base::binary);

int dupa = 20;
file.write(( char *) &dupa, sizeof(int));
file.close();

int dupawynik=-1;
ifstream f2;
f2.open("wynikbin", ios_base::binary);
f2.read((char *) &dupawynik, sizeof(int));
cout << dupawynik;

}


}
system("pause");
return 0;
}
http://www.cplusplus.com/forum/beginner/1/
Don't ask others to debug your broken code without
giving a hint what sort of problem they should be searching for


Use code highlighting (shows line numbers) and post the error.
Last edited on
if you can't compile it you are probably getting a compiler error..What is the error? Also please use code tags
[code][/code]
around your code.
Hmm...didn't I already answer you back in your other topic?
http://www.cplusplus.com/forum/beginner/122131/

In any case, I can get it to compile by adding #include <cstdlib> .
(Now, whether it runs correctly or not, I have no clue, since I can't read that language)
Last edited on
Topic archived. No new replies allowed.