0% found this document useful (0 votes)
153 views

Programming Practice Using C++ (IT594F) : Assignment

This document outlines programming assignments related to object-oriented programming concepts in C++ including class and object, constructors and destructors, operator overloading, function overloading, friend functions, inheritance, virtual functions, templates, and exception handling. Students are asked to write programs implementing various classes that demonstrate these OOP concepts, such as a class to calculate area and perimeter, a date class, a complex number class, and classes for shapes and employees.

Uploaded by

39MILAN MANDAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views

Programming Practice Using C++ (IT594F) : Assignment

This document outlines programming assignments related to object-oriented programming concepts in C++ including class and object, constructors and destructors, operator overloading, function overloading, friend functions, inheritance, virtual functions, templates, and exception handling. Students are asked to write programs implementing various classes that demonstrate these OOP concepts, such as a class to calculate area and perimeter, a date class, a complex number class, and classes for shapes and employees.

Uploaded by

39MILAN MANDAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Department of Information Technology, Academy of Technology

Programming Practice using C++ (IT594F)


Assignment
Class and object

P1.Write a program in C++ to find area and perimeter of circle by creating objects.
P2.Write a program in C++ to find areas of triangle, rectangle and square by creating objects.
P3. Write a program in C++ to add two complex numbers by creating objects.
A1. Write a simple program that convert the temperature in degree Celsius to degree Fahrenheit and vice
versa using the basic concept of class and object. Make separate class for Centigrade and Fahrenheit
which will have the private member to hold the temperature value and make conversion functions in
each class for conversion from one to other. For example you will have function to Fahrenheit () in class
Celsius that converts to Fahrenheit scale and returns the value.
A2. Write a program in C++ to implement DATE class which will have 3 data members (day, month,
and year) and some member functions. Use a function to get date. Create another function to validate a
given date. (e.g. 30.02.2013 is not a valid date)

Constructor-Destructor

P4.Implement stack where each stack object deals with different array size as per user’s given size.
P5. Create a complex class to perform addition, subtraction, multiplication and division of two Complex
Numbers. Your complex class should contain-
i.Constructors to initialize data members
ii.Copy constructor
iii.Member functions for addition, subtraction, multiplication and division of two Complex Numbers
P6. Create a class called Time that has a separate integer member data for hours, minutes and seconds.
One method initialize it to fixed values. A member function should display it, in HH:MM:SS format.
The final two member functions should add and subtract two objects of time passed as arguments. A
main() program should create two initialized time objects. Then it should add the two initialized objects,
storing the result in a third time object. Finally it should display the value of the third time object.
P7.Write down a program on C++ to define your own Stringclass. Your String class should contain-
i.Dynamic constructor(s) to allocate memory space for string.
ii.Copy constructor
iii.Member functionto merge two strings and store it in another string.
iv.Destructor
A3. Write down a program on C++ to define a class Matrix which uses a 2D array and two variable
rlimit and climit to hold the row size and column size of the matrix. Your Matrix class should contain-i.
i.Copy constructor
ii.Dynamic constructor to allocate memory space for matrix.
iii.Member function for addition of two matrices and store it in another matrix.
iv.Destructor
A4. Write an object-oriented program to enter and display Employee’ information.
Enter following information about students:
Name
Age
Department
Salary
Use constructor to allocate the memory for n employees(show both static and dynamic initialization of
objects). Also define destructor to de-allocate memory.

1
Department of Information Technology, Academy of Technology
Programming Practice using C++ (IT594F)
Assignment
Operator overloading

P8.Create a class String then implement the following operations


i. Overload + operator to concatenate two strings
ii. Overload assignment operator (=) to assign one string into another.
iii. Overload comparison operators (<, ==) to compare two strings.
P9. Create a complex class to perform addition, subtraction, multiplication and division of two Complex
Numbers. Your complex class should contain-
i.Constructors to initialize data members
ii.Copy constructor
iii.Overload operators +, -, *, / for addition, subtraction, multiplication and division of two
ComplexNumbers respectively. Then find the expression a-b*c+d (where a, b, c, and d are complex
objects).
A5. Create a class called HEIGHT that stores the height of a student in feet and inches in two private
instance variables. Include a constructor that sets these values. Define a function into_cm(), which
returns the height in cm. overload the operator "-" to perform the difference of two student’s heights.
Also Overload comparison operators (<, ==) to compare twostudent’s heights.

Function overloading:

P10. Write a program in C++ to implement class ADD that will have 3 overloaded functions.
1st one will add two integer numbers.
2nd one will add two floating and one integer number.
3rd one will take two complex objects as parameter and will add two complex numbers.
A6. Assume that object represents an employee report that contains the information about employee id,
total bonus, and total overtime in a particular year. Use four objects to represent four employees' reports.
Write a program that display report information. Use setpara() overloaded member functions to set
report attributes by passing/without passing the arguments and member function displayreport() to show
the reports according to parameter passed.

Friend class & function

A7. Create a class complex that contains two double data members. Overload +, - , and * arithmetic
operators using friend function, so that they can operate on the object of complex. Then find the
expression a - b * c + d (where a, b, c, and d are complex objects).
A8. Create two class DM & DB which store the value of distances. DM stores it in meter & centimeters.
DB stores it in feet & inches. Write a program that can read values for the class objects & add one object
of DM with another object of DB. Use a friend function to carry out the addition operation. The objects
that store the result may be of either type depending on the units in which the results are required. The
display function should act accordingly.

Inheritance

P11. Write three derived classes inheriting functionality of base class person (should have member
function. That ask to enter name and age) and with added unique features of student, employee, and
functionality to assign, change and delete records of student and employee. And make one member
function for printing address of the objects of classes (base and derived) using this pointer. Create two
objects of base class and derived classes each and print the addresses of individual objects. Using
calculator, calculate the address space occupied by each object and verify this with address spaces
printed by the program.

2
Department of Information Technology, Academy of Technology
Programming Practice using C++ (IT594F)
Assignment
P12. Write base class that ask the user to enter a complex number and derived class adds the complex
number of its own with the base. Finally make third class that is friend of derived and calculate the
difference of base complex number and its own complex number.

A9.

This is the database of the employees of an Educational Institute. Specify all the classes & define
functions to create database & retrieve individual information when required.

Virtual Functions

P13. Write a program to create a class shape with functions to find area of the shapes and display the
name of the shape and other essential component of the class. Create derived classes circle, rectangle and
trapezoid each having overridden functions area and display. Write a suitable program to illustrate
virtual functions and virtual destructor.
A10. Create a class Person and two derived classes Employee, and Student, inherited from class Person.
Now create a class Manager which is derived from two base classes Employee and Student. Show the
use of the virtual base class.

Template:

P14. Write a program in C++ to implement STACK class that will have push, pop and display
operations using template. Use a constructor to initialize top value.
A11.Implement QUEUE class, which will perform all operations of a linear queue using template.

Others:

A12. Write a program to pass n numbers through command line. Then find out largest among them.
A13.Write an interactive program which divides two numbers. Here inputs are actually passed by
command line arguments. Enhance your design by using exception handling (possible cause of
exception-number of arguments must be 2, divide by 0, both arguments must be a number).

You might also like