Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<iomanip>
- #include<string.h>
- #include<fstream>
- #include<conio.h>
- #include<windows.h>
- //Ahmet Durmic
- //Harun Kaknjo
- using namespace std;
- int n,izbor,option;
- double m;//ukupni bodovi
- double um;//bodovi za prolaznost
- double _max=0;
- double _min=INT_MAX;
- double _max2=INT_MIN;
- int br=0;
- int br2=0;
- void ispis(){
- cout.width(85);
- cout << "------------------------------------------------------------------------" << endl;
- cout.width(25);
- cout<< "\t\t\t\t SIDE MENU" << endl ;
- cout.width(85);
- cout<< "------------------------------------------------------------------------" << endl;
- cout << " ID\tOPTION" << endl;
- cout << " 1)\tStudent sa maksimalnim brojem bodova" << endl << " 2)\tStudent sa minimalnim brojem bodova" << endl;
- cout << " 3)\tStudenti koji su polozili predmet"<<endl<<" 4)\tStudenti koji nisu polozili predmet"<<endl;
- cout << " 5)\tSortiranji niz studenata po broju bodova"<<endl<<" 6)\tUnesi nove studente"<<endl<<" 7)\tIspisi podatake o studentu na osnovu unesenog predmeta i imena\n"<<" 8)\tSortirani niz studenata po broju bodova na osnovu unesenog predmeta\n"<<" 9)\tProlaznost[%]"<<endl;
- cout << " 10)\ Main menu";
- }
- void cls(){
- system("pause");
- system("cls");
- ispis();
- }
- void main_menu(){
- cout.width(85);
- cout << "---------------------------------------------------------------------------" << endl;
- cout.width(25);
- cout<< "\t\t\t\tMAIN MENU" << endl ;
- cout.width(85);
- cout<< "----------------------------------------------------------------------------" << endl;
- cout << " ID\tOPTION" << endl;
- cout << " 0)\tIspis unesenih studenata iz datoteke "<<endl;
- cout << " 1)\tUnos studenata u datoteku" << endl << " 2)\tSIDE MENU" << endl;
- cout << " 3)\tSacuvaj stanje i izadi "<<endl;
- }
- void cls_main(){
- system("pause");
- system("cls");
- main_menu();
- }
- struct prosjek{
- double pp,dp;//prva parcijala,druga parcijala
- };
- struct pamtime{
- char ime1[25],ime2[25];
- };
- struct student{
- char predmet[30];
- char ip[25];
- prosjek unos;
- pamtime pi;
- };
- void podaci_o_ispitu(){
- cout<<"----------------------------------------------------------------------\n";
- cout<<"[UKUPNI BROJ BODOVA MORA BITI VECI OD 55% DA BI STUDENT POLOZIO ISPIT]\n\n";
- cout<<"Unesite ukupan broj bodova [ 1.] i [ 2.] parcijalnog ispita: ";
- cin>>m;
- while(!cin) {
- cout << "Pogresan unos!.\nUnesite ukupan broj bodova [ 1.] i [ 2.] parcijalnog ispita: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> m;
- }
- cout<<endl;
- um=m/1.8;
- cout<<" [UKUPNI BROJ BODOVA MORA BITI VECI OD "<<um<<"]\n";
- cout<<"----------------------------------------------------------------------\n";
- cout<<endl;
- cin.ignore(10000,'\n');cin.clear();
- }
- student unesi_podatke(){
- student s;
- cout<<"Unesite predmet: ";cin.getline(s.predmet,30);
- while(!cin) {
- cout << "Pogresan unos!.\nUnesite predmet: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin.getline(s.predmet,30);
- }
- podaci_o_ispitu();
- cout<<"Unesite ime i prezime: ";cin.getline(s.ip,25);
- while(!cin) {
- cout << "Pogresan unos!.\nUnesite ime i prezime: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin.getline(s.ip,25);
- }
- cout<<"Unesite bodove sa [ 1.] parcijalnog ispita: ";cin>>s.unos.pp;
- while(!cin||s.unos.pp>m/2) {
- cout << "Pogresan unos!.\nUnesite bodove sa [ 1.] parcijalnog ispita: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin>>s.unos.pp;
- }
- cout<<"Unesite bodove sa [ 2.] parcijalnog ispita: ";cin>>s.unos.dp;
- while(!cin||s.unos.dp>m/2) {
- cout << "Pogresan unos!.\nUnesite bodove sa [ 2.] parcijalnog ispita: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin>>s.unos.dp;
- }
- // sacuvaj_stanje("s.dat",s);
- return s;
- }
- void ispisi_max(student A[],int a){
- int maxI;
- for(int i=0;i<a;i++){
- if(A[i].unos.pp+A[i].unos.dp>_max){
- _max=A[i].unos.pp+A[i].unos.dp;
- strcpy(A->pi.ime1,A[i].ip);
- br++;
- for(int i=1;i<br;i++){
- if(i==br){
- maxI=i;
- strcpy(A->pi.ime1,A[maxI].ip);
- }
- }
- }
- }
- cout<<"Student sa maximalnim brojem bodova je "<<A->pi.ime1<<" i ima ukupno ["<<_max<<"] bodova";
- }
- void ispisi_min(student A[],int a){
- int minI;
- for(int i=0;i<a;i++){
- if(A[i].unos.pp+A[i].unos.dp<_min){
- _min=A[i].unos.pp+A[i].unos.dp;
- strcpy(A->pi.ime2,A[i].ip);
- br2++;
- for(int i=1;i<br2;i++){
- if(i==br2){
- minI=i;
- strcpy(A->pi.ime2,A[minI].ip);
- }
- }
- }
- }
- cout<<"Student sa minimalnim brojem bodova je "<<A->pi.ime2<<" i ima ukupno ["<<_min<<"] bodova";
- }
- void ispisi_polozili(student A[],int a){
- int br1=0;
- int br2=0;
- cout<<"Studenti koji su zadovoljili kriterije su\n ";
- for(int i=0;i<a;i++){
- if(A[i].unos.pp+A[i].unos.dp>um){
- br1++;
- cout<<i+1<<". "<<A[i].ip<<endl;
- }else{
- br2++;
- if(br2==a){
- cout<<"[Niti jedan student nije zadovoljio ocekivani kriteriji]"<<endl;
- }
- }
- }
- }
- void ispisi_nisupolozili(student A[],int a){
- int br1=0;
- int br2=0;
- cout<<"Studenti koji nisu zadovoljili kriterije su\n ";
- for(int i=0;i<a;i++){
- if(A[i].unos.pp+A[i].unos.dp<um){
- br1++;
- cout<<i+1<<". "<<A[i].ip<<endl;
- }else{
- br2++;
- if(br2==a){
- cout<<"[Svi studenti su zadovoljili ocekivane kriterije]"<<endl;
- }
- }
- }
- }
- void rotiraj(student &x,student &y){
- student temp=x;
- x=y;
- y=temp;
- }
- void sortiraj(student A[],int a){
- for(int i=0;i<a-1;i++){
- for(int j=0;j<a-1;j++){
- if((A[j].unos.pp+A[j].unos.dp)<(A[j+1].unos.pp+A[j+1].unos.dp)){
- rotiraj(A[j],A[j+1]);
- }
- }
- }
- }
- void ispisi_sortirano(student A[],int a){
- sortiraj(A,a);
- cout<<"==================================================================\n";
- for(int i=0;i<a;i++){
- cout<<" "<<i+1<<". "<<A[i].ip<<" - "<<" PREDMET "<<"["<<A[i].predmet<<"]"<<" "<<(A[i].unos.pp+A[i].unos.dp)<<" [BODA]"<<endl;
- }
- cout<<"==================================================================\n";
- }
- void ispisi_prolaznost(student A[], int a){
- float prolaznost;
- float br3=0;
- for(int i=0;i<a;i++){
- if(A[i].unos.pp+A[i].unos.dp>um){
- br3++;
- }
- }
- prolaznost=(br3/a)*100;
- cout <<"Prolaznost iznosi ["<<prolaznost<<"%]";
- }
- void ispisi_studenta(student A){
- cout<<"==============================================\n";
- cout<<"\t"<<A.ip<<" "<<(A.unos.pp+A.unos.dp)<<" [BODOVA]"<<endl;
- cout<<"==============================================\n";
- }
- void pretraga_po_imenu(student *A, char *B, int a){
- student uneseni;
- for(int i=0;i<a;i++){
- if(stricmp((A+i)->ip,B)==0){
- uneseni=A[i];
- }
- }
- ispisi_studenta(uneseni);
- }
- void pretraga_po_predmetu(student *A, char *B, int a){
- student predmet;
- for(int i=0;i<a;i++){
- if(stricmp((A+i)->predmet,B)==0){
- predmet=A[i];
- }
- }
- }
- void pretraga_po_predmetu_isti_predmet(student *A, char *B, int a){
- student predmet2;
- cout<<"=====================================\n";
- for(int i=0;i<a;i++){
- if(stricmp((A+i)->predmet, B)==0){
- predmet2 = A[i];
- cout<<" "<<predmet2.ip<<" "<<(predmet2.unos.pp+predmet2.unos.dp)<<" [BODOVA]"<<endl;
- }
- }
- cout<<"=====================================\n";
- }
- void spisak_unesenih_predmeta(student *A,int a){
- cout<<" Spisak unesenih predmeta\n";
- cout<<"=================================\n";
- for(int i=0;i<a;i++){
- cout<<"\t "<<(A+i)->predmet<<endl;
- }
- cout<<"=================================\n";
- }
- void sacuvaj_stanje(student s[], int n){
- std::ofstream _broj("broj_prijava.dat", std::ios::binary);
- _broj.write(reinterpret_cast<char*>(&n), sizeof(int));
- _broj.close();
- std::ofstream pisanje("studenti.dat", std::ios::binary);
- for(int i(0); i<n; ++i){
- pisanje.write(reinterpret_cast<char*>(&s[i]), sizeof(student));
- }
- pisanje.close();
- }
- int main(){
- cout<<endl;
- int brMAIN=0;// Brojac za unos 1
- int brMAIN2=0;//Brojac za provjeru stanja datoteke
- std::ifstream broj("broj_prijava.dat", std::ios::binary);
- n=0;
- if(!broj){
- Sleep(1);
- } else{
- broj.read(reinterpret_cast<char*>(&n), sizeof(int));
- broj.close();
- }
- student s[30];
- std::ifstream citanje("studenti.dat", std::ios::binary);
- citanje.seekg(0, std::ios::end);
- if (citanje.tellg() == 0){
- }else{
- brMAIN2++;
- }
- citanje.seekg(0, std::ios::beg);
- for(int i(0); i<n; ++i){
- citanje.read(reinterpret_cast<char*>(&s[i]), sizeof(student));
- }
- citanje.close();
- cls_main();
- cout << endl << "---Odaberite opciju: "; cin >> option;cout<<endl;
- while(!cin||option>3) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> option;
- }
- cin.clear();cin.ignore(10000,'\n');
- system("cls");
- do{
- if(option==0){
- ispisi_sortirano(s,n);
- cout<<endl;
- cls_main();
- cout << endl << "---Odaberite opciju: "; cin >> option;cout<<endl;
- while(!cin||option>3) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> option;
- }
- cin.clear();cin.ignore(10000,'\n');
- system("cls");
- }
- ///////////////////////////////////////////////////////////////////////
- if(option==1){
- if(brMAIN>=1||brMAIN2>=1){
- cout<<"=========================================================\n";
- cout <<"Opcija nije moguca, iz sigurnosnih razloga za dodavanje \n novih studenata pritisnite opciju 2 zatim opciju 6"<<endl;
- cout<<"=========================================================\n";
- }else{
- cout<<"==========================\n";
- cout<<"Unesite broj studenata: ";
- cin>>n;
- while(!cin) {
- cout << "Pogresan unos!. Unesite broj studenata: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> n;
- }
- cout<<"==========================\n";
- cin.clear();cin.ignore(10000,'\n');
- for(int i=0;i<n;i++){
- system("cls");
- cout<<"Unesite podatke o "<<i+1<<". studentu\n";
- s[i]=unesi_podatke();
- cin.clear();cin.ignore(10000,'\n');
- cout<<endl;
- }
- sacuvaj_stanje(s,n);
- }
- brMAIN++;
- cls_main();
- cout << endl << "---Odaberite opciju: "; cin >> option;cout<<endl;
- while(!cin||option>3) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> option;
- }
- cin.clear();cin.ignore(10000,'\n');
- system("cls");
- }
- ////////////////////////////////////////////////////////////////////////
- if(option==2){
- cls();
- cout << endl << "---Odaberite opciju: "; cin >> izbor;cout<<endl;
- while(!cin||izbor>10) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> izbor;
- }
- cin.ignore(10000,'\n');cin.clear();
- system("cls");
- do{
- if(izbor==1){
- system("cls");
- ispisi_max(s,n);
- cout<<endl;
- cls();
- cout << endl << "---Odaberite opciju: "; cin >> izbor;cout<<endl;
- while(!cin||izbor>10) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> izbor;
- }
- cin.clear();cin.ignore(10000,'\n');
- system("cls");
- }
- ////////////////////////////////////////////////////////////////////////
- if(izbor==2){
- system("cls");
- ispisi_min(s,n);
- cout<<endl;
- cls();
- cout << endl << "---Odaberite opciju: "; cin >> izbor;cout<<endl;
- while(!cin||izbor>10) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> izbor;
- }
- cin.clear();cin.ignore(10000,'\n');
- system("cls");
- }
- ////////////////////////////////////////////////////////////////////////
- if(izbor==3){
- system("cls");
- ispisi_polozili(s,n);
- cout<<endl;
- cls();
- cout << endl << "---Odaberite opciju: "; cin >> izbor;cout<<endl;
- while(!cin||izbor>10) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> izbor;
- }
- cin.clear();cin.ignore(10000,'\n');
- system("cls");
- }
- ////////////////////////////////////////////////////////////////////////
- if(izbor==4){
- system("cls");
- ispisi_nisupolozili(s,n);
- cout<<endl;
- cls();
- cout << endl << "---Odaberite opciju: "; cin >> izbor;cout<<endl;
- while(!cin||izbor>10) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> izbor;
- }
- cin.clear();cin.ignore(10000,'\n');
- system("cls");
- }
- ////////////////////////////////////////////////////////////////////////
- if(izbor==5){
- system("cls");
- ispisi_sortirano(s,n);
- cout<<endl;
- cls();
- cout << endl << "---Odaberite opciju: "; cin >> izbor;cout<<endl;
- while(!cin||izbor>10) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> izbor;
- }
- cin.clear();cin.ignore(10000,'\n');
- system("cls");
- }
- ////////////////////////////////////////////////////////////////////////
- if(izbor==6){
- system("cls");
- cout<<"Unesite podatke o novom studentu:\n";
- s[n]=unesi_podatke();
- n=n+1;
- sacuvaj_stanje(s,n);
- cout<<endl;
- cls();
- cout << endl << "---Odaberite opciju: "; cin >> izbor;cout<<endl;
- while(!cin||izbor>10) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> izbor;
- }
- cin.clear();cin.ignore(10000,'\n');
- system("cls");
- }
- ////////////////////////////////////////////////////////////////////////
- if(izbor==7){
- int pred=0;
- int im=-1;
- system("cls");
- char pretraga[25];
- char clas[30];
- spisak_unesenih_predmeta(s,n);
- cout<<"Unesite predmet: ";
- cin.getline(clas,30);
- for(int i=0;i<n;i++){
- if(stricmp( (s+i)->predmet,clas )!=0){
- }else{
- pred++;
- }
- }
- while(pred<1){
- pred = 0;
- cout<<"[Unijeli ste nepostojeci predmet]\nUnesite predmet: ";
- cin.getline(clas,30);
- for(int i=0;i<n;i++){
- if(stricmp( (s+i)->predmet,clas )!=0){
- }else{
- pred++;
- }
- }
- }
- pretraga_po_predmetu(s, clas, n);
- cout <<"Unesite ime za ispis: ";
- cin.getline(pretraga,25);
- for(int i=0;i<n;i++){
- if(stricmp( (s+i)->ip,pretraga )==0){
- im++;
- }else{
- }
- }
- while(im==-1){
- im = -1;
- cout<<"[Unijeli ste nepostojece ime]\nUnesite ime za ispis: ";
- cin.getline(pretraga,25);
- for(int i=0;i<n;i++){
- if(stricmp( (s+i)->ip,pretraga )==0){
- im++;
- }else{
- }
- }
- }
- pretraga_po_imenu(s, pretraga, n);
- cout<<endl;
- cls();
- cout << endl << "---Odaberite opciju: "; cin >> izbor;cout<<endl;
- while(!cin||izbor>10) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> izbor;
- }
- cin.clear();cin.ignore(10000,'\n');
- system("cls");
- }
- ////////////////////////////////////////////////////////////////////////
- if(izbor==8){
- int pred=0;
- system("cls");
- char clas2[30];
- system("cls");
- spisak_unesenih_predmeta(s,n);
- cout<<"Unesite predmet: ";
- cin.getline(clas2,30);
- for(int i=0;i<n;i++){
- if(stricmp( (s+i)->predmet,clas2 )!=0){
- }else{
- pred++;
- }
- }
- while(pred<1){
- pred = 0;
- cout<<"[Unijeli ste nepostojeci predmet]\nUnesite predmet: ";
- cin.getline(clas2,30);
- for(int i=0;i<n;i++){
- if(stricmp( (s+i)->predmet,clas2 )!=0){
- }else{
- pred++;
- }
- }
- }
- sortiraj(s,n);
- pretraga_po_predmetu_isti_predmet(s,clas2,n);
- cout<<endl;
- cls();
- cout << endl << "---Odaberite opciju: "; cin >> izbor;cout<<endl;
- while(!cin||izbor>10) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> izbor;
- }
- cin.clear();cin.ignore(10000,'\n');
- system("cls");
- }
- ////////////////////////////////////////////////////////////////////////
- if(izbor==9){
- system("cls");
- ispisi_prolaznost(s,n);
- cout<<endl;
- cls();
- cout << endl << "---Odaberite opciju: "; cin >> izbor;cout<<endl;
- while(!cin||izbor>10) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> izbor;
- }
- cin.clear();cin.ignore(10000,'\n');
- system("cls");
- }
- ////////////////////////////////////////////////////////////////////////
- if(izbor==10){
- cls_main();
- cout << endl << "---Odaberite opciju: "; cin >> option;cout<<endl;
- while(!cin||option>3) {
- cout << "Pogresan unos!. Unesite broj: ";
- cin.clear(); // Oporavak toka
- cin.ignore(10000, '\n'); // Brisanje spremnika
- cin >> option;
- }
- cin.clear();cin.ignore(10000,'\n');
- system("cls");
- }
- } while(izbor!=10);
- }
- }while(option!=3);
- sacuvaj_stanje(s,n);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement