vendredi 26 mars 2021

How do i get maximum value from private salary variable?

This is my class named employee, how do I go about getting the maximum value from the salary variable, since the variable is private and can only be accessed using setter getter functions, should I compare the getter functions to get maximum value? Help required!!Also, what can I change in the end condition voidsal() to get my answer?

#include<iostream>
#include<string>
using namespace std;
class employee{
    private:
        string name;
        string designation;
        int age;
        int salary;
    public:
        void set_name(string n)
        {
            name=n;
        }
        string get_name()
        {
            return name;
        }
        void set_des(string d)
        {
            designation=d;
        }
        string get_des()
        {
            return designation;
        }
        void set_age(int a)
        {
            age=a;
        }
        int get_age()
        {
            return age;
        }
        void set_sal(int s)
        {
            salary=s;
        }
        int get_sal()
        {
            return salary;
        }
        int Max=0;
        void sal(){
        for(int j=0;j<5;j++)
        {
            if(salary[Max]<=salary[j])
            {
                Max=j;
            }
        }
    }
};  
    
     ```


Aucun commentaire:

Enregistrer un commentaire