Lab 1 Class and Object
Lab 1 Class and Object
class Area {
float r, area;
public:
void input() ; // input value for the data members
void findArea(); // Calculate area of the circle
void display() ; // Display area of the circle
};
class Fraction
{
private:
int numerator; // no restrictions
int denominator; // Invariant: denominator != 0
public:
void Input(); // input a fraction from keyboard.
void Show(); // Display a fraction on screen
int GetNumerator();
int GetDenominator();
void SetValue(int n, int d); // set the fraction's value through
parameters
double Evaluate(); // Return the decimal value of a fraction
};
4. Create a class called Employee as shown below. Net Salary of the
employee is calculated as (basic+da)-it; Store and show the details
of 5 employee.
Note: here data members are private, therefore you can’t access
the basic, da and it . Inside show_emp_details() call
fund_net_salary function.
class Employee
{
int emp_number;
char emp_name[20];
float emp_basic;
float emp_da;
float emp_it;
public:
void get_emp_details();
float find_net_salary(float basic, float da, float it);
void show_emp_details();
};
class DList
{
private:
double array[MAX];
int current; // number of stored items (max is 10)
public:
bool Insert(double item); // inserts item into list (if room)
double GetElement(unsigned int n); // returns element at
index n
void Print(); // prints the list
int GetSize(); // returns number of elements in list
};