OPPLABS

You might also like

You are on page 1of 6

LAB # 01:

1. Write a function that compute the square of element stored in an


array.
2. Write a C++ code to find multiplication table of a number using for loop
and represents it in a proper format.
3. Write a program that takes options from user to perform addition,
subtraction, multiplication and modulus of integers.

LAB # 02:
1. Create a class heater that contains single integer field temperature.
Define a constructor that takes no parameters. The temperature field
should be set to the value 15in the constructor. Define the members
“warmer” and “cooler”. Whose effect is to be increase / decrease the
value of temperature by 5C respectively. Define an accessor method to
return the value of temperature.
2. Create a class “rectangle”. The class has attributes length, width each
of which default to 1. Provide method that calculate the perimeter and
the area of rectangle. Provide get and set for both length and width.
The set method should verify that length and width are members
greater than or equal to 0.0. {less than 20.0 write a program to test
class rectangle}
3. Create a class called complex for performing arithmetic with complex
numbers. Complex numbers have real part + imaginary part*i.
Write a program to test your class. Use floating point variables to
represent the private data of class. Provide a constructor that enables
an object of this class to be initialized when it is declared . Provide a no
argument constructor with default values in case no initializers are
provided. Provide public methods that perform the following
operations :
a. Add two complex numbers The real parts are added together,
and imaginary parts are added together.
b. Subtract two complex numbers The real part of right operand is
subtracted from real part of left operand and the imaginary part
of right operand is subtracted from imaginary part of left
operand.
c. Print: Complex numbers in the form (a, b) where a is real part
and b is imaginary part.
d. In class complex ,define a multiply method that returns the
product of two complex numbers. Suppose you are trying to
compute the product of two complex numbers a+bi and c+di.
The real part will be ac-bd while the imaginary part will be
ad+bc. Modify complex test to test your solution.

LAB # 03:
1. Create a class called complex that has separate data member for real
and imaginary part. Provide the following member functions for the
class.
a. a no argument constructor to initialize real and imaginary part.
b. A two-argument constructor to initialize the members to values sent
from the calling function at the time of creation of an object.
c. A Member function to display the complex number in X + Yi format.
d. A Member function for addition of two complex numbers.
e. A Member function for multiplication of two complex numbers.
f. A Member function for division of two complex numbers.

2. Create a class call time that has separate in member data for hours
minutes and seconds. Provide the following member functions for this
class.
a. No argument constructor to initialize hours minutes and seconds to
zero.
b. A three-argument constructor to initialize the members to values
sent from the calling function at the time of creation of an object
make sure that valid values are provided for all the data members.
In case of an invalid value set the variable to zero.
c. A Member function show to display time in 11:59:59 format.
d. a function add time for addition of two-time objects each time unit
of one object must add into the corresponding time unit of other
object keep in view the fact that minutes and seconds of so let's see
what resultant should not exceed the maximum limit So 60 here If
any of them do exceed subtract 60 from corresponding unit and add
a 1 to the next higher unit
e. not define all member functions outside the class
f. a main () program should create two initialized time objects and
one that isn't initialized then it should add the two initialized values
together leaving the result in the third time variable finally it should
display the value of this third variable.
3. Create a class called Matrix that represent a 3x3 matrix. This Matrix
contains a two dimensional integer array of size 3x3 provide the
following member functions for this class
a. a no argument constructor for initializing the matrix with zero
values.
b. a one argument constructor to initialize the member matrix to the
matrix sent as an argument from the calling function.
c. an add Matrix function for addition of two matrices.
d. a multiply matrix method for finding the product of two matrices
e. an is equal function for checking the equality of 2 matrices. define
all member functions outside the class.

LAB # 04:
1. Create a class call time that has separate int members for hours
minutes and seconds provide the following member functions for the
class
a. a no argument constructor
b. a three-argument constructor to initialize the data members
c. a member function to display the time in 11:49:20 format
d. an overloaded plus operator for addition of two-time objects
e. overload operators pre and post increment the increment operator
should add 1 to the second unit of time
f. overload the operator pre and post decrement.

2. Create class called Complex for performing arithmetic with complex


numbers write a program to test your class use floating point variables
to represent the private date of the class provide a constructor that
enables an object of this class to be initialized when it is declared
provide a no argument constructor with default values in case No
initializers are provided provide public methods that perform the
following operations.
a. add two complex numbers overload the operator +, += for addition
of two complex numbers
b. subtract two complex numbers overload the operator -, -= for
subtraction of two complex numbers
c. increment complex number incrementing a complex number results
in addition of 1 to the real portion overload both pre and post
incrementation operators
d. decrement complex number decrementing a complex number
results in subtraction of one from the real portion overload both pre
and post decrementation operators
e. print complex numbers in the form (a, b) where a the real part and
b is the imaginary part
f. multiply 2 complex numbers overload * and *= operators for
multiplication of complex numbers.

3. Create a class called Matrix that represents a three cross three matrix
create a constructor for initializing the matrix with zero values create
another overloaded constructor for initializing the matrix to the value
sent from outside overload the + and += operator for addition of two
matrices == operator for checking the equality of 2 matrices and *= for
finding the product of two matrices define All the member functions
outside the class.

LAB # 05:
1. Create a class complex, then derive a class op_comp from class
complex which performs addition and subtraction of two complex
numbers and display them.
2. Create a class called point that has two data members x and y
coordinates of the point provide:
a. A no argument constructor and two argument constructors.
b. Provide separate get and set function for each data member.
c. Provide display function to display the point (x, y).
d. Derive a class circle from the point class that has an additional
member radius.
e. Provide a no argument and one argument constructor of the
derive class.
f. Provide functions to determine the area and circumference of
the circle.

LAB # 06:

1. Write a program using hierarchical inheritance.


2. Create a class employee that has a field for storing the complete
name of employee (first and last name) a field for storing the
identification number of employee and another field for storing
his salary. Provide
a. A no argument constructor for initializing the fields to default
values.
b. A 3-argument constructor for initializing the fields to values sent
from outside. Use strcpy function to copy one string into
another.
c. A setter function (mutator) that sets the values of these fields by
getting input from user.
d. An accessor function to display to display the values of the fields.
Derive three classes from this employee class: Manager, scientist, and
laborer. Manager class has an additional data member of # subordinate.
Scientist class has additional information of # publications. Laborer class is
just similar to employee class. It has no additional capabilities. Drive a class
foreman from laborer class that has an additional data member for storing
the percentage of quotas met by a foreman. Provide appropriate no
argument and n argument constructors for all the classes. Provide the
override getter and setter functions here to input and output all the fields.
Determine whether public, private, or protected inheritance should be used.
3. Create a class student that contains information about a
student’s name, semester, roll number and date of admission. To
store the date of admission, again reuse the date class that you
have already developed. Determine whether you should use
inheritance or composition.
Provide:
a. Provide a no argument constructor for initializing the data
members to some default.
b. A four-argument constructor to initialize the data members
sent from calling function at time of creation.
c. Set input function for setting the status of student.
d. A display function to display the attributes of the student.

LAB # 07:
1. Explain dynamic memory allocation with example.
2. Create a class student this class contains data members for roll no and
Cgpa of a student. Provide
a. A no argument constructor.
b. A two-argument constructor.
c. A setter function for each data member.
d. A getter function for each data member.
e. Create a display function.
f. Let us suppose we want to keep into about average Cgpa of student in
department make appropriate changes in the class to handle extra
info.

LAB # 08:
1. Explain the concept of virtual function and function overriding with
example.

LAB # 09:
1. Create a linked list with three nodes only.
2. Write functions for following operations on linked list.
g. Traversal
h. Node insertion at beginning
i. Node insertion at end
j. Node insertion at nth location.

You might also like