fork download
  1. //organized code(week2 problem 3)
  2.  
  3.  
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6.  
  7. class Employee{
  8. string name;
  9. int year;
  10. string address;
  11. public:
  12. void set_all(string x,int y,string z){
  13. name=x;
  14. year=y;
  15. address=z;
  16.  
  17. }
  18. void display(){
  19.  
  20. cout<<setw(10)<<left<<name<<setw(10)<<left<<year<<setw(10)<<left<<address<<endl;
  21.  
  22.  
  23. }
  24. void print(){
  25.  
  26. cout<<"Welcome "<<name<<" to our office at "<<address<<"!" << endl;
  27. // cout << "Welcome " + name + " to our office at " + address + "!" << endl;
  28. }
  29.  
  30. };
  31. int main(){
  32. Employee e[3];
  33. string a,b;
  34. int c;
  35. for(int i=0;i<3;i++){
  36. cout<<"Enter Name of employee "<<i<<" :";
  37.  
  38. getline(cin,a);
  39. cout<<"Enter joining year of employee "<<i<<" :";
  40. cin>>c;
  41. cin.ignore();
  42. cout<<"Enter Address of employee "<<i<<" :";
  43. getline(cin,b);
  44. e[i].set_all(a,c,b);
  45. }
  46.  
  47. cout<<setw(10)<<left<<"Name"<<setw(10)<<left<<"Year of joining"<<setw(10)<<left<<"Address"<<endl;
  48.  
  49. for(int i=0;i<3;i++){
  50. e[i].display();
  51. }
  52. cout<<"\n";
  53. for(int i=0;i<3;i++){
  54. e[i].print();
  55. }
  56.  
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Enter  Name of employee 0 :Enter joining year of employee 0 :Enter Address of employee 0 :Enter  Name of employee 1 :Enter joining year of employee 1 :Enter Address of employee 1 :Enter  Name of employee 2 :Enter joining year of employee 2 :Enter Address of employee 2 :Name      Year of joiningAddress   
          0                   
          0                   
          0                   

Welcome  to our office at !
Welcome  to our office at !
Welcome  to our office at !