Is there any better way to fix below codes in c++::
============
class employer{
string FirstName,
string LastName;
int emplID;
public:
///to set employer
void setemployer(string f,string l,int y)
{
FirstName=f;
LastName=l;
emplID=y;
}
string getFirstName(){
return FirstName;
}
string getLastName(){
return LastName;
}
int getemplID(){
return emplID;
}
....
// This sections is in the main:
int main()
{
string first;
string last;
int emplID;
for(int i=0;i<size;i++)
{
cin>>first>>last>>emplID; ///read data
employer[i].setemployer(first,last,emplID);
}
//code.cpp #include <iostream> #include <iomanip> using namespace std; class employer{ string FirstName; string LastName; int emplID; public: ///to set employer void setemployer(string f,string l,int y) { FirstName=f; LastName=l; emplID=y; } string getFirstName(){ return FirstName; } string getLastName(){ return LastName; } int getemplID(){ return emplID; } }; // This sections is in the main: int main() { string first; string last; int emplID; int size= 5; employer emp; for(int i=0;i<size;i++) { cin>>first>>last>>emplID; ///read data emp.setemployer(first,last,emplID); cout<<"First name = "<<emp.getFirstName()<<endl; cout<<"Last name = "<<emp.getLastName()<<endl; cout<<"Emp ID = "<<emp.getemplID()<<endl; } }
Get Answers For Free
Most questions answered within 1 hours.