1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <iostream>
#include <map>
#include <string>
#include <new>
using namespace std;
class Student{
int id;
string name, lastname, address;
public:
void SetStudentProperties(int,string,string,string);
void GetInfo(int);
map<int, string> mystudents;
map<int, string>::iterator it;
pair<map<int, string>::iterator,bool> ret;
};
void Student::SetStudentProperties (int id, string name, string lastname, string address){
map<int, string> mystudents;
map<int, string>::iterator it;
pair<map<int, string>::iterator,bool> ret;
string fullinfo= "Name: "+name+"\nSurname: "+lastname+"\nAdress"+address+"\n";
mystudents.insert(pair<int, string>(id,fullinfo));
}
void Student::GetInfo(int id){
map<int, string> mystudents;
string getinfo;
if(mystudents.find(id) == mystudents.end()){
cout<<"ERROR! Unexisting ID.";
}
else{
getinfo=mystudents.find(id)->second;
cout<<getinfo;
}
}
int main(){
string *address1, *name2, *surname;
int id2;
string answer;
do{
int i;
int a;
int *p;
cout<<"Enter quantity of students: ";
cin>>a;
p= new (nothrow) int [a];
address1= new (nothrow)string [a];
name2= new (nothrow)string [a];
surname= new (nothrow)string [a];
Student man[a];
for(i=0;i<a; i++){
cout<<"Student "<<"Id: ";
cin>>p[i];
cout<<"Student "<<"Address: ";
cin>>address1[i];
cout<<"Student "<<"Name: ";
cin>>name2[i];
cout<<"Student "<<"Surname: ";
cin>>surname[i];
}
for(int c=0; c<a;a++){
man[c].SetStudentProperties(p[c], name2[c], surname[c], address1[c]);
}
cout<<"Check for someone? Enter his ID: ";
cin>>id2;
for(int d=0; d<a;d++){
if(id2 == p[d]){
man[d].GetInfo(id2);
}
}
for(i=0; i<a;i++){
delete[] p;
}
cout<<"Do you want to run again?\n1. Yes\n2. No\n";
}while(answer=="1" || answer=="Yes" || answer=="y" ||answer=="Y" || answer=="yes");
return 0;
}
|