Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- #include<vector>
- #include <list>
- #include<algorithm>
- #include <fstream>
- using namespace std;
- static vector<int> indexNumbers;
- static list<string> studentNames;
- static map<int,string> mapNumbersToStrings;
- static map<string,int> mapStringsToNumbers;
- void addStudent();
- void loadStudent();
- void addStudentSpecial();
- void printIndexNumbers();
- void printStudentNames();
- void printindexAndNames();
- void makeIndexToNameMap();
- void printIndexToNameMap();
- void makeNameToIndexMap();
- int main(int argc, char *argv[]) {
- //addStudent();
- //addStudentSpecial();
- //loadStudent();
- //printIndexNumbers();
- //printStudentNames();
- //printindexAndNames();
- //makeIndexToNameMap();
- //printIndexToNameMap();
- //makeNameToIndexMap();
- //printDesiredIndex(string name);
- //printDesiredName(int x);
- addStudent();
- addStudent();
- makeIndexToNameMap();
- printIndexToNameMap();
- return 0;
- }
- void loadStudent() {
- ifstream inputFile("baza_studenata.txt");
- if(inputFile.bad()) {
- cout<<"bad_file_name!"<<endl;
- return;
- }
- int index;
- string ime;
- string prezime;
- do{
- inputFile>>ime;
- inputFile>>prezime;
- inputFile>>index;
- ime = ime + " "+ prezime;
- indexNumbers.push_back(index);
- studentNames.push_back(ime);
- }while(inputFile.eof()==false);
- }
- void printIndexNumbers(){
- vector<int>::reverse_iterator it1;
- for(it1 = indexNumbers.rbegin(); it1!= indexNumbers.rend(); ++it1) {
- cout<< *it1<<endl;
- }
- }
- void printStudentNames(){
- list<string>::iterator it2;
- for(it2 = studentNames.begin(); it2!=studentNames.end(); ++it2) {
- cout<< *it2<<endl;
- }
- }
- void printindexAndNames(){
- vector<int>::iterator it1;
- list<string>::iterator it2;
- for(it1 = indexNumbers.begin(), it2 = studentNames.begin(); it1!= indexNumbers.end(),it2!=studentNames.end();
- ++it1, ++it2) {
- cout<< *it2 <<" "<<*it1<<endl;
- }
- }
- void addStudent() {
- int x;
- cout<<"Broj indexa: " <<endl;
- cin>>x;
- string ime,prezime;
- cout<<"Ime: "<<endl;
- cin>>ime;
- cout<<"Prezime: "<<endl;
- cin>>prezime;
- indexNumbers.push_back(x);
- ime = ime+" "+prezime;
- studentNames.push_back(ime);
- }
- void addStudentSpecial() {
- //metoda koja dodaje Marka Kraljevica(23456) odmah iza indexa 12345
- string ime = "Marko Kraljevic";
- int index = 23456;
- vector<int>::iterator it1;
- list<string>::iterator it2;
- for(it1 = indexNumbers.begin(), it2 = studentNames.begin(); it1!= indexNumbers.end(),it2!=studentNames.end();
- ++it1, ++it2) {
- if(*it1==12345) {
- ++it1; ++it2;
- studentNames.insert(it2,ime);
- indexNumbers.insert(it1,index);
- break;
- }
- }
- }
- void makeIndexToNameMap(){
- //napraviti mapu preslikavanja brojeva indeksa na imena
- vector<int>::iterator it1;
- list<string>::iterator it2;
- for(it1 = indexNumbers.begin(), it2 = studentNames.begin(); it1!=indexNumbers.end(),it2!=studentNames.end();
- ++it1, ++it2) {
- mapNumbersToStrings[*it1] = *it2; //izlazak iz funkcije,unistavanje mape!
- }
- }
- void printIndexToNameMap(){
- map<int,string>::iterator it3;
- for(it3 =mapNumbersToStrings.begin(); it3!=mapNumbersToStrings.end(); ++it3 ) {
- cout<< it3->first<<" "<<it3->second<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement