Search
 
 
  Engleski
 
 
 
Open in this window (click to change)
Forum@DeGiorgi: Početna
Forum za podršku nastavi na PMF-MO
Login Registracija FAQ Smajlići Članstvo Pretražnik Forum@DeGiorgi: Početna

zadatak s vježbi
WWW:
Idite na Prethodno  1, 2
Moja sarma
 
Započnite novu temu   Odgovorite na temu   printer-friendly view    Forum@DeGiorgi: Početna -> Kolegiji 2. godine -> Računarski praktikum 1
Prethodna tema :: Sljedeća tema  
Autor/ica Poruka
marsupial
Forumaš(ica)
Forumaš(ica)


Pridružen/a: 09. 01. 2012. (22:46:33)
Postovi: (63)16
Spol: kućni ljubimac
Sarma = la pohva - posuda
= 5 - 1

PostPostano: 10:36 uto, 29. 4. 2014    Naslov: Citirajte i odgovorite

kada će biti objavljena rješenja zadataka sa 5. i 6. vježbi?
kada će biti objavljena rješenja zadataka sa 5. i 6. vježbi?


[Vrh]
Korisnički profil Pošaljite privatnu poruku
relax
Forumaš(ica)
Forumaš(ica)


Pridružen/a: 01. 02. 2014. (20:23:33)
Postovi: (1E)16
Spol: žensko
Sarma = la pohva - posuda
= 5 - 0

PostPostano: 23:21 uto, 29. 4. 2014    Naslov: Citirajte i odgovorite

Evo source za Vjezbe 5 i 6 po zadacima. Možda ima viška koda (to sam radio na satu na vjezbama), ali ako pokrenete program, radit ce tocno ono sto se trazi :)

Na dnu imate za download .cpp datoteke

[b]Vjezbe 5 zadatak 1[/b]
[code:1]
#include<iostream>
#include<vector>
#include<list>

using namespace std;

template <typename STL>

void ispis(STL struktura){
for(typename STL::iterator i = struktura.begin(); i != struktura.end(); ++i)
cout << *i << " ";
cout << endl;
}

// ovo je funkcija koja dodaje slova ispred rijeci, kao u prvom dijelu zadatka
void dodaj(list<string>& L){
list<string>::iterator li = L.begin();
while(li != L.end()){
for(int i = 0; i < (*li).length(); ++i)
L.insert(li , string(1, (*li)[i]));
++li;
}
}

// ovo je funkcija koja dodaje slova poslije rijeci, ono sto pise za dz u prezentaciji
void dodajNaKraj(list<string>& L){
list<string>::iterator li = L.begin();
list<string>::iterator li_;
while(li != L.end()){
li_ = li;
++li_;
for(int i = 0; i < (*li).length(); ++i){
L.insert(li_, string(1, (*li)[i]));
}
li = li_;
}
}

int main(){

string S;
list<string> L;
cin >> S;
while(S != "kraj"){
L.push_back(S);
cin >> S;
}
//cout << "-Ucitana lista: ";
//ispis(L);
//dodaj(L);
dodajNaKraj(L);
//cout << "-Obradena lista: ";
ispis(L);

vector<string> V;
vector<string>::iterator vi = V.begin();
list<string>::iterator li = L.begin();
while(li != L.end()){
if((*li).size() > 1){
string a = (*li);
V.push_back(a);
li = L.erase(li);
}
else
++li;
}

cout << "-Vektor: ";
ispis(V);
/*
cout << "-Lista: ";
ispis(L);
*/
return 0;
}
[/code:1]
[b]Vjezbe 6 zadatak 1[/b]
[code:1]#include<iostream>
#include<set>
#include<string>

using namespace std;

template<typename STL>

void ispis(STL struktura){
typename STL::iterator si;
si = struktura.begin();
while(si != struktura.end()){
cout << endl << *si;
++si;
}
}

