Answer to Question #259486 in C++ for wahab

Question #259486

A class named “Teachers” holds information like teacher code, name, gender, year of joining. Write a program to create five hundred objects (Array of teacher objects) of teacher and enter some data into it through setters. Make getters and setters for all employee information. Then ask the user to enter current year. Display the names of those employees whose tenure is 10 or more than 10 years according to the given current year only using getters.

1
Expert's answer
2021-11-01T01:58:57-0400


#include <iostream>


using namespace std;


class Teachers
{
    private:
        int teacher_code;
        string name;
        string gender;
        int year_of_joining;
    public:
        void setTeacherCode(int c){
            teacher_code=c;
        }
        
        void setName(string n){
            name=n;
        }
        void setGender(string g){
            gender=g;
        }
        void setYear(int y){
            year_of_joining=y;
        }
        int getTeacherCode(){
            return teacher_code;
        }
        string getName(){
            return name;
        }
        string getGender(){
            return gender;
        }
        int getYear(){
            return year_of_joining;
        }
};
int main()
{
    Teachers t[500];
    int diff[500];
    int cur_year;
    cout<<"\nEnter current year: ";
    cin>>cur_year;
    cout<<"\nEnter teachers details: ";
    for(int i=0;i<500;i++){
        cout<<"\nEnter details for teacher "<<(i+1);
        int code;
        cout<<"\nTeacher code: ";
        cin>>code;
        t[i].setTeacherCode(code);
        
        string name;
        cout<<"\nName: ";
        cin>>name;
        t[i].setName(name);
        
        string gender;
        cout<<"\nGender: ";
        cin>>gender;
        t[i].setGender(gender);
        
        int year;
        cout<<"\nYear of joining: ";
        cin>>year;
        
        int diff[i]=cur_year-year;
        t[i].setYear(year);
        
    }
    
    for(int i=0;i<500;i++){
        if(diff[i]>=10){
            cout<<"\nName: "<<t[i].getName();
        }
    }


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS