CP Assignment 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CHANDIGARH UNIVERSITY

Gharuan, Mohali
Institute/Department: University Institute of Engineering
Division: Academic Unit - 2
Subject Name: Object Oriented Programming Using C++
Subject Code: CST-157

Assignment No.: 2
Max. Marks: 12

Date of Allotment: 19- Feb -20


Last date of Submission: 17-Mar-20

Course Outcomes:
CO Title Level
Number
It will provide the environment that allows students to understand Understand
CO1
object-oriented programming Concepts.
Students will demonstrate basic experimental skills for Remember
differentiating between object-oriented and procedural
CO2
programming paradigms and the advantages of object-oriented
programs.
Ability to demonstrate their coding skill on complex programming Understand
CO3 concepts and use it for generating solutions for engineering and
mathematical problems.
Students will develop skills to understand the application of Understand
classes, objects, constructors, destructors, inheritance, operator
CO4
overloading and polymorphism, pointers, virtual functions,
templates, exception handling, file operations and handling.

Questions:

Sr. Grou ASSIGNMENT CO


No. p Numb
er
1 Grou 1. What all is not inherited from parent class in C++? CO1
pA
2. Write a program to read and print employee information with department CO3
and PF (provident fund) information using hierarchical inheritance.
3. What is the significance of operator overloading? Give example. CO1
CO3
4. How ambiguity of inheritance is resolved? Explain with the help of a CO1
programming example. CO3
5. A hospital wants to create a database regarding its indoor patients. The CO4
information to store include:
i. Name of the patient
ii. Date of admission
iii. Disease
iv. Date of discharge
Create a structure to store the date (year, month and date as its members).
Create a base class to store the above information. The member function
should include functions to enter information and display a list of all the
patients in the database. Create a derived class to store the age of the
patients. List the information about all the to store the age of the patients.
List the information about all the pediatric patients (less than twelve years
in age).
2 Grou 1. Write a program to overload the operator ‘+’ for complex numbers. CO3
pB
2. An electricity board charges the following rates to domestic users to CO4
discourage large consumption of energy : For the first 100 units − 50 P per
unit Beyond 300 units − 60 P per unit If the total cost is more than Rs.250.00
then an additional surcharge of 15% is added on the difference. Define a
class Electricity in which the function Bill computes the cost. Define a
derived class More_Electricity and override Bill to add the surcharge.
3. Write a program with following : CO3
a. A function to read two double type numbers from keyboard
b. A function to calculate the division of two numbers
c. A try block to throw an exception when a wrong type of data is
keyed in
d. A try block to detect and throw an exception if the condition
“divided –by-zero” occurs
e. Appropriate catch block to handle the exceptions thrown
4. Explain the situation when ambiguity is occurred in inheritance with CO1
the help of program.
5. Illustrate the concept of constructor overloading with help of a CO1
program. CO2
3 Grou 1. Define Rules for operator overloading. Write a program to overload the CO2
pC subscript operator ‘[ ]’. CO3

2. Write a program to check given date is in valid format or not. CO4


3. What all is inherited from parent class in C++? CO1

4. Consider a publishing company that markets both book and audio cassette CO4
version to its works. Create a class Publication that stores the title (a string)
and price (type float) of a publication. Derive the following two classes
from the above Publication class: Book which adds a page count (int) and
Tape which adds a playing time in minutes(float). Each class should have
get_data() function to get its data from the user at the keyboard.
Write the main() function to test the Book and Tape classes by creating
instances of them asking the user to fill in data with get_data() and then
displaying it using put_data().
5. Write a program containing a possible exception. Use a try block to throw CO3
it and a catch block to handle it properly.
4. Grou 1. Write a program to overload ‘-‘ operator for numbers as well as complex CO1
pD numbers.
2. Class Y has been derived from class X. The class Y does not contain any CO2
data members of its own. Does the class Y require constructor. If yes,
why?
3. Write a C++ program for addition & multiplication of two matrices CO4
by overloading + and * operators.
4. Write a program that illustrates the application of multiple catch CO4
statements.
5. Create a class account that stores customer name, account number CO3
and type of account. From this derive the classes cur_acct and
sav_acct to make them more specific to their requirements. Include
necessary member functions in order to achieve the following tasks:
a. Accept deposit from a customer and update the balance.
b. Display the balance.
c. Compute and deposit interest.
d. Permit withdrawal and update the balance.
e. Check for the minimum balance, impose penalty, necessary, and
update the balance.

1. Write a program having a base class Student with data member rollno CO4
5 Grou and member functions getnum() to input rollno and putnum() to
pE display rollno. A class Test is derived from class Student with data
member marks and member functions getmarks() to input marks and
putmarks() to display marks. Class Sports is also derived from class
Student with data member score and member functions getscore() to
input score and putscore() to display score. The class Result is
inherited from two base classes, class Test and class Sports with data
member total and a member function display() to display rollno,
marks, score and the total(marks + score).
2. Write a program which uses catch(…) handler. CO3

3. What are nesting classes? Explain the concept of nesting of classes CO1
with the help of suitable programming example.
4. Differentiate among C++ multiple, multilevel and hierarchical CO2
inheritance with the help of suitable examples. CO3
5. A C++ Program that reads the marks obtained of ten students out of CO3
100. It also computes the average; lowest and highest marks. Then
shows the difference of marks of every student from the average
marks.
6 Grou 1. Explain the difference between function overloading and overriding. CO1
pF 2. Operators such as >>, which read input from the keyboard, must be CO3
able to convert a series of digits into a number. Write a program that
does the same thing. It should allow the user to type up to six digits,
and then display the resulting number as a type long integer. The
digits should be read individually, as characters, using getche().
3. Start with a program that allows the user to input a number of CO4
integers, and then stores them in an intarray. Write a function called
maxint()that goes through the array, element by element, looking for
the largest one. The function should take as arguments the address of
the array and the number of elements in it, and return the index
number of the largest element. The program should call this function
and then display the largest element and its index number.
4. Write a program that demonstrates the concept of rethrowing an CO2
exception.
5. Write a program to read and print house details along with room CO2
details.
7 Grou 1. What are the different types of Binding? Explain them with the help of CO4
pG suitable programming example.
2. Define Class, Nested class. How to declare a nested class? Give an example CO4
3. Create a class that includes a data member that holds a “serial number” for CO2
each object created from the class. That is, the first object created will be
numbered 1, the second 2, and so on. To do this, you’ll need another data
member that records a count of how many objects have been created so far.
Then, as each object is created, its constructor can examine this count
member variable to determine the appropriate serial number for the new
object. Add a member function that permits an object to report its own serial
number. Then write a main() program that creates three objects and queries
each one about its serial number. They should respond I am object number
2, and so on.
4. How to stop class inheritance in c++ with condition that object creation CO3
should be allowed.

5. Write a program in c++ to calculate marks and percentage of a student CO4


using hybrid inheritance.
8 Grou 1. What do you mean by static class members? Explain the characteristics of CO1
pH static class members with suitable examples.
2. A class Teacher has following specifications : CO4

Private members : Name, Subject, Basic, DA, HRA,salary.


float Calculate( ) function computes the salary and returns it. Salary is sum
of Basic, DA and HRA. Public members: Readdata ( ) function accepts the
data values and invokes calculate function. Displaydata( ) function prints
the data on the screen.
3. Write a program that demonstrates how certain exception types are not CO4
allowed to be thrown.
4. Class Y has been derived from class X. The class Y does not contain any CO3
data members of its own. Does the class Y require constructor? If yes, why?
5. How can I overload global << and >> operators to work with cin, cout etc? CO3

9 Grou 1. Create a class Distance with feet and inch and with a print function to print CO1
pI the distance. Write a non-member function max which returns the larger of
two distance objects, which are arguments. Write a main program that
accepts two distance objects from the user, compare them and display the
larger.
2. Student and Professor are two subclasses in which Student subclass CO3
displays the name and CGPA (grade points in float) and Professor subclass
displays the name and number of publications (int). Write a main program
using polymorphism to display the data of one student and one professor.
3. Consider a publishing company that markets both book and audio cassette CO4
version to its works. Create a class Publication that stores the title (a string)
and price (type float) of a publication. Derive the following two classes
from the above Publication class: Book which adds a page count (int) and
Tape which adds a playing time in minutes (float). Each class should have
get_data() function to get its data from the user at the keyboard.
Write the main() function to test the Book and Tape classes by creating
instances of them asking the user to fill in data with get_data() and then
displaying it using put_data().
4. Write a program that illustrates how a try block invokes a function that CO4
generates an exception.
5. Write a program that illustrates the concept of operator overloading CO3

10 Grou 1. Consider a class network that shows in figure. The class master derives CO4
pJ information from both account and admin classes which in turn derive
information from the class person. Define all the four classes and write a
program to create, update and display the information contained in master
objects.

Person
Name

code

account admin

pay experience

master

Name

Code

Experience
2. Explain the advantage of virtual base class with the help of suitable CO3
example.
3. Create a class Employee with a name and salary. Create a class Manager CO4
inherit from Employee. Add an instance variable, named department, of
type string. Supply a method to toString that prints the manager’s name,
department and salary. Make a class Executive inherit from Manager.
Supply a method to String that prints the string “Executive” followed by
the information stored in the Manager superclass object. Supply a test
program that tests these classes and methods.
4. Consider the following class hierarchy. Create a base class employee CO4
(empcode emp name). Derive the class manager (designation
clubdues), scientist (department name ,publication) and labourer
from employee class. Write C++ menu driven program
a) To accept the detail of ‘n’ employee.
b) To display the information.
c) To display all the scientist from “chemical department”.
5. Write a C++ program to perform arithmetic operations on two CO4
numbers and throw an exception if the dividend is zero or does not
contain an operator.
11 Grou 1. A supermarket chain has asked you to develop an automatic checkout CO4
pK system. All products are identifiable by means of a barcode and the product
name. Groceries are either sold in packages or by weight. Packed goods
have fixed prices. The price of groceries sold by weight is calculated by
multiplying the weight by the current price per kilo. Develop the classes
needed to represent the products first and organize them hierarchically. The
Product class, which contains generic information on all products (barcode,
name, etc.), can be used as a base class.
2. Write a program with following CO3
• A function to read two double type numbers from keyboard
• A function to calculate the division of two numbers
• A try block to throw an exception when a wrong type of data is keyed in
• A try block to detect and throw an exception if the condition “divided –
by-zero” occurs
• Appropriate catch block to handle the exceptions thrown
3. A class has three data members: name, roll no, marks of 5 subjects CO3
and a member function Assign() to assign the streams on the basis of
table given below:
Avg. Marks Stream
90% or more Computers
80% - 89% Electronics
75% - 79% Mechanical
70% - 74% Electrical
4. What is early binding and late binding? Explain with help of diagram. CO1

5. Explain the concept of virtual base class with the help of an example. CO3

12 Grou 1. What is the difference between function overloading and overriding? CO3
pL Explain with examples.
2. Write a C++ program to accept user name and password and throw an CO1
exception if the password has less than 6 characters or does not contain a
digit.
3. Create the mark sheet of an university examination with the following items CO3
from the keyboard: Name of the student Roll no. Subject name Subject code
Internal marks External marks Design a base class consisting of data
members Name of the student and Roll no. The derived class consists of the
data members Subject name, Subject code, Internal marks and External
marks.
4. A function area() to compute the area of objects of different classes – CO3
triangle, rectangle, square. Invoke these in the main program. Comment on
the binding (static or dynamic) that takes place in your program.
5. Create a program that calculates the cost of construction for building a house CO4
for this. Derive a class publicly from three base classes cement, steel and
wood. The requirements for building a house will be 500 bags of cement
where each bags costs rs150, three tons of steel costing rs 28000 per ton and
so on cubic feet of wood costing rs 1500 per cubic foot.

You might also like