int main(){
set<string> S;
string a;
int cnt = 0;
cin >> a;
//do cin >> a; while(S.insert(a).second);

while(!S.count(a)){
S.insert(a);
cnt++;
cin >> a;
}

cout << endl << "Unijeli smo ih " << cnt;
cout << endl << "Sortirani niz stringova:" << endl;
ispis(S);

// brisanje elemenata
set<string>::iterator si = S.begin();
while(si != S.end()){
if(!(si->size() % 2)){
S.erase(si++);
--cnt;
}
else ++si;
}
cout << endl << "Ostalo ih je " << cnt;
ispis(S);
}
[/code:1]

[b]Vjezbe 6 zadatak 2[/b]
[code:1]
#include<iostream>
#include<string>
#include<map>

using namespace std;

template<typename STL>

void ispis(STL struktura){
typename STL::iterator si;
si = struktura.begin();
int i = 1;
while(si != struktura.end()){
cout << endl << "#" << i++ << " " << si->first << "\t\t" << si->second;
++si;
}
}

int main(){
map<string, int> M;
map<string, int>::iterator mi = M.begin();
string ucenik;
int ocjena;
// unos ucenika i njihovih ocjena
cin >> ucenik;
while(ucenik != "kraj"){
cin >> ocjena;
M[ucenik] = ocjena;
cin >> ucenik;
}
cout << endl << "Popis ucenika s negativnom ocjenom: " << endl;
// prolazimo po mappingu i ispisujemo samo one koji imaju ocjenu 1
mi = M.begin();
int i = 1;
while(mi != M.end()){
if(mi->second == 1)
cout << endl << "#" << i++ << " " << mi->first << "\t\t" << mi->second;
++mi;
}
// izbacivanje ucenika s ocjenom 1
mi = M.begin();
while(mi != M.end()){
if(mi->second == 1)
M.erase(mi++);
else ++mi;
}
// ispis preostalih ucenika
cout << endl << "Popis ucenika koji imaju pozitivnu ocjenu:" << endl;
ispis(M);
}
[/code:1]
Evo source za Vjezbe 5 i 6 po zadacima. Možda ima viška koda (to sam radio na satu na vjezbama), ali ako pokrenete program, radit ce tocno ono sto se trazi Smile

Na dnu imate za download .cpp datoteke

Vjezbe 5 zadatak 1
Kod:

#include<iostream>
#include<vector>
#include<list>

using namespace std;

template <typename STL>

void ispis(STL struktura){
   for(typename STL::iterator i = struktura.begin(); i != struktura.end(); ++i)
      cout << *i << " ";
   cout << endl;
}

// ovo je funkcija koja dodaje slova ispred rijeci, kao u prvom dijelu zadatka
void dodaj(list<string>& L){
   list<string>::iterator li = L.begin();
   while(li != L.end()){
         for(int i = 0; i < (*li).length(); ++i)
            L.insert(li , string(1, (*li)[i]));
      ++li;
   }
}

// ovo je funkcija koja dodaje slova poslije rijeci, ono sto pise za dz u prezentaciji
void dodajNaKraj(list<string>& L){
   list<string>::iterator li = L.begin();
   list<string>::iterator li_;
   while(li != L.end()){
      li_ = li;
      ++li_;
      for(int i = 0; i < (*li).length(); ++i){
         L.insert(li_, string(1, (*li)[i]));
      }
      li = li_;
   }
}

int main(){

   string S;
   list<string> L;
   cin >> S;
   while(S != "kraj"){
      L.push_back(S);
      cin >> S;
   }
   //cout << "-Ucitana lista: ";
   //ispis(L);
   //dodaj(L);
   dodajNaKraj(L);
   //cout << "-Obradena lista: ";
   ispis(L);

   vector<string> V;
   vector<string>::iterator vi = V.begin();
   list<string>::iterator li = L.begin();
   while(li != L.end()){
      if((*li).size() > 1){
         string a = (*li);
         V.push_back(a);
         li = L.erase(li);
      }
      else
         ++li;
   }

   cout << "-Vektor: ";
   ispis(V);
   /*
   cout << "-Lista: ";
   ispis(L);
   */
   return 0;
}

