Please download to get full document.

View again

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
 2
 
  Short c++ programs
Share
Transcript
  #include <iostream> using namespace std; void bubble_sort(int *polje, int duljina) { int tmp; for(int i=duljina - 1; i>0; i--) { for(int j=0; j<i; j++) { if(polje[j + 1] < polje[j]){ tmp = polje[j]; polje[j] = polje[j+1]; polje[j+1] = tmp; } } } } int main() { int i; int niz[10] = {9, 8, 7, 10, 6, 4, 3, 2, 5, 1}; for(i=0; i<10; i++) cout << niz[i] << ; cout << \nSortiram ... << endl; bubble_sort(niz, 10); for(i=0; i<10; i++) cout << niz[i] << ; cin >> i; return 0; }  //Program učitava broj sekundi (prirodni broj) te ispisuje koliko je to sati, minuta i sekundi  #include <iostream> using namespace std; int main(){ int br_sec,min,hour,sec; cout << Unesi broj sekundi: ; cin >> br_sec; hour=br_sec/3600; min=br_sec%3600/60; sec=br_sec-(hour*3600)-(min*60); cout << hour << h: << min << min: << sec << 's' << endl; cin >> sec; return 0; }  #include <iostream> #include <fstream> using namespace std; struct tslog{ int mat_br; char prez_ime[35]; int g_upisa; }; tslog slog; fstream dat; void unos(){ char jos='d'; dat.open ( podaci.dat ,ios::out | ios::binary); while ((jos=='d')||(jos=='D')){ cout << Maticni broj: ; cin >> slog.mat_br; cout << Prezime i ime : ; cin >> slog.prez_ime; cout << Godina upisa : ; cin >> slog.g_upisa; dat.write ((char *) &slog,sizeof(slog)); cout << Hocete li jos upisivati (d/n) ? ; cin >> jos; }; dat.close(); dat.clear(); }; void ispis(){ dat.open ( podaci.dat ,ios::in | ios::binary); while (1){ dat.read ((char *) &slog,sizeof(slog)); if (dat.eof()) break; cout << Maticni broj : << slog.mat_br << endl; cout << Prezime i ime : << slog.prez_ime << endl;   cout << Godina upisa : << slog.g_upisa << endl; }; dat.close(); dat.clear(); }; int main(){ int izbor; do{ cout << Izaberite: << endl << endl; cout << 1. Unos podataka u datoteku << endl; cout << 2. Ispis podataka iz datoteke << endl; cout << 9. Izlaz iz programa << endl; cin >> izbor; switch (izbor){ case 1: unos();break; case 2: ispis();break; default: cout << Pogresan unos! << endl; }; } while (izbor!=9); cout << Kraj programa! << endl; char c; cin >> c; }
Related Search
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x