cs593 lab assignments

10
LAB ASSIGNMENTS PROGRAMMING PRACTICES USING C++ (Code: CS593) FOR 5 TH SEM B. TECH CSE (2012-2013) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING B. P. PODDAR INSTITUTE OF MANAGEMENT & TECHNOLOGY

Upload: nitishgalaxy

Post on 08-Feb-2016

28 views

Category:

Documents


0 download

DESCRIPTION

Cs593 Lab Assignments

TRANSCRIPT

Page 1: Cs593 Lab Assignments

LAB ASSIGNMENTS

PROGRAMMING PRACTICES USING C++

(Code: CS593)

FOR 5THSEM B. TECH CSE

(2012-2013)

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

B. P. PODDAR INSTITUTE OF MANAGEMENT & TECHNOLOGY

Page 2: Cs593 Lab Assignments

WBUT SYLLABUS

Programming Practices Using C++Code: CS593Contact: 3P(1L+2P)Credits: 2

Introduction of UNIX/Linux Operating System which includes preliminary commands, start-up & shutdown methodology, file handling as well as introduction to editors like Vi editor, introduction to GNU C & C++ compiler, as well as introduction to GNU & GDB script. [4P]

Introduction to C++, basic loop control, executing programs, writing functions, selectionstatements, review of functions and parameters, command line arguments, recursion, I/O streams, arraysand string manipulation, pointers, structures & unions. [6P]

Object-Oriented Programming in C++, fundamentals of classes, constructors-destructors.

Dealing with member functions, operator overloading and polymorphism (both static & dynamic).[6P]

Dealing with inheritance, derived class handling, abstract class, virtual class, overriding, template class, name-space & exception handling.[4P]

Dynamic memory allocation, implementation of Linked Lists, using C++.[4P]

Page 3: Cs593 Lab Assignments

Chapter 01: Classes and Objects

Accessing Class Members

ASSIGNMENT 01:

Write the definition for a class called Rectangle that has floating point data members length and width. The class has the following member functions:void setlength(float) to set the length data membervoid setwidth(float) to set the width data memberfloat perimeter() to calculate and return the perimeter of the rectanglefloat area() to calculate and return the area of the rectanglevoid show() to display the length and width of the rectangleintsameArea(Rectangle) that has one parameter of type Rectangle. sameArea returns 1 if the two Rectangles have the same area, and returns 0 if they don't.

1. Write main function to create two rectangle objects. Set the length and width of the first rectangle to 5 and 2.5. Set the length     and width of the second rectangle to 5 and 18.9. Display each rectangle and its area and perimeter.

2. Check whether the two Rectangles have the same area and print a message indicating the result. Set the length and width of the     first rectangle to 15 and 6.3. Display each Rectangle and its area and perimeter again. Again, check whether the two Rectangles have the same area and print a message indicating the result.

ASSIGNMENT 02:

Write a program using basic concept of objects and classes to check whether given number is prime or not.

Data Hiding

ASSIGNMENT 03:

Create a class called carpart that has int member data for car id, int member data for charge/hour and float member data for time. Set the data and show the charges and parked hours of corresponding car id. Make two member functions for setting and showing the data. Member function should be called from other functions.

ASSIGNMENT 04:

Let us consider a shopping list of items for which we place an order with a dealer every month.The list includes details such as the code number and price of each item.We would like to perform operations such as adding an item to the list, deleting an itam from the list and printing the total value of the order.

Page 4: Cs593 Lab Assignments

Outside Member Functions as inline

ASSIGNMENT 05:Write a C++ program to display the date of birth of three authors using inline function. The dates of birth of the authors are passed as parameters to function.

Passing Objects as Arguments

ASSIGNMENT 06:

Create a class time that has integer data members hours and minutes. The class has the following member functions:

voidgettime(int, int) to set the hours and minutes data membersvoidputtime(void) to display the hours and minutes data membersvoid sum(time, time) to add two times that will illustrate the concepts of Passing Objects as Arguments.