Vjezbe 6 zadatak 1
Kod:
#include<iostream>
#include<set>
#include<string>

using namespace std;

template<typename STL>

void ispis(STL struktura){
   typename STL::iterator si;
   si = struktura.begin();
   while(si != struktura.end()){
      cout << endl << *si;
      ++si;
   }
}

int main(){
   set<string> S;
   string a;
   int cnt = 0;
   cin >> a;
   //do cin >> a;   while(S.insert(a).second);

   while(!S.count(a)){
      S.insert(a);
      cnt++;
      cin >> a;
   }

   cout << endl << "Unijeli smo ih " << cnt;
   cout << endl << "Sortirani niz stringova:" << endl;
   ispis(S);

   // brisanje elemenata
   set<string>::iterator si = S.begin();
   while(si != S.end()){
      if(!(si->size() % 2)){
         S.erase(si++);
         --cnt;
      }
      else ++si;
   }
   cout << endl << "Ostalo ih je " << cnt;
   ispis(S);
}


Vjezbe 6 zadatak 2
Kod:

#include<iostream>
#include<string>
#include<map>

using namespace std;

template<typename STL>

void ispis(STL struktura){
   typename STL::iterator si;
   si = struktura.begin();
   int i = 1;
   while(si != struktura.end()){
      cout << endl << "#" << i++ << " " << si->first << "\t\t" << si->second;
      ++si;
   }
}

int main(){
   map<string, int> M;
   map<string, int>::iterator mi = M.begin();
   string ucenik;
   int ocjena;
   // unos ucenika i njihovih ocjena
   cin >> ucenik;
   while(ucenik != "kraj"){
      cin >> ocjena;
      M[ucenik] = ocjena;
      cin >> ucenik;
   }
   cout << endl << "Popis ucenika s negativnom ocjenom: " << endl;
   // prolazimo po mappingu i ispisujemo samo one koji imaju ocjenu 1
   mi = M.begin();
   int i = 1;
   while(mi != M.end()){
      if(mi->second == 1)
         cout << endl << "#" << i++ << " " << mi->first << "\t\t" << mi->second;
      ++mi;
   }
   // izbacivanje ucenika s ocjenom 1
   mi = M.begin();
   while(mi != M.end()){
      if(mi->second == 1)
         M.erase(mi++);
      else ++mi;
   }
   // ispis preostalih ucenika
   cout << endl << "Popis ucenika koji imaju pozitivnu ocjenu:" << endl;
   ispis(M);
}





vjezbe6.2.cpp
 Description:
Vjezbe 6, zadatak 2

Download
 Filename:  vjezbe6.2.cpp
 Filesize:  1.11 KB
 Downloaded:  132 Time(s)


vjezbe6.1.cpp
 Description:
Vjezbe 6, zadatak 1

Download
 Filename:  vjezbe6.1.cpp
 Filesize:  780 Bytes
 Downloaded:  135 Time(s)


vjezbe5.1.cpp
 Description:
Vjezbe 5, zadatak 1

Download
 Filename:  vjezbe5.1.cpp
 Filesize:  1.43 KB
 Downloaded:  139 Time(s)

[Vrh]
Korisnički profil Pošaljite privatnu poruku
Prethodni postovi:   
Započnite novu temu   Odgovorite na temu   printer-friendly view    Forum@DeGiorgi: Početna -> Kolegiji 2. godine -> Računarski praktikum 1 Vremenska zona: GMT + 01:00.
Idite na Prethodno  1, 2
Stranica 2 / 2.

 
Forum(o)Bir:  
Možete otvarati nove teme.
Možete odgovarati na postove.
Ne možete uređivati Vaše postove.
Ne možete izbrisati Vaše postove.
Ne možete glasovati u anketama.
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2002 phpBB Group
Theme created by Vjacheslav Trushkin
HR (Cro) by Ančica Sečan