Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Datum {
- int _dan;
- int _mjesec;
- int _godina;
- void unos(int d, int m, int g){
- _dan = d;
- _mjesec = m;
- _godina = g;
- }
- void ispis(){
- cout << _dan << "/" << _mjesec << "/" << _godina << endl;
- }
- };
- void unos(Datum &datum){
- cout << "Unesite dan: ";
- cin >> datum._dan;
- cout << "Unesite mjesec: ";
- cin >> datum._mjesec;
- cout << "Unesite godinu: ";
- cin >> datum._godina;
- }
- void ispis(Datum datum){
- cout << datum._dan << "/" << datum._mjesec << "/" << datum._godina << endl;
- }
- struct Student
- {
- char _IB[9];
- char _ime[10];
- char _prezime[15];
- Datum _datumRodjenja;
- void unos(char ime[], char prezime[], Datum datum){
- strcpy_s(_ime, strlen(ime)+1, ime);
- strcpy_s(_prezime, strlen(prezime) + 1, prezime);
- _datumRodjenja = datum;
- }
- void ispis(){
- cout << "Ime studenta: " << _ime << endl;
- cout << "Prezime studenta: " << _prezime << endl;
- cout << "IB: " << _IB << endl;
- _datumRodjenja.ispis();
- }
- };
- void unos(Student &s){
- char tmpIme[10], tmpPrez[15];
- cout << "Unesite ime studenta: ";
- cin.ignore();
- cin.getline(tmpIme, 10);
- int velIme = strlen(tmpIme)+1;
- strcpy_s(s._ime, velIme, tmpIme);
- cout << "Unesite prezime studenta: ";
- cin.getline(tmpPrez, 15);
- int velPrez = strlen(tmpPrez) + 1;
- strcpy_s(s._prezime, velPrez, tmpPrez);
- //cin.ignore()
- cout << "Unesite dan, mjesec i godinu za datum rodjenja studenta" << endl;
- unos(s._datumRodjenja);
- //int d, m, g;
- //
- //cin >> d >> m >> g;
- //unos(d,m,g)
- }
- void ispis(Student s){
- cout << "Ime studenta: " << s._ime << endl;
- cout << "Prezime studenta: " << s._prezime << endl;
- cout << "IB studenta; " << s._IB << endl;
- cout << "Datum rodjenja studenta: ";
- ispis(s._datumRodjenja);
- //s._datumRodjenja.ispis();
- }
- //• prilikom incijalizacije IB za svakog studenata upotrijebite funkciju : (prvi IB je 170001)
- //char * naredniBrojIndeksa(char * posljednji); funkcija vraća naredni IB, a šaljete joj zadnji iskorišteni IB;
- int brojIndeksaGlobal = 180000;
- char * naredniBrojIndeksa(char * posljednji){
- int size = 9;
- char *noviIndeks = new char[size];
- strcpy_s(noviIndeks, size, "IB");
- char temp[10];
- _itoa_s(brojIndeksaGlobal, temp, 10);
- strcat_s(noviIndeks, size, temp);
- brojIndeksaGlobal++;
- return noviIndeks;
- }
- //• pronaći i ispisati studenta koji je rođen na datum kojeg zada korisnik; upotrijebite funkciju :
- //Student * pretragaPoDatumuRodjenja(Student *, int, Datum); funkcija vraća pokazivač na studenta koji zadovoljava traženi uvjet;
- bool IstiDatum(Datum d1, Datum d2)
- {
- if (d1._godina == d2._godina && d1._mjesec == d2._mjesec && d1._dan == d2._dan)
- return true;
- return false;
- }
- Student* pretragaPoDatumuRodjenja(Student *n, int vel, Datum datum){
- Student temp;
- int lok = -1;
- bool pronadjeni = false;
- for (size_t i = 0; i < vel; i++)
- {
- if (IstiDatum(n[i]._datumRodjenja, datum)) {
- lok = i;
- return&n[lok];
- pronadjeni = true;
- }
- }
- if(pronadjeni==false){
- cout << "Nije pronadjen student s tim datumom..." << endl;
- return nullptr;
- }
- }
- void main(){
- //Datum danas;
- //danas.unos(14, 4, 2018);
- //Student s1;
- //s1.unos("Emir", "Sator", danas);
- //strcpy_s(s1._IB, 10, naredniBrojIndeksa(""));
- //s1.ispis();
- //Student s2;
- //s1.unos("Emir", "Pajic", danas);
- //strcpy_s(s2._IB, 10, naredniBrojIndeksa(""));
- //s2.ispis();
- int v;
- cout << "Unesite velicinu niza" << endl;
- cin >> v;
- Student *niz = new Student[v];
- for (int i = 0; i < v; i++)
- {
- unos(niz[i]);
- }
- for (int i = 0; i < v; i++)
- {
- strcpy_s(niz[i]._IB, 10, naredniBrojIndeksa(""));
- }
- for (int i = 0; i < v; i++)
- {
- ispis(niz[i]);
- }
- Datum jucer;
- int d, m, g;
- cout << "Unesite dan, mjesec i godinzu za pretragu" << endl;
- cin >> d >> m >> g;
- jucer.unos(d, m, g);
- if (pretragaPoDatumuRodjenja(niz,v,jucer) != nullptr){
- cout << "Studenti rodjeni na datum kojeg je korinisk unio je: " << endl;
- ispis(*(pretragaPoDatumuRodjenja(niz, v, jucer)));
- }
- system("pause>0");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement