B.E.(CE & IT) 4th Sem - OOP with CPP List of
Lab Exercises
1.Write a program that accepts salary
from user and calculates bonus 10% and display salary, bonus and gross salary.
2.
Write a program that accepts five
numbers and print max and min of them [using if statement].
3.
Enter a number and check whether the
number is positive, negative or zero and print appropriate message [using
ternary operator].
4.
Write a program that accepts a number
of a month print month name respectively [using switch statement].
5.
Write a function named exchange
to interchange the values of two variables.
6.
Create 3 UDF having same name Line to draw line
a. First
will accept one char and one int value as argument.
b. Second
will accept one char as argument.
c. Third
will not accept any argument.
7.
Write
a function called Power () that takes a double value for m
and an int value for P and returns the result as double value.
Use a default argument of 2 for P,
So that if this argument is omitted, the number will be squared. Write a main
() function that gets value from the user to test this function.
8.
Define a class num with public
data member public int a. Create an object of class num, accept value from the
user for the data member. Display the message “The number you entered is
___”.
9.
Define a class num with
following members
int a
seta(int) // function accepts a value as parameter and assigns it
to a.
geta() //returns the value in a.
create an object of class num.
The following statements should be supported.
num n;
n.seta(5);
cout<<”the value of a is “<<n.geta();
10.
Modify the class circle to make the data member private.
Add
the following member functions as public
void setrad(float ) // accepts a value and sets the rad float
getrad() //
returns the radius.
Create
an object ring and calculate and display its area in main().
11.
Define a class facto with
private data members
int n, nfact
set(int) // sets the value only for n.
retn() // returns the value of n
calcnfact() // calculates the n! and assigns it to nfact.
retnfact() // returns the value in nfact.
Create an object of class facto and assign
the value of n. Calculate nfact and display both the values.
12.
W.A.P. that reads n values in an
array, arrange them in ascending/ descending order (Linear Sorting).
13.
W.A.P. that performs two-matrix
addition and subtraction. Print resultant matrix.
14.
Define a class stack with private data members
Int
n[] // define size
for 10 element
Int
tos // keeps track of top of
stack
Settos()
// initializes tos to -1
Void
push(int n) // pushes the value on
the top of the stack
int
pop() // returns the
value that is on the top of the stack
Create an object and implement the stack
operation. Insert few values and pop. Also check for stack underflow and stack overflow.
15.
Write a
program of using a static variable to count how many objects of items are
created.
16.
Define
class named Overload with following
private data members and appropriate get/set functions and constructors:
Int
a;
Display() //display
a
display(char
) // displays the character a
times
Create
an object n1 and invoke all forms of display function [for ex, n1.display(),
n1.display(‘*’)].
17. Define a class person with following private data members
char
name[10]
person() // asks the user to enter
name
welcome() // displays welcome message and
the name.
~person() //displays bye message and the
name.
setname(char
[ ]) //sets the name to the parameter
value.
Create an object child. Display
the welcome message. Change the name in the child object. Does the new name
reflect in the bye message?
1 18.
Define
a class cake with following
private member
int
candleno
char
desc[15] // eg. chocolate,
blackforest, plum
float
wt // weight of the
cake.
cake() // accept
all values from user.
cake(int
, float , char [ ] ) // parameters for
all the data members.
cake(int
, char [ ]) // parameters for candleno
and desc.
cake(char
[ ] , float ) //
parameters for desc and wt.
Create
objects named bday, xmas, marriage,
simple. Invoke the appropriate constructor for each object.
1 19. Create class name with following members and appropriate get/set
functions and constructors:
char
firstname[15]
Create
class surname with following
members and appropriate get/set functions and constructors
char
lastname[15]
fullname() // friend function of class name that displays the
full
name
2 20.
Define class num with
following private data members and appropriate get/set functions and
constructors:
int
a, b
+(num local) // overloaded operator
adds this->a to local.a
create two objects ob1, ob2.
Write program to support the statement
num ob3= ob1+ ob2
2 21.
Define class wtkg with following private data
members and appropriate get/set functions and constructors
float
kilos // à
conversion routine of source class
define
class wtqt with the following private data members and
appropriate get/set functions and constructors
float
quintals // à conversion routine of source class
Create
object goods of class wtkg. Convert the goods of class wtkg to materials of
object of wtqt class.
2 22.
Define a class
cap with members
char
colour [15] //colour of cap
Define
another class bottle that inherits cap
int
size //values can be considered in lts eg. 1,2,5)
Define
another class drinks that inherits bottle
char
contents[10] //eg. Thumbsup, maaza, limca
create
an object softdrink of class drinks. Accept details from the use and display in
the foll format.
Name
of drink:
Size:
lts.
Cap
colour:
2 23.
Create a class
manufacturer with following members and appropriate get/set functions and
constructors.
char comp_name[15] ( company name)
float price; int yy (year of model)
create class car that inherits
manufacturer with following members and appropriate get/set functions and
constructors.
char colour[10], modelno
create class bike that inherits
manufacturer with following members and appropriate get/set functions and
constructors.
float mileage; char modelno
create class owner that inherits car
and bike with appropriate get/set functions and constructors.
char owner_name
int age
void dispvehicles()
create an object of class owner and
display the owner’s as well as his vehicles’ details.
2 24.
Write a program
that reads a text file one by one character and write it into another text
file.
2 25.
Write a program
to swap the numbers
using the concept of function template.