You are on page 1of 10

C++ Programming Lab Assignments

Variable and Identifier( DAY 1, 2)


1. Write a program to display output using a single cout statement.
Subject Marks
---------------------------
Mathematics 90
Computer 77
Chemistry 69

2. Write a program which accept temperature in Farenheit and print it in centigrade.


3. Write a program to accept three DIGIT number and display the middle digit.
4. Write a program to accept a character and display its ASCII value.
5. Write a program which accepts days as integer(ex.
integer 7856 days) and display total number of years,
months and days in it.
6. Write a program to check whether the given number is positive or negative using ternary operator (? : )
7. In a company an employee is paid as under:
unde
If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary
and DA = 90% of basic salary.
If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500
and DA = 98% of basic salary.
If the employee's salary is input by the user write a program to find his gross salary.
GS=DA+HRA
8. If the ages of Ram, Lakshman, sita are input by the user, write a program to determine the youngest of
three.
9. Write a program to find the sum and average of one dimensional integer array of 15 elements.
elements
10. Write a program to count the number of words in a String.
11. Write a program to convert a String in lowercase.
12. Write a program to convert a String in uppercase.

Function, Function Overload (static


static polymorphism),
polymorph inline, default arguments ( Day 3)
13. What is the difference between call by value and call by reference in a user defined function in C++?
14. What is the difference between local variable and global variable?
15. What is Reference Variable?

Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: info@universalinformatics.com
info@universalinform
C++ Programming Lab Assignments

16. Write a program that lets the user perform arithmetic operations on two numbers. Your program must be
menu driven, allowing the user to select the operation (+, -,, *, or /) and input the numbers. Furthermore,
your program must consist of following functions:
a). Function showChoice: This function shows the options to the user and explains how to enter data.
b). Function add: This function accepts two number as arguments and returns sum.
c). Function subtract: This function accepts two number as arguments and returns their difference.
d). Function mulitiply: This function accepts
accepts two number as arguments and returns product.
e). Function divide: This function accepts two number as arguments and returns quotient.

17. Write a program to convert KM, CM or inch feet into meters using function.
18. Write a program to return absolute value of variable types integer and float using function overloading.
19. Write a program to calculate Simple Interest using function with interest rate as default argument.
20. What is inline function, it's types, merit's and constraints. Explain
xplain with example?

Basic C++, OOPs Intro, Structure , Class and Object(Day


Object 4,5,6)
21. Difference between c and c++?
+?
22. What are the major differences between Object Oriented and Procedural Programming approaches?
23. What are the basic concepts of OOP?
24. Difference between object oriented and object based?
25. Create
reate a class to calculate addition of two numbers (data member) using following member functions.
Create members function
1. init - to input numbers from user
2. add - to calculate and display result

26. Create
reate a class to calculate factorial with one data member to store the number
and another to store factorial value. Create members function
1. init - to input number from user
2. fact - to calculate factorial
3. display- to display answer

27. Write a program to define a class Student with the following specification
Private members of class student
---------------------------------
admno integer

Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: info@universalinformatics.com
info@universalinform
C++ Programming Lab Assignments
sname 20 character
eng, math, science float
total float

ctotal() (a Function to calculate eng + math + science with float return type.)

Public member function of class student


takeData() (a Function to accept values for admno, sname, eng, science and invoke ctotal() to calculate
total.)
showData() (a Function to display all the data members on the screen.)

28. Write a program to Define a class TEST in C++ with following description:
Private Members
-------------------------------
TestCode of type integer
Description of type string
Candidates of type integer (total candidates appearing)
CenterReqd (number of centers required) of type integer

A member function calcCenter() to calculate and return the number of centers.(Students


centers per center is not
more than 50).

Public Members
- A function schedule() to allow user to enter values for TestCode, Description, Candidates & call
function calcCenter() to calculate the number of Centres
- A function displayTest() to allow user to view the content of of a Test

29. Create a class account with data


dat members (accno, name, balance). Create
reate function members
a) getdata()
() to accept member data from user
b) deposit(float money) to deposit money in account
c) withdraw(float money) to withdraw money from account
d)display() to show account info

30. Store six user’s account information using class created in above problem and calculate
- total money deposited in all accounts

Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: info@universalinformatics.com
info@universalinform
C++ Programming Lab Assignments
- list all account number with balance greater than 1000

Constructor and Destructor, static, this, Scope Resolution Operator(Day


Operator 7,8,9)

31. What is a constructor? What are its features?


32. Write a program to calculate the area of a rectangle, which accepts
accepts value from the user and displays it.
Use
se Constructor to initialize members.
33. Create and use copy constructor for above problem.
34. Create a class Employee with members (empid, salary).Create
reate following functions
a) calcTax()
ax() with employee object as argument and print tax on salary with
12.5% tax rate;
b) max() which accepts two employee as objects
objects and return the employee with
higher salary

35. What is a purpose of destructor?


