Advertisement
pjobro

lista...igre....input output....zadatak student(laksi)

Mar 15th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.03 KB | None | 0 0
  1. using namespace std;
  2.  
  3. int main()
  4. {
  5.     //lista deklaracija unost i sipis
  6.     list<int>lista;
  7.  
  8.     cout << "unost lementa u listu" << endl << endl;
  9.  
  10.     //unost lemenata u listu( dvba na pocetku i dva na kraju)
  11.     int e_liste;
  12.  
  13.     cout << "unestie lement na pocetak liste: ";
  14.     cin>> e_liste;
  15.     lista.push_front(e_liste);
  16.     cout << "unestie lement na pocetak liste: ";
  17.     cin >> e_liste;
  18.     lista.push_front(e_liste);
  19.     cout << "unestie lement na krej liste: ";
  20.     cin >> e_liste;
  21.     lista.push_back(e_liste);
  22.     cout << "unestie lement na krej liste: ";
  23.     cin >> e_liste;
  24.     lista.push_back(e_liste);
  25.  
  26.     for (list<int>::iterator i = lista.begin(); i != lista.end; i++) {
  27.         cout << *i << endl;
  28.     }
  29.    
  30.     return 0;
  31.  
  32. }
  33.  
  34. pogodi broj............
  35. int main()
  36. {
  37.  
  38.     srand(time(NULL));
  39.     int broj = 0;
  40.     int trazeniBroj = (rand() % 99) + 1;
  41.  
  42.     cout << "pogodite broj od 1do100; ";
  43.     cin >> broj;
  44.     while (trazeniBroj != broj)
  45.     {
  46.         if (broj < trazeniBroj)
  47.         {
  48.             cout << "broj koji pogadas je veci.try gain." << endl;
  49.         }
  50.         else if (broj > trazeniBroj)
  51.         {
  52.             cout << "broj koji pogas je manje.try again." << endl;
  53.         }
  54.  
  55.        
  56.     }
  57.     cout << "bravo!broj koji se trazioje= " << trazeniBroj << endl;
  58.  
  59.  
  60.     return 0;
  61.  
  62. }
  63.  
  64. novcic................
  65. int main()
  66. {
  67.     srand(time(NULL));
  68.     char unos = 'x';
  69.     cout << "unestite x za bacanje novcica ili neki drugi znakza izlaz" << endl;
  70.     cin >> unos;
  71.     while (unos == 'x')
  72.     {
  73.         if (rand() % 2 == 0)
  74.             cout << "pistmo" << endl;
  75.         else
  76.             cout << "glava" << endl;
  77.  
  78.         cout << "unestite x za vacanje noviccca ili neki drugi znak" << endl;
  79.         cin >> unos;
  80.     }
  81.     return 0;
  82. }
  83.  
  84.  
  85. rucka.........
  86. #include "stdafx.h"
  87. #include <iostream>
  88.  
  89. #include<cstdlib>
  90. #include<ctime>
  91.  
  92. using namespace std;
  93.  
  94. int main()
  95. {
  96.     srand(time(NULL));
  97.     int a=1 , b=2 , c=3;
  98.     char x;
  99.    
  100.  
  101.    
  102.     do
  103.     {
  104.         cout << "unsetite x da bi zavrtio";
  105.         cin >> x;
  106.         a =rand() % 3+1;
  107.         b =rand() % 3+1;
  108.         c = rand() % 3+1;
  109.         cout << a << " " << b << " " << c << endl;
  110.        
  111.  
  112.        
  113.     } while (a != b || b != c || a != c);
  114.  
  115.  
  116.         cout << "pobjeda!" << endl;
  117.         cout << a << " " << b << " " << c << endl;
  118.  
  119.     }
  120.  
  121. ..............getline....stream...txt
  122. #include "stdafx.h"
  123. #include <iostream>
  124. #include <vector>
  125. #include<string>
  126.  
  127. #include<cstdlib>
  128. #include<ctime>
  129. #include<fstream>
  130.  
  131. using namespace std;
  132.  
  133. int main()
  134. {
  135.     //ispis podata iz datoteke
  136.     vector<string> podaci;
  137.  
  138.     ifstream input("Text.txt");//deklariranej if streama
  139.                                    //objekta input
  140.     string line;
  141.     while(input) { //dok ima inputa
  142.         getline(input, line); //input se sprema u line
  143.         podaci.push_back(line); //line se sprema u vektor
  144.     }
  145.     input.close(); //zatvaranje stream-a
  146.     for (int i = 0; i < podaci.size()-1; i++) {
  147.         cout << podaci[i] << endl;
  148.     }
  149.     //...................
  150.     //unos podataka u datoteku
  151.     int id;
  152.     string ime, prezime, za_spremanje;
  153.     cout << "uensite ID: ";
  154.     cin >> id;
  155.     cin.ignore();  //koristime jer u streamu situacija izgleda ovako 123\n -> 123 se ucita u int,
  156.                    // a \n se ucita u string pa nam getline preskoci jedan inpuz,
  157.                    //signore() kako bi preskocio \n, a ne da ga ucita u varijablu
  158.  
  159.     cout << "unesite ime: ";
  160.     getline(cin, ime);
  161.     cout << "unestie prezime: ";
  162.     getline(cin, prezime);
  163.  
  164.     //pripremaza spremanje
  165.     za_spremanje = to_string(id) + " " + ime + " " + prezime + "\n";
  166.  
  167.     ofstream output; ///stvaranje ofstream objekta output
  168.     output.open("text.txt", ios::out | ios::app); //ios-flagovi...da bi na odgovarajuci nacin nesto napisali//app---dodaj na ono sto postoji
  169.     output << za_spremanje;
  170.     output.close(); ///zarvaranje outputa
  171.  
  172.     return 0;
  173.  
  174.     }
  175.  
  176. napsite program koji ce u datoteku spremati i citatti brojeve od 0do onoga kojega koristnik unese(svaki puta neka se datoteka "pregazi" nobivm brojem.
  177. ..................
  178. #include "stdafx.h"
  179. #include <iostream>
  180. #include <vector>
  181. #include<string>
  182. #include<cstdlib>
  183. #include<ctime>
  184. #include<fstream>
  185.  
  186. using namespace std;
  187.  
  188. int main()
  189. {
  190.    
  191.     int x;
  192.     cout << "unesite broj: ";
  193.     cin >> x;
  194.  
  195.     ifstream output;
  196.     output.open("text.txt", ios::out);
  197.    
  198.     for (int i = x; i > 0; i--)
  199.     {
  200.         output << i << endl;   
  201.     }
  202.     output.close();
  203.     return 0;
  204. }
  205. napravi zadatak u jemu ce igraci bacati kockicu . nakon svakog bacanja neka se ispise tko je pobjednik te neka se brojevi na kockici i ime igraca spremi u datoteku
  206. ............
  207. int main()
  208. {
  209.    
  210.     int a, b;
  211.  
  212.     cin >> a;
  213.     cout << "ante je bacio: " << a << endl;
  214.     cin >> b;
  215.     cout << "jure je bacio: " << b << endl;
  216.  
  217.     fstream output;
  218.     output.open("text.txt", ios::out);
  219.    
  220.    
  221.         output << a << endl;
  222.         output << b << endl;
  223.         if (a > b)
  224.         {
  225.             output << "ante je dobija!";
  226.         }
  227.         else if (a < b)
  228.         {
  229.             output << "jure je dobija";
  230.         }
  231.         else
  232.         {
  233.             output << "tie";
  234.         }
  235.    
  236.     output.close();
  237.     return 0;
  238. }
  239. ............napisi program koji ce korisniku prikazati izbornik s mogucnostima(citanje i pisanje u datoteku):1prikat svih studneata 2unost novoga studenta(rbr,ime,pretime,prosjecna ocjena,broj polozenih ects-a 3.pretrazivanje po rbr 4. izracun prosjecne ocjene cijele grupe
  240.  
  241. #include "stdafx.h"
  242. #include <iostream>
  243. #include <vector>
  244. #include<string>
  245. #include<cstdlib>
  246. #include<ctime>
  247. #include<fstream>
  248.  
  249. using namespace std;
  250.  
  251. int main()
  252. {
  253.    
  254.     int izbor;
  255.     cin >> izbor;
  256.     cout << "1. prikaz svih studenata: "<<endl;
  257.     cout << "2. unos novoga studenta: " << endl;
  258.     cout << "3. pretrazivanje po rbr: " << endl;
  259.     cout << "4. izracun prosjecne ocjene: " << endl;
  260.  
  261.     switch (izbor) {
  262.     case 1:
  263.         prikaz();
  264.     case 2:
  265.         unos();
  266.     case 3:
  267.         pretrazivanje();
  268.     case 4:
  269.         prosjek_grupe();
  270.     default:
  271.         cout << "try again";
  272.     }
  273.  
  274.    
  275.     return 0;
  276. }
  277.  
  278. void prikaz()
  279. {
  280.     //ispis podata iz datoteke
  281.     vector<string> podaci;
  282.  
  283.     ifstream input("Text.txt");//deklariranej if streama
  284.                                //objekta input
  285.     string line;
  286.     while (input) { //dok ima inputa
  287.         getline(input, line); //input se sprema u line
  288.         podaci.push_back(line); //line se sprema u vektor
  289.     }
  290.     input.close(); //zatvaranje stream-a
  291.     for (int i = 0; i < podaci.size() - 1; i++) {
  292.         cout << podaci[i] << endl;
  293. }
  294.  
  295. *******studenti od domagoja....nedovrseno?
  296. #include <iostream>
  297. #include <string>
  298. #include <vector>
  299. #include <sstream>
  300.  
  301. using namespace std;
  302. //const int MAX = 3;
  303.  
  304. struct student
  305. {
  306.   string ime, oib, matBroj, prezime;
  307.   int godine;
  308.  
  309. };
  310.  
  311. int main () {
  312.   int N, min = 999, minIndex;
  313.   cin >> N;
  314.  
  315.   vector<student> stud;
  316.  
  317.   for(int i = 0; i < N; i++) {
  318.     stud.push_back(student());
  319.     cin >> stud[i].ime >> stud[i].prezime >> stud[i].godine >>  stud[i].oib >>  stud[i].matBroj;
  320.  
  321.   }
  322.  
  323.   for (int i = 0; i < N; ++i)
  324.     if(stud[i].godine < min) {
  325.       minIndex = i;
  326.       min = stud[i].godine;
  327.     }
  328.  
  329.   cout << stud[minIndex].ime << " " << stud[minIndex].prezime << " " << stud[minIndex].godine << endl;
  330.  
  331.  
  332.   // int  var[MAX] = {10, 100, 200};
  333.   // int *ptr[MAX];
  334.  
  335.   // for (int i = 0; i < MAX; i++) {
  336.   //   ptr[i] = &var[i]; // assign the address of integer.
  337.   // }
  338.  
  339.   // for (int i = 0; i < MAX; i++) {
  340.   //   cout << "Value of var" << i << " = ";
  341.   //     cout << &ptr[i] << endl;
  342.   //  }
  343.  
  344.    return 0;
  345. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement