CS 1262 OBJECT ORIENTED PROGRAMMING LABORATORY 0 0 3 100
AIM
To implement dynamic memory allocation, constructors, destructors, friend function, inheritance and interfaces.
1. String concatenation using dynamic memory allocation concept.
2. Implementation of arithmetic operations on complex numbers using
constructor overloading.
3. To read a value of distance from one object and add with a value in another
object using friend function.
4. Implementation of + and - operator overloading and
implementation of addition operation of octal object with integer using operator overloading.
5. Implementation of addition and subtraction of two polynomial objects using
operator overloading.
6. Managing bank account using inheritance concept.
7. To compute the area of triangle and rectangle using inheritance and virtual
function.
8. Writing simple programs in Java.
9. Use of interfaces in Java.
10. Developing packages in Java.
P = 45 Total = 45
Detailed Syllabus
1. String concatenation using dynamic memory allocation concept
Aim
To implement the string concatenation function by using dynamic memory
allocation concept.
Objective
To concatenate two or more strings into one string by allocating memory to objects at the time of their construction.
Exercises
1. Create class STRING with two constructors. The first is an empty constructor, which allows declaring an array of strings. The second constructor initializes the length of the strings, and allocates necessary space for the string to be stored and creates the string itself.
2. Create a member function to concatenate two strings.
3. Estimate the combined length of the strings to be joined and allocates memory for the combined string using new operator and then creates the same using the string functions strcpy() and strcat().
4. Display the concatenated string.
Software Equipment Required
TURBO C++ - 30 nodes
Hardware Equipment Required
PC (preferably P-IV) - 30 nos
2. Implementation of arithmetic operations on complex numbers using
constructor overloading
Aim
To implement arithmetic operations on complex numbers using constructor overloading
Objective
To represent complex numbers and to perform arithmetic operations on complex numbers using overloaded constructors in a class.
Exercises
1. Create class COMPLEX with three constructor to perform constructor overloading. The first constructor takes no arguments which is used to create objects which are not initialized.the second takes one argument which is used to create objects and initialize them and the third takes two arguments which is also used to create objects and initialize them to specific values.
2. Declare friend function.
4. Overload arithmetic operators +,-,*,/ to perform arithmetic operations on the complex numbers.
5. Display the results of each arithmetic operations.
Software Equipment Required
TURBO C++ - 30 nodes
Hardware Equipment Required
PC - 30 nos
2. To read a value of distance from one object and add with a value in another object using friend function
Aim
To read a value of distance from one object and add with a value in another object using friend function.
Objective
To create two classes and store the values of distance and to read the value from one class and add with a value in another object using friend function.
Exercises
1. Create two classes AB and AC and store the value of distances.
2. Declare friend function.
3. Read the value from the classes.
4. Perform addition to add one object of AB with another object of AC.
5. Display the result of addition.
Software Equipment Required
TURBO C++ - 30 nodes
Hardware Equipment Required
PC - 30 nos
4. Implementation of + and - operator overloading and implementation of addition operation of octal object with integer using operator overloading
Aim
To implement + and – operator overloading and to implement addition operation of octal object with integer using operator overloading.
Objective
To display the number of days between two valid dates and the date after a number of days from a valid date by overloading the operators + and -.
To represent octal numbers and to add an octal object with integer by overloading operator ‘+’.
Exercises
1. Create a class called DATE and define two member functions get-data and
display-result.
2. Accept two valid dates in the form of dd/mm/yyyy using get-data.
3. Overload operators + and – to display the number of days between two valid dates using display-result.
4. Repeat step 3 to display the date after a number of days from a valid date using display-result.
1. Create class OCTAL for representing octal numbers.
2. Create a constructor to implement OCTAL h=x where x is an integer.
3. Overload operator ‘+’ to perform the integer addition with an OCTAL object like int y= h+k (where h is an OCTAL object and k is an integer).
4. Display the resultant integer value y.
Software Equipment Required
TURBO C++ - 30 nodes
Hardware Equipment Required
PC - 30 nos
5. Implementation of addition and subtraction of two polynomial objects using
operator overloading
Aim
To implement addition and subtraction operations of two polynomials and display using << operator overloading. Objective To add and subtract two POLYNOMIAL objects and to display results by overloading the operator <<. Exercises 1. Create a class called POLYNOMIAL with constructors to create polynomial objects and to initialize with specific values. 2. Create member functions to perform addition and subtraction of two polynomials. 3. Overload operator << to display the results of addition and subtraction operations on two polynomials. 4. Display the results. Software Equipment Required TURBO C++ - 30 nodes Hardware Equipment Required PC - 30 nos 6. Managing bank account using inheritance concept Aim To manage the account information of the customer using inheritance concept. Objective To maintain and update the customer account specific information using inheritance concept. Exercises 1. Create a class with the following member variables. Customer name, account number and account type. 2. Create the derived classes with following member variables. • for current account information Balance, Deposit and withdrawal amount • for savings account information Balance and Deposit amount 3. Write a member function to get the Deposit and withdrawal amount and to update the balance information for current account. 4. Write a member function to get the Deposit amount and to update the balance information for saving account. 5. Write a member function to Display the balance information for respective account type. Software Equipment Required TURBO C++ - 30 nodes Hardware Equipment Required PC - 30 nos 7. To compute the area of triangle and rectangle using inheritance and virtual function Aim To implement derived class and virtual function concepts. Objective To calculate the area of triangle and rectangle using derived classes and display the result using virtual function. Exercises 1. Create a base class SHAPE. 2. Derive two sub classes TRIANGLE and RECTANGLE from the base class SHAPE. 3. Define member functions get_data() and display_area(). 4. Find out the area of triangle and rectangle and display the result using display_area(). 5. Make display_area() as a virtual function. Software Equipment Required TURBO C++ - 30 nodes Hardware Equipment Required PC - 30 nos 8. Writing simple programs in Java Aim To generate random numbers using simple Java program Objective To generate random numbers using built in function random(). Exercises 1. Create a class called rand with variable declaration and includes header file math. 2. Generate random numbers using built in function random(). 3. Display the result. Software Equipment Required JDK 1.3 - 30 nodes Hardware Equipment Required PC - 30 nos 9. Use of Interfaces in Java Aim To calculate area of rectangle and circle using interfaces. Objective To create two classes and store the values of distance and to read the values from one class and add with a value in another object using friend function Exercises 1. Create two classes AB and AC and store the value of distances. 2. Declare friend function. 3. Read the value from the classes. 4. Perform addition to one object of AB with another object of AC. 5. Display the result of addition. Software Equipment Required JDK 1.3 - 30 nodes Hardware Equipment Required PC - 30 nos 10. Developing packages in Java Aim To find out the total score of the student using packages. Objective To design the packages with interface and to find out the total score of a student using packages. Exercises 1. Create a package called PACK1 to contain the class STUDENT with member functions to obtain the subject marks. 2. Create another package called PACK2 to contain interface SPORTS with variables and method declaration. 3. Implement the class STUDENT with interface to calculate the total score including sports and subjects. 4. Display the results. Software Equipment Required JDK 1.3 - 30 nodes Hardware Equipment Required PC - 30 nos
AIM
To implement dynamic memory allocation, constructors, destructors, friend function, inheritance and interfaces.
1. String concatenation using dynamic memory allocation concept.
2. Implementation of arithmetic operations on complex numbers using
constructor overloading.
3. To read a value of distance from one object and add with a value in another
object using friend function.
4. Implementation of + and - operator overloading and
implementation of addition operation of octal object with integer using operator overloading.
5. Implementation of addition and subtraction of two polynomial objects using
operator overloading.
6. Managing bank account using inheritance concept.
7. To compute the area of triangle and rectangle using inheritance and virtual
function.
8. Writing simple programs in Java.
9. Use of interfaces in Java.
10. Developing packages in Java.
P = 45 Total = 45
Detailed Syllabus
1. String concatenation using dynamic memory allocation concept
Aim
To implement the string concatenation function by using dynamic memory
allocation concept.
Objective
To concatenate two or more strings into one string by allocating memory to objects at the time of their construction.
Exercises
1. Create class STRING with two constructors. The first is an empty constructor, which allows declaring an array of strings. The second constructor initializes the length of the strings, and allocates necessary space for the string to be stored and creates the string itself.
2. Create a member function to concatenate two strings.
3. Estimate the combined length of the strings to be joined and allocates memory for the combined string using new operator and then creates the same using the string functions strcpy() and strcat().
4. Display the concatenated string.
Software Equipment Required
TURBO C++ - 30 nodes
Hardware Equipment Required
PC (preferably P-IV) - 30 nos
2. Implementation of arithmetic operations on complex numbers using
constructor overloading
Aim
To implement arithmetic operations on complex numbers using constructor overloading
Objective
To represent complex numbers and to perform arithmetic operations on complex numbers using overloaded constructors in a class.
Exercises
1. Create class COMPLEX with three constructor to perform constructor overloading. The first constructor takes no arguments which is used to create objects which are not initialized.the second takes one argument which is used to create objects and initialize them and the third takes two arguments which is also used to create objects and initialize them to specific values.
2. Declare friend function.
4. Overload arithmetic operators +,-,*,/ to perform arithmetic operations on the complex numbers.
5. Display the results of each arithmetic operations.
Software Equipment Required
TURBO C++ - 30 nodes
Hardware Equipment Required
PC - 30 nos
2. To read a value of distance from one object and add with a value in another object using friend function
Aim
To read a value of distance from one object and add with a value in another object using friend function.
Objective
To create two classes and store the values of distance and to read the value from one class and add with a value in another object using friend function.
Exercises
1. Create two classes AB and AC and store the value of distances.
2. Declare friend function.
3. Read the value from the classes.
4. Perform addition to add one object of AB with another object of AC.
5. Display the result of addition.
Software Equipment Required
TURBO C++ - 30 nodes
Hardware Equipment Required
PC - 30 nos
4. Implementation of + and - operator overloading and implementation of addition operation of octal object with integer using operator overloading
Aim
To implement + and – operator overloading and to implement addition operation of octal object with integer using operator overloading.
Objective
To display the number of days between two valid dates and the date after a number of days from a valid date by overloading the operators + and -.
To represent octal numbers and to add an octal object with integer by overloading operator ‘+’.
Exercises
1. Create a class called DATE and define two member functions get-data and
display-result.
2. Accept two valid dates in the form of dd/mm/yyyy using get-data.
3. Overload operators + and – to display the number of days between two valid dates using display-result.
4. Repeat step 3 to display the date after a number of days from a valid date using display-result.
1. Create class OCTAL for representing octal numbers.
2. Create a constructor to implement OCTAL h=x where x is an integer.
3. Overload operator ‘+’ to perform the integer addition with an OCTAL object like int y= h+k (where h is an OCTAL object and k is an integer).
4. Display the resultant integer value y.
Software Equipment Required
TURBO C++ - 30 nodes
Hardware Equipment Required
PC - 30 nos
5. Implementation of addition and subtraction of two polynomial objects using
operator overloading
Aim
To implement addition and subtraction operations of two polynomials and display using << operator overloading. Objective To add and subtract two POLYNOMIAL objects and to display results by overloading the operator <<. Exercises 1. Create a class called POLYNOMIAL with constructors to create polynomial objects and to initialize with specific values. 2. Create member functions to perform addition and subtraction of two polynomials. 3. Overload operator << to display the results of addition and subtraction operations on two polynomials. 4. Display the results. Software Equipment Required TURBO C++ - 30 nodes Hardware Equipment Required PC - 30 nos 6. Managing bank account using inheritance concept Aim To manage the account information of the customer using inheritance concept. Objective To maintain and update the customer account specific information using inheritance concept. Exercises 1. Create a class with the following member variables. Customer name, account number and account type. 2. Create the derived classes with following member variables. • for current account information Balance, Deposit and withdrawal amount • for savings account information Balance and Deposit amount 3. Write a member function to get the Deposit and withdrawal amount and to update the balance information for current account. 4. Write a member function to get the Deposit amount and to update the balance information for saving account. 5. Write a member function to Display the balance information for respective account type. Software Equipment Required TURBO C++ - 30 nodes Hardware Equipment Required PC - 30 nos 7. To compute the area of triangle and rectangle using inheritance and virtual function Aim To implement derived class and virtual function concepts. Objective To calculate the area of triangle and rectangle using derived classes and display the result using virtual function. Exercises 1. Create a base class SHAPE. 2. Derive two sub classes TRIANGLE and RECTANGLE from the base class SHAPE. 3. Define member functions get_data() and display_area(). 4. Find out the area of triangle and rectangle and display the result using display_area(). 5. Make display_area() as a virtual function. Software Equipment Required TURBO C++ - 30 nodes Hardware Equipment Required PC - 30 nos 8. Writing simple programs in Java Aim To generate random numbers using simple Java program Objective To generate random numbers using built in function random(). Exercises 1. Create a class called rand with variable declaration and includes header file math. 2. Generate random numbers using built in function random(). 3. Display the result. Software Equipment Required JDK 1.3 - 30 nodes Hardware Equipment Required PC - 30 nos 9. Use of Interfaces in Java Aim To calculate area of rectangle and circle using interfaces. Objective To create two classes and store the values of distance and to read the values from one class and add with a value in another object using friend function Exercises 1. Create two classes AB and AC and store the value of distances. 2. Declare friend function. 3. Read the value from the classes. 4. Perform addition to one object of AB with another object of AC. 5. Display the result of addition. Software Equipment Required JDK 1.3 - 30 nodes Hardware Equipment Required PC - 30 nos 10. Developing packages in Java Aim To find out the total score of the student using packages. Objective To design the packages with interface and to find out the total score of a student using packages. Exercises 1. Create a package called PACK1 to contain the class STUDENT with member functions to obtain the subject marks. 2. Create another package called PACK2 to contain interface SPORTS with variables and method declaration. 3. Implement the class STUDENT with interface to calculate the total score including sports and subjects. 4. Display the results. Software Equipment Required JDK 1.3 - 30 nodes Hardware Equipment Required PC - 30 nos
EmoticonEmoticon