36. Explain the use of this pointer in CPP.

37. Create a class Student with data member (rno, fees and static member totalFees).Create
totalFees). parameterized
constructor (using this pointer) which update the totalFees and create member function which prints the
total fees collected of all the students.

38. Create a Class Number with two member function.


a) showNum() :- which displays the first number using this
b) dispNum() :- which displays the
t second number using this
39. Create a Class Calculate with two data members(num,num1)Declare two member function.
a) a) create parameterized constructor which takes two integer value and initialize members with
this pointer.
b) sum() :- which displays the number
numb using this
40. Create class Plot with data members length and breadth. Create constructor. Create member functions
a) float calcArea()->to
to return area of plot
b) Plot compare(Plot p)-> which takes Object of Plot class as argument and return 0 if area of argument
object is same as current object, 1 if current object area is > then argument object and -1 if area of
argument object is > then current object.

Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: info@universalinformatics.com
info@universalinform
C++ Programming Lab Assignments

41. Create a class Product with data members (pid, pname, amount) and declare and define the member
function with the help of Scope Resolution Operator
1. acceptProduct()-- which accept product details.
2. displayProduct() -- display product information.
3. Create Destructor.
42. Create a class Student (rollno, name) which keeps track of how many objects are created of the class.
Every time object of the class is created, it should display number of total objects created.
43. Create a class TCSEmployee
Employee with data members name,
nam eid, salary and companyName to store
information of All TCS’s Employee
Employe records. Create functions which accept these members value and
display them. Now u need to manage that companyName should be assign only once, no matter how
many number of object of this class created.

44. Create a class Box with data members (boxlabel,


( length , width, height) and function that calculate and
return volume of that box. Now create a function comapre that take an object of Box class as
parameters and show boxlabel of object who’s volume is greater?. you need to create two object of Box
class to compare.
45. Create a class Max with one data member(v)
member and functions
a) getV(): which iss use to read variable value
b) display()
() : to display value
c) check() : which return an object of Max class and find maximum value using one objects as
argument.(use this pointer to return an object).

Friend Function, Friend Class and Operator Overloading(


Overload Day 10, 11, 12)
46. What is Friend
iend Function? Why it is needed?
47. Why this pointer is not used inside friend function?
48. Write a program to swap two numbers using friend function.
49. Write a program to swap two numbers using friend class.
50. What iss the use of operator overloading?
overload List down the operators which can’t be
overloaded.
51. Create a class Order withh data members
member (oid, name, qty).Overload ++
(increment) and --(decrement)
(decrement) operator to increase/decrease quantity by 1.
52. A complex number have two parts(imaginary and real) eg. 3+5i. (5 is imaginary part). Create a class
Complex to store real and imaginary part. and apply binary + and - operator to add and subtract two
complex numbers.

Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: info@universalinformatics.com
info@universalinform
C++ Programming Lab Assignments
eg. 3+5i 3+5i
+( 2+6i) -( 2+8i)
===== ======
5+11i 1-3i;
53. Create a class Fraction to store numerator and denominator and apply binary + and - operator to add
and subtract two Fractions numbers.
eg. a/b + c/d = (a*d+b*c)/b*d and. a/b - c/d = (a*d-b*c)/b*d

54. Apply binary + operator on above Fraction class using friend function
55. Create a class Distance with data members (feet and inch).Write a program to add two object of
Distance class using friend function operator overloading.

56. Create a class Alpha and Beta. Both classes contain one data member
member of type integer. Write a program
to find which class data member is greater using friend function.

Inheritance (Day 13,14,15)


57. What is Inheritance? List its advantages.
58. Explain types of inheritance with diagram
59. Explain the IS A and HAS A class relationships.
60. What a derived class inherits or doesn’t inherit?
61. Create a class FourWheeler with two data member(category and amount).Declare
amount).Declare two members
functions.
a)char getCategory() :- which returns category
b)int getamount():- which returns amount

Create another class Car with two data members (brand and model).Declare two member function:-
function:
a)getDetail():- which accepts the brand, model, category and amount of a Car
b)showDetail():- which displays the category, amount, brand and model.

62. Create three classes


Faculty (facultyname, department, salary)
FullTimeFaculty (basic, allowance) inherits class Faculty
PartTimeFaculty (hour, rate) inherits class Faculty

Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: info@universalinformatics.com
info@universalinform
C++ Programming Lab Assignments
Create a function for accepting input for FullTimeFaculty and PartTimeFaculty
Faculty but salary should not be
accepted. Salary is calculated on the basis of (basic+allowance) for FullTimeFaculty and (hour*rate) for
PartTimeFaculty. Also create function for displaying data for any faculty.

63. Create a class Rectangle with two protected data members (length and breadth).Declare a Constructor
which accepts length and breadth of a Rectangle
Create another class Area which calculates the area of a Rectangle.
Create another class Perimeter which calculates the perimeter of a Rectangle.

64. Create a class Publication with two data members


