You are on page 1of 3

Lab 10

Objects as Function Argument, Array of objects


Q1) ) Write the definition for a class called Rectangle that has data member length as
integer and width as integer. The class has the following member functions:

a. void set(int, int) to give value to object


b. void disp() to display the lenght and width of the rectangle
c. int area() to calculate the area of the Rectangle
d. int Perimeter() to calculate the perimeter of the Rectangle
e. Define a default constructor ,a constructor with two parameters and a
destructor

Q2) A complex number consists of two parts a real part and an imaginary part. Define a
class Complex whose private members are of integer type and represent a real and an
imaginary part

a) The class should have a set function to set the values of the private members

void set(int , int);

b) The class should have a display function to display the private members

void display();

c) The class should have a default constructor

d) to add the two complex numbers there should be an add function , define it outside the
class

Complex add(Complex);

e) define a default constructor and a destructor


Name Object Oriented Programming TE-53 Sec

Q3)The class declaration for a Phone Book class is given below. Implement the class
functions.

class PhoneBook

private:

char name[30];

char address[50];

char city[20];

double phoneNumb;

public:

void insert(char[], char[], char[], double);

//This function is called when a new entry has to be made into the phonebook. The
name, address, city and phone number are passed to the function and are assigned
to the calling objects members.

void update(char[],char[],char[],double);

//This function is called when a record has to be updated. The new values for the
members are given as arguments.

void display ();

//this function is called to display all data members of the invoking object

};

a. Do the following in main:


i. Display the information of all 4 objects
ii. Call the update function on the 4 objects.
iii. Display the information of all updated objects
b. Write a function called total_count() which gives the value of the total number of
objects created at any time
Name Object Oriented Programming TE-53 Sec

c. In the main function, create an array of PhoneBook Objects which can hold 6
PhoneBook Objects. The syntax for making an array of objects is given below:

const int SIZE = 6;

PhoneBook list[SIZE];

Write a search function (outside the class) that takes from user a string, representing a
name. An array of PhoneBook objects is passed to it as an argument. That string is
matched with the name attribute of all objects. If the object with required name is
found, the record is displayed.

void Search(PhoneBook []);

Q4) Modify the above program to add constructors.

PhoneBook();

// constructor sets name to , address to , city to and numb to 0. Use the


strcpy function to copy character arrays

PhoneBook(char n[], char a[], char c[], double nm);

// constructor sets name to n, address to a, city to c and numb to nm.

You might also like