Advertisement
pjobro

student 300+(ivan)

Mar 17th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.29 KB | None | 0 0
  1. // Strukture - Student management.cpp :
  2. /* Napišite program koji će omogućiti administraciju studenata:
  3.     - unos novih
  4.     - brisanje (po ID-u)
  5.     - izmjenu podataka o studentu
  6.     - prikaz svih studenata
  7.     - prikaz prosjeka po ispitu
  8.     - prikaz najboljeg
  9.     - prikaz najgoreg
  10.     - prikaz po ID-u
  11.     - sortiranje po ukupnom uspjehu
  12.  
  13.     struktura Student mora imati sljedeće podatke:
  14.     - ID
  15.     - ime
  16.     - prezime
  17.     - spol
  18.     - rezultat 1. kolokvija
  19.     - rezultat 2. kolokvija
  20.     - rezultat zavrsnog ispita
  21.     - ukupni uspjeh
  22.  
  23.     Pametno iskoristite sturukture podataka
  24. */
  25.  
  26. #include "stdafx.h"
  27. #include <iostream>
  28. #include <string>
  29. #include <map>
  30. #include <vector>
  31. #include <array>
  32.  
  33. using namespace std;
  34.  
  35. struct Student {
  36.     string ID;
  37.     string ime;
  38.     char spol;
  39.     map <string, double> rezultati;
  40. };
  41.  
  42. void menu();
  43. int search(Student st[100], string id, int itemcount);
  44. void add_student(Student st[100], int &itemcount);
  45. void show_students(Student st[100], int itemcount);
  46. void delete_student(Student st[100], int &itemcount);
  47. void izmjena_student(Student st[100], int itemcount);
  48. void prosjek_po_ispitu(Student st[100], int itemcount);
  49. void prikaz_najboljeg(Student st[100], int itemcount);
  50. void prikaz_najgoreg(Student st[100], int itemcount);
  51. void pronalazak_po_id(Student st[100], int itemcount);
  52. void soriranje_studenata(Student st[100], int itemcount);
  53.  
  54. int main()
  55. {
  56.     cout << "\t\t - Sustav za upravljanje studentima - \n";
  57.    
  58.     Student st[100];
  59.     int student_count = 0;
  60.  
  61.  
  62.     int izbor = -1;
  63.  
  64.     while (izbor != 0) {
  65.         menu();
  66.         cout << "Unesite svoj izbor: ";
  67.         cin >> izbor;
  68.         switch (izbor) {
  69.         case 1:
  70.             add_student(st, student_count);
  71.             break;
  72.         case 2:
  73.             delete_student(st, student_count);
  74.             break;
  75.         case 3:
  76.             izmjena_student(st, student_count);
  77.             break;
  78.         case 4:
  79.             show_students(st, student_count);
  80.             break;
  81.         case 5:
  82.             prosjek_po_ispitu(st, student_count);
  83.             break;
  84.         case 6:
  85.             prikaz_najboljeg(st, student_count);
  86.             break;
  87.         case 7:
  88.             prikaz_najgoreg(st, student_count);
  89.             break;
  90.         case 8:
  91.             pronalazak_po_id(st, student_count);
  92.             break;
  93.         case 9:
  94.             soriranje_studenata(st, student_count);
  95.             break;
  96.         case 0:
  97.             cout << endl;
  98.             break;
  99.         default:
  100.             cout << "\nNiste unijeli valjani izbor. Pokusajte ponovo\n";
  101.             menu();
  102.             break;
  103.         }
  104.     }
  105.     system("pause");
  106.     return 0;
  107. }
  108.  
  109. void menu() {
  110.    
  111.     cout << "\nOdaberite sto zelite uciniti:\n\n";
  112.     cout << "1 - Unos novog studenta\n";
  113.     cout << "2 - Brisanje studenta\n";
  114.     cout << "3 - Izmjena podataka o studentu\n";
  115.     cout << "4 - Pregled podataka o svim studentima\n";
  116.     cout << "5 - Racunanje prosjeka rezultata po ispitu\n";
  117.     cout << "6 - Prikaz najboljeg studenta\n";
  118.     cout << "7 - Prikaz najgoreg studenta\n";
  119.     cout << "8 - Pronalazak studenta po ID-u\n";
  120.     cout << "9 - Sortiranje studenata po uspjehu\n";
  121.     cout << "0 - Izlaz\n\n";
  122. }
  123.  
  124. int search(Student st[100], string id, int itemcount) {
  125.     int found = -1;
  126.    
  127.     for (int i = 0; i < itemcount && found == -1; i++)
  128.     {
  129.         if (st[i].ID == id) {
  130.             found = i;
  131.         }
  132.         else {
  133.             found = -1;
  134.         }
  135.     }
  136.  
  137.     return found;
  138. }
  139.  
  140. void add_student(Student st[100], int &itemcount) {
  141.     cout << "Unesite ID studenta: ";
  142.     cin >> st[itemcount].ID;
  143.     if (search(st, st[itemcount].ID, itemcount) != -1)
  144.     {
  145.         cout << "\nVec postoji student s tim ID-om!\n";
  146.         add_student(st, itemcount);
  147.     }
  148.     else {
  149.         cout << "Unesite ime studenta: ";
  150.         cin >> st[itemcount].ime;
  151.         cout << "Unesite spol studenta: ";
  152.         cin >> st[itemcount].spol;
  153.         cout << "Unesite rezultat 1. kolokvija: ";
  154.         cin >> st[itemcount].rezultati["1. Kolokvij"];
  155.         cout << "Unesite rezultat 2. kolokvija: ";
  156.         cin >> st[itemcount].rezultati["2. Kolokvij"];
  157.         cout << "Unesite rezultat 3. kolokvija: ";
  158.         cin >> st[itemcount].rezultati["3. Kolokvij"];
  159.         cout << "Unesite rezultat zavrsnog ispita: ";
  160.         cin >> st[itemcount].rezultati["Zavrsni ispit"];
  161.         st[itemcount].rezultati["Ukupan rezultat"] =
  162.             (st[itemcount].rezultati["1. Kolokvij"] +
  163.                 st[itemcount].rezultati["2. Kolokvij"] +
  164.                 st[itemcount].rezultati["3. Kolokvij"] +
  165.                 st[itemcount].rezultati["Zavrsni ispit"]) / 4;
  166.        
  167.     }
  168.     itemcount++;
  169. }
  170.  
  171. void show_students(Student st[100], int itemcount) {
  172.     cout << "\nPodaci o studentima: \n\n";
  173.     for (int i = 0; i < itemcount; i++) {
  174.         cout << st[i].ID << " " << st[i].ime << " " << st[i].spol << " ";
  175.         cout << st[i].rezultati["1. Kolokvij"] << " ";
  176.         cout << st[i].rezultati["2. Kolokvij"] << " ";
  177.         cout << st[i].rezultati["3. Kolokvij"] << " ";
  178.         cout << st[i].rezultati["Zavrsni ispit"] << " ";
  179.         cout << st[i].rezultati["Ukupan rezultat"] << "\n";
  180.     }
  181. }
  182.  
  183. void delete_student(Student st[100], int &itemcount) {
  184.     string id;
  185.     int index;
  186.     cout << "Unesite ID studenta: ";
  187.     cin >> id;
  188.     for (int i = 0; i < itemcount; i++) {
  189.         if (st[i].ID == id) {
  190.             index = i;
  191.             break;
  192.         }
  193.     }
  194.     array <Student, 100> temp;
  195.     for (int i = 0; i < index; i++) {
  196.         temp[i] = st[i];
  197.     }
  198.     for (int i = index + 1; i < 100; i++) {
  199.         temp[i - 1] = st[i];
  200.     }
  201.     for (int i = 0; i < 100; i++) {
  202.         st[i] = temp[i];
  203.     }
  204.     itemcount--;
  205. }
  206.  
  207. void izmjena_student(Student st[100], int itemcount) {
  208.     string id;
  209.     int index;
  210.     cout << "Unesite ID studenta: ";
  211.     cin >> id;
  212.     for (int i = 0; i < itemcount; i++) {
  213.         if (st[i].ID == id) {
  214.             index = i;
  215.             break;
  216.         }
  217.     }
  218.     cout << "Unesite ime studenta: ";
  219.     cin >> st[index].ime;
  220.     cout << "Unesite spol studenta: ";
  221.     cin >> st[index].spol;
  222.     cout << "Unesite rezultat 1. kolokvija: ";
  223.     cin >> st[index].rezultati["1. Kolokvij"];
  224.     cout << "Unesite rezultat 2. kolokvija: ";
  225.     cin >> st[index].rezultati["2. Kolokvij"];
  226.     cout << "Unesite rezultat 3. kolokvija: ";
  227.     cin >> st[index].rezultati["3. Kolokvij"];
  228.     cout << "Unesite rezultat zavrsnog ispita: ";
  229.     cin >> st[index].rezultati["Zavrsni ispit"];
  230.     st[index].rezultati["Ukupan rezultat"] =
  231.         (st[index].rezultati["1. Kolokvij"] +
  232.             st[index].rezultati["2. Kolokvij"] +
  233.             st[index].rezultati["3. Kolokvij"] +
  234.             st[index].rezultati["Zavrsni ispit"]) / 4;
  235. }
  236.  
  237. void prosjek_po_ispitu(Student st[100], int itemcount) {
  238.     int izbor;
  239.     cout << "\nIzaberite za sto zelite prosjek (1 - 1. kolokvij,\n";
  240.     cout << "2 - 2. kolokvij, 3 - 3. kolokvij, 4 - Zavrsni ispit,\n";
  241.     cout << "5 - Ukupni rezultat\n";
  242.     cout << "Unesite izbor: ";
  243.     cin >> izbor;
  244.     double prosjek = 0;
  245.     switch (izbor)
  246.     {
  247.     case 1:
  248.         prosjek = 0;
  249.         for (int i = 0; i < itemcount; i++) {
  250.             prosjek += st[i].rezultati["1. Kolokvij"];
  251.         }
  252.         cout << "Prosjek 1. kolokvija je " << prosjek / itemcount << endl;
  253.         break;
  254.     case 2:
  255.         prosjek = 0;
  256.         for (int i = 0; i < itemcount; i++) {
  257.             prosjek += st[i].rezultati["2. Kolokvij"];
  258.         }
  259.         cout << "Prosjek 2. kolokvija je " << prosjek / itemcount << endl;
  260.         break;
  261.     case 3:
  262.         prosjek = 0;
  263.         for (int i = 0; i < itemcount; i++) {
  264.             prosjek += st[i].rezultati["3. Kolokvij"];
  265.         }
  266.         cout << "Prosjek 3. kolokvija je " << prosjek / itemcount << endl;
  267.         break;
  268.     case 4:
  269.         prosjek = 0;
  270.         for (int i = 0; i < itemcount; i++) {
  271.             prosjek += st[i].rezultati["Zavrsni ispit"];
  272.         }
  273.         cout << "Prosjek zavrsnog ispita je " << prosjek / itemcount << endl;
  274.         break;
  275.     case 5:
  276.         prosjek = 0;
  277.         for (int i = 0; i < itemcount; i++) {
  278.             prosjek += st[i].rezultati["Ukupan prosjek"];
  279.         }
  280.         cout << "Ukupni prosjek je " << prosjek / itemcount << endl;
  281.         break;
  282.     default:
  283.         cout << "Niste unijeli valjan odabir!" << endl;
  284.         break;
  285.     }
  286. }
  287.  
  288. void prikaz_najboljeg(Student st[100], int itemcount) {
  289.     int index = 0;
  290.     for (int i = 1; i < itemcount; i++) {
  291.         if (st[i].rezultati["Ukupan rezultat"] > st[i-1].rezultati["Ukupan rezultat"]) {
  292.             index = i;
  293.         }
  294.     }
  295.     cout << "Najbolji student je " << st[index].ime << endl;
  296. }
  297.  
  298. void prikaz_najgoreg(Student st[100], int itemcount) {
  299.     int index = 0;
  300.     for (int i = 1; i < itemcount; i++) {
  301.         if (st[i].rezultati["Ukupan rezultat"] < st[i - 1].rezultati["Ukupan rezultat"]) {
  302.             index = i;
  303.         }
  304.     }
  305.     cout << "Najgori student je " << st[index].ime << endl;
  306. }
  307.  
  308. void pronalazak_po_id(Student st[100], int itemcount) {
  309.     string id;
  310.     int index;
  311.     cout << "Unesite ID studenta: ";
  312.     cin >> id;
  313.     for (int i = 0; i < itemcount; i++) {
  314.         if (st[i].ID == id) {
  315.             index = i;
  316.             break;
  317.         }
  318.     }
  319.     cout << "ID: " << st[index].ID << endl;
  320.     cout << "Ime: " << st[index].ime << endl;
  321.     cout << "Spol: " << st[index].spol << endl;
  322.     cout << "Rezultati: " << endl;
  323.     cout << "1. kolokvij: " << st[index].rezultati["1. kolokvij"] << endl;
  324.     cout << "2. kolokvij: " << st[index].rezultati["2. kolokvij"] << endl;
  325.     cout << "3. kolokvij: " << st[index].rezultati["3. kolokvij"] << endl;
  326.     cout << "Zavrsni ispit: " << st[index].rezultati["Zavrsni ispit"] << endl;
  327.     cout << "Ukupan rezultat: " << st[index].rezultati["Ukupan rezultat"] << endl << endl;
  328. }
  329.  
  330. void soriranje_studenata(Student st[100], int itemcount) {
  331.     Student temp;
  332.     for (int i = 0; i < itemcount; i++) {
  333.         for (int j = i+1; j < itemcount; j++) {
  334.             if (st[i].rezultati["Ukupan rezultat"] < st[j].rezultati["Ukupan rezultat"]) {
  335.                 temp = st[i];
  336.                 st[i] = st[j];
  337.                 st[j] = temp;
  338.             }
  339.         }
  340.     }
  341. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement