C++ Lab Practice
C++ Lab Practice
Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: [email protected]
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?
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: [email protected]
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.)
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
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
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: [email protected]
info@universalinform
C++ Programming Lab Assignments
- list all account number with balance greater than 1000
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.
Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: [email protected]
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.
Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: [email protected]
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.
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.
Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: [email protected]
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.
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.
Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: [email protected]
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
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: [email protected]
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
Abhay Prashal, Race Course Road, Indore, Ph. 2535381, 2431972 Email: [email protected]
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: [email protected]
info@universalinform