Returning Objects from Functions

ASSIGNMENT 07:

Write a C++ program to add two complex numbers illustrating the concept of Returning Objects from Functions.

Friend Functions and Friend Classes

ASSIGNMENT 08:

Write a C++ program to find the maximum of two numbers illustrating the concept of Friend Functions.

Static Data Member

ASSIGNMENT 09:

Write a C++ program to illustrate the concept of static data members.

Static Member Functions

ASSIGNMENT 10:

Write a C++ program to illustrate the concept of static member functions.

Page 5: Cs593 Lab Assignments

Chapter 02: Constructor and destructor

Constructor

ASSIGNMENT 11:

Create a class called Box that has double data members length, breadth and height. Write a C++ program to find the volume of a box illustrating the concept of Constructor.

Constructor Overloading

ASSIGNMENT 12:

Create a class called complex that has two floating point data members x and y. Write a C++ program to add two complex numbers by using multiple constructors in the class complex.

Constructors with Dynamic Operations

ASSIGNMENT 13:

Write a C++ program to illustrate the concept of Constructors with Dynamic Operation new.

Copy constructor  

ASSIGNMENT 14:

Write a C++ program to illustrate the concept of Copy Constructors.

Creating and Deleting Dynamic Objects

ASSIGNMENT 15:

Write a C++ program to create and delete dynamic objects by using dynamic operation new and delete.

this Pointer

ASSIGNMENT 16:

Write a C++ program to illustrate the working of this pointer.

Destructor  

ASSIGNMENT 17:

Write a C++ program to implement the concept of Destructor.

Page 6: Cs593 Lab Assignments

Chapter 03: Operator OverloadingASSIGNMENT 18:

Write a C++ program to add, subtract, multiply and divide two complex numbers by using the concept of operator overloading.

Chapter 04: Inheritance

Multilevel Inheritance

ASSIGNMENT 19:

Write a C++ program to show multilevel inheritance.

Multiple inheritance  

ASSIGNMENT 20:

Consider a publishing company that publishes and markets books, whose activities are shown in Figure below. Create a class publication that stores the title (string) and price (float) of a publication. Create another class sales that holds an array of three float's so that it can record the sales of a particular publication for the last three months. From these two classes, derive a new class called book that hold pages of integer type. Each of these classes should have the member functions getdata() and display().

From the publication and sales classes, derive the tape class, which adds playing time in minutes (type float). Create another class pamphlet from publication, which has no features of its own. Derive a class notice from pamphlet class having data members char whom[20] and member functions getdata() and putdata().

Page 7: Cs593 Lab Assignments

Hybrid Inheritance

ASSIGNMENT 21:

Write a C++ program to implement hybrid inheritance.

Chapter 05: Virtual Functions & Polymorphism

ASSIGNMENT 22:

Create four classes figure (base class), triangle (publicly derived from class figure), square (publicly derived from class figure) and circle (publicly derived from class figure).Write a C++ program to find the area of triangle, square and circle by using the concept of Virtual Polymorphism. All the dimensions will be entered through keyboard in the derived classes.

Runtime Polymorphism

ASSIGNMENT 23:

Create three classes media(base class), book(publicly derived from class media) tape(publicly derived from class media).Write a C++ program to display the details of book(title, pages and price) and tape(title, play time and price) by using the concept of Runtime Polymorphism.The details of book (title, pages and price) and tape (title, play time and price) will be entered through keyboard in main () function.

Chapter 06: Abstract Classes

Abstract Classes

ASSIGNMENT 24:

Write a C++ program to illustrate the concept of Abstract Class.

INNOVATIVE PROGRAMS

1. MINI PROJECT 01: banking-system-project using C++2. MINI PROJECT 02: library-management-system-project using C++3. MINI PROJECT 03: Student Record Systemproject using C++