member (title and price).Declare two member function:-
function:
a) getData():- for accepting data from user.
b) putData():- for displaying data.
Create another class Sales with three data member ((s1,s2,s3) which accepts the sales of three
months).Declare two member function :-
:
a)getSales():- for accepting three month sales.
b)showsales():- for displaying sales.
Create one more class Book with one data member (pages).Declare
e two member function :-
:
a)getBookDetail():- which accepts the book details which includes title, price, sales and pages.
b)showBookDetail():- which displays the book details which includes title, price, sales and pages.

65. Create a class Employee with two protected data member (name, payRate).Declare two member
function
a) void getName() :- which accepts name.
b) float getPay() :- which accepts the pay.
Create a class Manager with one data member is_salaried (which should be in the form of 0(false)
0(false or
1(true).
Declare one member function
a)int is_salaried() :- which returns whether the manager is salaried or not.
b)showDetail() :- it display the entire detail of a employee.

Polymorphism, Abstract Class, Dynamic Memory Allocation(


Allocation Day 16, 17, 18 )
66. What is a Concrete class?
67. Define polymorphism?
68. What is overriding?
69. Create a class Shape with one member function

Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: info@universalinformatics.com
info@universalinform
C++ Programming Lab Assignments
a) double calcArea()
Create a class Rectangle with two data members (length and breadth) and inherits Shape and calculate
the area
Create a class Circle with one data members (radius) and inherits Shape and calculate the area

70. Create a class BankAccount with one data member(balance).


Declare four methods
a)BankAccount() :- which initialize the member function with 0.
b)void deposit(double amount) :-
: which adds balance in amount.
c)void withdraw(double amount) :-
: which deducts balance in amount.
d)double getBalance() :-
: which returns the balance.
Create a class SavingAccount with two data members(interest_rate and min_balance).Declare
min_balance) a
member function
a)setInterestRate() :- which sets the interest and use the above methods to calculate the account
balance.
71. Explain Abstract class. How do we create it in CPP?
72. What is the size of a class having one or more virtual functions?
73. .Create a Abstract class Volume with two data members(radius and height).
Declare two member function
a)getValue() :- which accepts value from user.
b)showValue() :- which displays valus.
valus
c)calVol() :- which calculates volumes.
Create a class Cone which uses the above mentioned three methods to calculate the volume of Cone.
Create a class Cylinder which uses the above mentioned three methods to calculate the volume of
Cylinder.

74. Create a class Pet with two member function


a) void speak()
b) void breath()
Create a class Rat and Cat which uses above mentioned function. Use dynamic memory allocation
i.e (new and delete operator) which dynamically allocates memory to both the classes, displays
output and deallocate them.

75. . Create a class Employee with one data member(name).Declare the member function
a)Employee() :- initializes the data member.

Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: info@universalinformatics.com
info@universalinform
C++ Programming Lab Assignments
b)getName() :- which gets the name.
c)setName() :- which sets the name.
d)pay(int hours_worked)
Create a class HourlyEmployee which takes two data members(name and wage).Use above member
function. The pay method should calculate the hourly wage of an employee.

Create a class SalariedEmployee which takes two data members(name and wage).Use above member
function. The pay method should
hould calculate the hourly wage of an employee.

Template Day 19

76. What is Template?


77. Difference between function template and class template?
78. Write a program to display larger number among two numbers using function templates. (If two
characters are
e passed to function template, character with larger ASCII value is displayed.)
79. Write a program to swap two numbers using class template.
80. Write a program to find the product of two numbers and returning the value.
81. Create a function template which returns
ret the average of three numbers.
82. Create a class template which returns the sum of two numbers.

File Input and Output. Day 20,21,22


83. What is a Stream?
84. Create a class Student with three data members (rno, name, marks).Write a program to write Student
data in a text file.
85. Write a program to read Student data in a text file in the above mentioned program.
86. Write a program to write Product data in a binary file.(pcode, pname, pprice, pqty and total price of
product).
87. Write a program to read Product data in a binary file in the above mentioned file.(pcode, pname,
pprice, pqty and total price of product).
88. Explain different modes in which file is made.
89. Declare a class TeleRecord , containing name (20 characters) and telephone number. Write a
program to maintain a file of telephone records. The program should allow the following operations on
the file:
a) To append records in the file.

Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: info@universalinformatics.com
info@universalinform
C++ Programming Lab Assignments
b) Display the name for a given telephone number. If the telephone number
does not exist then display error message "record not found".
c) Display the telephone number(s) for a given name. If the name does not
exist then display error message "record
"reco not found".

90. A blood bank maintains a data file that contains the following information for every donor: Name,
Date of Birth, Telephone number, Blood group. Write a program in C++ to do the following:
a) Given a blood group, display name, date of birth
birth and phone number of all the persons of the
given blood group.
b) Append records in the file.
c) Input a telephone number and view the corresponding record.

Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: info@universalinformatics.com
info@universalinform

You might also like