#include<iostream> #include<iomanip> #include<vector> #include<cstring> using namespace std; class person{ protected: string first_name; string last_name; string telephone; vector<string> skills; public: person::person(string, string); void person::changedata(int); }; person::person(string a, string b){ string tempskill; skills.clear(); first_name=a; last_name=b; cout<<"\nEnter telephone number: (xxx-xxx-xxxx) ";cin>>telephone; char ans='y'; int r=0; while(ans=='y'){ cout<<"\nEnter skill number "<<r<<": ";cin>>tempskill; ++r;skills.push_back(tempskill); cout<<"\nEnter new skill? (y/n)";cin>>ans; } } void person::changedata(int q){ if(q==1){cout<<"\nCurrent Telephone: "<<telephone; cout<<"\nEnter new number (xxx-xxx-xxxx)";cin>>telephone;} else{cout<<"\nCurrent skills: "; for(int t=0;t<skills.size();++t) cout<<endl<<skills.at(t); char ans='y'; string tempskill; while(ans=='y'){ cout<<"\nEnter new skill: ";cin>>tempskill; skills.push_back(tempskill); cout<<"\nAdd another skill? (y/n)";cin>>ans; }} } class employee:public person{ private: string f_name, l_name, city; int id_no; double salary; public: employee::employee(int, string, string); int returnid(); void display(); string returnfname(); string returnlname(); }; employee::employee(int q,string a, string b):person(a,b){ f_name=a; l_name=b; cout<<"\nEnter Employee's city: ";cin>>city; id_no=q; cout<<"\nEnter employee salary: ";cin>>salary; } string employee::returnfname(){return f_name;} string employee::returnlname(){return l_name;} int employee::returnid(){return id_no;} void employee::display(){ cout<<"\nEmployee id no: "<<id_no; cout<<"\nEmployee name: "<<f_name<<" "<<l_name; cout<<"\nEmployee city: "<<city; cout<<"\nTelephone number: "<<telephone; cout<<"\nSalary: "<<salary; cout<<"\nSkills: "; for (int t=0;t<skills.size();++t) cout<<skills.at(t)<<", "; } int main(){ cout<<setprecision(2)<<setiosflags(ios::fixed)<<setiosflags(ios::showpoint); cout<<"\nJoshua Smith\nCIS326\nQuiz#4"; string fname,lname; int id; vector<employee> roster; roster.clear(); int which; int ans, z=1; while(ans!=0) {cout<<"\n1.New Employee\n2.Display Employee info\n3.Edit Employee Info\n4.Display All Employees\n0.Exit\n"; cin>>ans; switch(ans){ case 0: system("pause"); exit(1); break; case 1: cout<<"\nEnter ID no: ";cin>>id; for(int t=0;t<roster.size();++t) if(roster[t].returnid()==id)++z; if(z>1){cout<<"\nEmployee already exists!";break;} else{cout<<"\nEnter First name: ";cin>>fname; cout<<"\nEnter Last Name: ";cin>>lname; z=roster.size(); roster.push_back(employee(id,fname,lname)); //roster[z]=employee(id,fname,lname); break;} cout<<"\ncycle complete"; break; case 2: z=-1; cout<<"\nEnter ID no to display: ";cin>>id; for(int t=0;t<roster.size();++t) if(roster[t].returnid()==id) z=t; if(z==-1){cout<<"\nEmployee does not exist!";} else{roster[z].display();} break; case 3: z=-1; cout<<"\nEnter ID no to edit: ";cin>>id; for(int t=0;t<roster.size();++t) if(roster[t].returnid()==id) z=t; if(z==-1){cout<<"\nEmployee does not exist!";} else{ cout<<"\nWould you like to change 1: telephone or 2: skills?";cin>>which; roster[z].changedata(which);} break; case 4: for(int t=0;t<roster.size();++t) cout<<"\nID: "<<roster[t].returnid()<<"\nName: "<<roster[t].returnfname()<<" "<<roster[t].returnlname()<<endl; break;}} system("pause"); return 0; } |