Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <list>
- #include <vector>
- #include <map>
- #include <algorithm> // std::find
- using namespace std;
- // помоћне функције
- static bool loadStudents(string fileName);
- static void printStudentNames();
- static void printStudentIndexNums();
- static void printStudentNamesAndIndexNums();
- static void addStudent();
- static void makeIndexToNameMap();
- static void printIndexToNameMap();
- static void printDesiredIndex(int x);
- static void makeNameToIndexMap();
- static void printDesiredName(string name);
- static void printSpecial();
- static void replace();
- // глобалне променљиве
- static list<string> studentNames;
- static vector<int> studentIndexNums;
- static map<int, string> studentIndexToNameMap;
- static map<string, int> studentNameToIndexMap;
- int main(int argc, char* argv[])
- {
- if (argc != 4)
- {
- cout << "Niste uneli potrebne argumente za pokretanje programa!" << endl;
- cout << "Argumenti komandne linije treba da budu:" << endl;
- cout << "1. apsolutna ili relativna putanja do datoteke: \"baza_studenata.txt\"" << endl;
- cout << "2. ime studenta" << endl;
- cout << "3. prezime studenta" << endl;
- exit(-1);
- }
- bool retVal;
- retVal = loadStudents(argv[1]);
- if (retVal == false)
- {
- cout << "Greska prilikom ucitavanja ulazne datoteke!\n" << endl;
- exit(-1);
- }
- printStudentNames();
- printStudentIndexNums();
- printStudentNamesAndIndexNums();
- addStudent();
- printStudentNamesAndIndexNums();
- makeIndexToNameMap();
- printIndexToNameMap();
- int x;
- cout << "Unesite broj indeksa: ";
- cin >> x;
- printDesiredIndex(x);
- makeNameToIndexMap();
- string name;
- string surname;
- // TODO: име и презиме студента преузети из прослеђених аргумената командне линије
- name = argv[2];
- surname = argv[3];
- string fullName;
- // TODO: формирај од имена и презимена један знаковни низ
- fullName = name + " " + surname;
- printDesiredName(fullName);
- // Додатни
- printSpecial();
- replace();
- cout << endl << endl;
- return 0;
- }
- bool loadStudents(string fileName)
- {
- // учитава датотеку "baza_studenata.txt"
- ifstream inputFile(fileName);
- if (inputFile.is_open() == false)
- {
- cout << endl << "GRESKA! Pogresno ime datoteke" << endl << endl;
- return false;
- }
- string ime;
- string prezime;
- int brojIndeksa;
- string ime_prezime;
- do
- {
- inputFile >> ime;
- inputFile >> prezime;
- inputFile >> brojIndeksa;
- // место за код
- // TODO: направите од имена и презимена један знаковни низ: надаље "име" се односи на име и презиме
- // TODO: попуните studentNames са именима, а studentIndexNums са бројевима индекса
- ime_prezime = ime + " " + prezime;
- studentNames.push_back(ime_prezime);
- studentIndexNums.push_back(brojIndeksa);
- } while (inputFile.eof() == false);
- return true;
- }
- void printStudentNames()
- {
- list<string>:: iterator it;
- for (it=studentNames.begin();it!=studentNames.end();it++)
- cout<<"Imena svih studenata su: "<<*it<<endl;
- // TODO: имплементирати
- }
- void printStudentIndexNums()
- {
- // studentIndexNums
- vector<int>:: reverse_iterator it;
- for(it=studentIndexNums.rbegin();it!=studentIndexNums.rend();it++)
- cout<<"Brojevi indexa studenata u obrnutom redosledu su: "<<*it<<endl;
- // штампа на екран студентске индексе али у обрнутом редоследу
- // TODO: имплементирати
- }
- void printStudentNamesAndIndexNums()
- {
- // штампа на екран име студента праћено бројем индекса
- // користити информације у studentNames и studentIndexNums
- // TODO: имплементирати
- list<string>::iterator it1;
- vector<int>::iterator it2;
- for (it2=studentIndexNums.begin(), it1=studentNames.begin();it1!=studentNames.end(),it2!=studentIndexNums.end();it1++,it2++){
- cout<<"Studenti sa njihovim brojevima indexa su: " <<*it1 << *it2<<endl;
- }
- }
- void addStudent()
- {
- string studentsName = "Marko Kraljevic";
- int studentsIndexNum = 54321;
- list<string>::iterator it1;
- vector<int>::iterator it2;
- it1=find(studentNames.begin(),studentNames.end(),"Mali Radojica");
- it2=find(studentIndexNums.begin(),studentIndexNums.end(),12345);
- // myvector.insert ( it , 200 );
- studentNames.insert(it1,"Marko Kraljevic");
- studentIndexNums.insert(it2,54321);
- // TODO: додати студента Краљевића Марка тачно иза Малог Радојице (12345)
- }
- void makeIndexToNameMap()
- {
- // TODO: направити мапу пресликавања бројева индекса на имена
- // kljuc se preslikava na vrednost
- // f(x) = x^2
- // f(2) = 4
- // x -> y
- // f(2) = 4
- //mapica[1323] -> dobijemo Malog Radojicu
- //map<int,string> mapa;
- //studentIndexToNameMap vec definisano!!! samo korisitmo!!!!
- // 1 for petlja koja ide kroz vektor i listu ovde ubaciti
- list<string>::iterator it1;
- vector<int>::iterator it2;
- for (it2=studentIndexNums.begin(), it1=studentNames.begin();it1!=studentNames.end(),it2!=studentIndexNums.end();it1++,it2++){
- studentIndexToNameMap.insert( pair<int, string>(*it2, *it1) ) ;
- }
- //
- }
- void printIndexToNameMap()
- {
- // TODO: одшампати на екран садржај IndexToName мапе
- // cout << it->first << it->second
- }
- void printDesiredIndex(int x)
- {
- // TODO: наћи име студента у мапи на основу броја индекса, и одшампати име на екран
- // претпоставити да је број индекса увек валидан
- // it = find(mapa.begin(), mapa.end(), x);
- // cout << it->second << endl;
- }
- void makeNameToIndexMap()
- {
- // TODO: направити мапу пресликавања имена на бројеве индекса
- // isto .x.x.x
- }
- void printDesiredName(string name)
- {
- // TODO: наћи индекс студента на основу имена, и одшампати име на екран
- // претпоставити да је могућ унос невалидног имена
- // it = find(mapa, mapa, name);
- // if ( it == mapa.end() ) // nema ga
- }
- void printSpecial()
- {
- // TODO: коришћењем итератора проћи кроз целу мапу studentIndexToNameMap
- // и исписати на екран парове индекс и име_презиме студената, за све студенте
- // осим последњег. За последњег студента исписати само име и презиме.
- /*
- for(it = begin; it != mapa.end(); it++ ){
- if ( it == mapa.end() -1 ) { // poslednji!
- {
- cout << it->second;
- }
- else {
- cout << it->first << it-> second;
- }
- }
- */
- }
- void replace()
- {
- // TODO: коришћењем метода знаковног низа у задатој реченици заменити зарезе размацима
- string str = "Sve,zareze,izmedju,reci,zameniti,razmacima";
- cout << endl << "Recenica koju treba prepraviti je:";
- cout << endl << str << endl;
- // TODO: имплементирати замену
- replace(str.begin(), str.end(), ' ', ',');
- cout << endl << "Ispravljena recenica:";
- cout << endl << str << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement