0% found this document useful (0 votes)
33 views

Lab 1 Class and Object

The document provides examples of 6 different C++ classes: 1. An Area class that calculates the area of a circle given its radius. 2. A Student class that stores student data like roll number, marks in 5 subjects, and age. 3. A Fraction class that represents fractions and allows input, output, and evaluation of fractions. 4. An Employee class that calculates employee net salary based on basic pay, DA, and IT deductions and stores details of 5 employees. 5. A DList class that implements a double linked list with functions to insert, get, print, and get size of elements. 6. An extension of the DList class with additional functions to

Uploaded by

Gump Forest
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Lab 1 Class and Object

The document provides examples of 6 different C++ classes: 1. An Area class that calculates the area of a circle given its radius. 2. A Student class that stores student data like roll number, marks in 5 subjects, and age. 3. A Fraction class that represents fractions and allows input, output, and evaluation of fractions. 4. An Employee class that calculates employee net salary based on basic pay, DA, and IT deductions and stores details of 5 employees. 5. A DList class that implements a double linked list with functions to insert, get, print, and get size of elements. 6. An extension of the DList class with additional functions to

Uploaded by

Gump Forest
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab 1 Class and Object

1. Create a class called Area as shown below. Implement the member


functions and write the driver code (main function) to call an object
of the Area class and perform calculation.

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
};

2. Create a class called Student with following data members:


int roll_no;
int marks[5];
int age;
Implement the following member functions:
void getdata ();
void tot_marks ();
Your main function looks like that:
void main()
{
student stu;
stu.getdata() ;
stu.tot_marks() ;
}

3. Create a class called Fraction as shown below and implement the


member functions and write the driver code to test the program.

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();
};

5. Create a class called DList as shown below. Implement the member


functions and write the driver code (main function) to call an object
of the DList class and perform calculation.

const int MAX = 10;

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
};

6. Modify above code by adding the following member functions to the


DList class.

bool Delete(int n); // delete the nth element of the list


// return true for success, false if n not a valid position

double Sum(); // return the sum of the elements of the list


double Average(); // return the average of the elements of the list
double Max(); // return the maximum value in the list
void Clear(); // reset the list to empty
int Greater(double x); /* count how many values in the list are
greater than x. Return the count.*/

You might also like