29
Computer Science & Engineering and Information Technology Department .  Jaypee Uni versity of Informat ion T echnology , Waknaghat Course Description Co urse Tit le Object -Ori ented S yste ms an d P ro grammi ng Lab Cou rse Code 10B1 7CI6 7 !0-0 - " # credi ts Course Coordinator Amol Vasudeva Pre-re$uisites Introduction to Computer Programming Post-courses Object Oriented Software Engineering Objecti%es 1. o strengt!en t!eir problem solving abilit" b" appl"ing t!e c!aracteristics of a object#oriented approac!. $. o strengt!en abilit" to design and represent solutions to problems using %& notations. (. o introduce object oriented concepts in C)) and *ava. Learning Outcomes Student &ill be able to' 1. E+plain w!at constitutes an object#oriented approac! to programming and identif  potential benefits of object#oriented programming over ot!er approac!es. $. Anal",e and decompose problem specifications from Object#Oriented Perspectives and represent t!e solution using %&' notation. (. Appl" an object #ori ented approac! to devel opi ng appli cat ions of var "i ng comple+ities. To(ics Labs )ours Objects- Classes- &et!ods- Constructors and estructors # Static members and /riend /unctions 1 # In!eritance 1 # /ile 0andling 1 # Operator Overloading and Conversion /unctions # Pol"morp!ism and Virtual /unctions in C)) 1 # emplates in C)) # Object#Oriented Concepts in *ava Objects- Classes- In!eritance- Pol"morp!ism etc.2 * E+ception 0andling in *ava # Pac3ages- Interfaces and Abstract classes in *ava + 6 Container classes in *ava # %&' esigning Class 4 Object iagram- %se Case iagram- Collaboration iagram- Se5uence iagram- State iagram2 * Structured 6uer" 'anguages ata efinition- ata &anipulation- ata Access Commands2 + 6 Total , #* 6 .%aluation Sc/eme  Jaypee University of Infor mation T echnology, Wanaghat, Solan, !imac hal "radesh

Amol_Object-Oriented Systems & Programming Lab Manual

Embed Size (px)

DESCRIPTION

fgdfgdfg

Citation preview

Computer Science & Engineering and Information Technology Department

.Jaypee University of Information Technology, Waknaghat

Course DescriptionCourse TitleObject-Oriented Systems and Programming Lab

Course Code10B17CI674 (0-0-4) 2 credits

Course CoordinatorAmol Vasudeva

Pre-requisitesIntroduction to Computer Programming

Post-coursesObject Oriented Software Engineering

Objectives1. To strengthen their problem solving ability by applying the characteristics of an object-oriented approach.

2. To strengthen ability to design and represent solutions to problems using UML notations.

3. To introduce object oriented concepts in C++ and Java.

Learning Outcomes

Student will be able to:

1. Explain what constitutes an object-oriented approach to programming and identify potential benefits of object-oriented programming over other approaches.

2. Analyze and decompose problem specifications from Object-Oriented Perspectives and represent the solution using UML notation.

3. Apply an object-oriented approach to developing applications of varying complexities.

TopicsLabs Hours

Objects, Classes, Methods, Constructors and Destructors24

Static members and Friend Functions 12

Inheritance 12

File Handling12

Operator Overloading and Conversion Functions24

Polymorphism and Virtual Functions in C++12

Templates in C++24

Object-Oriented Concepts in Java (Objects, Classes, Inheritance, Polymorphism etc.)48

Exception Handling in Java24

Packages, Interfaces and Abstract classes in Java36

Container classes in Java24

UML Designing (Class & Object Diagram, Use Case Diagram, Collaboration Diagram, Sequence Diagram, State Diagram)48

Structured Query Languages (Data Definition, Data Manipulation, Data Access Commands)36

Total = 2856

Evaluation Scheme

Attendance & Discipline in Lab: 15 marks Mid-Term Lab Exam and Viva: 20 marks End-Term Lab Exam and Viva: 20 marks

Lab Records: 15 marks Regular Assessment: 30 marks

(Quality and quantity of experiment

performed, Learning laboratory skills)

Total = 100 marks

Reference Material:

Grady Booch, James Rambaugh, Ivar Jacobson,Unified Modelling Language usersguide, Addison Wesley Limited Lafore R., Object oriented programming in C++, Waite Group Stroustrap B., The C++ Programming Language, Addison Wesley Langsam,Augestein,Tenenbaum: Data Structures using C and C++ Sahani, Sartaj: Data Structures in C++/Data Structures in Java Java 2: The Complete Reference, Fifth Edition -- by Herbert Schildt

PRACTICAL #1

Classes and ObjectsLearning outcomes

On successful completion of this module you should be able to:

Understand the role of C++ classes as the implementation facility for abstract data types, the central concept of object oriented programming. Identify suitable types and their operations in various problem domains. Understand the difference between a class and an object. Code and use simple C++ classes using the following facilities:

public and private members constant member functions

1. Create a class called Complex for performing arithmetic with complex numbers. Use double variables to represent the private data of the class. Provide public member functions for each of the following: (Define all the member functions outside the class)a) Enter the values of real and imaginary part.

b) Addition of two Complex numbers: (The real parts are added together and the imaginary parts are added together.

c) Subtraction of two Complex numbers. (The real part of the right operand is subtracted from the real part of the left operand and the imaginary part of the right operand is subtracted from the imaginary part of the left operand.

d) Printing Complex numbers in the form: a + b i2. Define a class to represent a bank account. Include the following members:Data members:

a) Name of the depositor

b) Account number

c) Type of account

d) Balance amount in the accountMember functions: (Define all the member functions inside the class)

a) To assign initial values

b) To deposit an amount

c) To withdraw an amount after checking the balance

d) To display name and balanceWrite a main function to create a database of 10 customers

PRACTICAL #2

ConstructorsLearning outcomes

On successful completion of this module students should be able to:

Explain the purpose of a default constructor, parameterized constructor, copy constructor and destructor Explain the circumstances under which objects are created and destroyed, including the temporary objects, and hence when constructors and destructors will be invoked. Create objects from dynamic storage using the new operator and destroy them using the delete operator.1. Employees have a number, date of birth (dd-mm-yyyy), rank, and salary. When an employee is first recruited then all these are given values of 0. Upon confirmation, the actual values of these are entered for the employee. Their rank can be incremented by 1 and when this happens an employee gets an increment of 25%.

Write a C++ class for Employee.

2. Students are registered in a University. When students are created then they are given default values (zeroes or blanks) for roll_number, department, year, and semester of study. At registration time, the values of these attributes of student are updated with the proper values. Students can be promoted and their departments can be changed.

Write a C++ class for Student.

3. Users of the computer have profile which consists of Name, Password, and Access Rights. Access rights take on values X, R, W, and ALL. It is possible to have default values for Password and Access rights which are the first three letters of the Name and ALL respectively. Users can change their password and access rights.

Write a class User in C++ and create a user named Rajesh.

4. There are three ways in which Users of question 3 above can be created

i) by supplying Name only and using default values for the others

ii) by supplying Name and password and using default value for Access rights

iii) by supplying all information

Write the user class. Create

a) Rajesh using (i) above

b) Rajesh with password = crol87pp under (ii) above and

c) Rajesh with password = crol87pp and access right = W under (iii) above.

PRACTICAL #3

Static and Friend FunctionsLearning outcomes

On successful completion of this module students should be able to:

Develop C++ classes using static data members and static member functions Use of friend functions to provide an interface between two or more classes

1. Define two classes Distance1 and Distance2. Distance1 stores distance in miles and Distance2 in kmeters & meters. Write a program that reads values of the class objects and adds one object of Distance1 with the object of Distance2 class. The display should be in the format of miles or kmeters & meters depending on the type of object (Distance1 or Distance2) being used to invoke the function. (Hint: Make use of friend function.).

2. Implement a singleton class. A class whose number of instances that can be instantiated is limited to one is called a singleton class. (Hint: make use of static members).

PRACTICAL #4

InheritanceLearning outcomesOn successful completion of this module students should be able to:

Explain the purpose of inheritance as an implementation of class generalization and specialization. Identify the constructors and destructors that will be invoked in an inheritance hierarchy and their sequence of execution. Use public, protected and private access control to correctly limit access to class members in an inheritance hierarchy Explain how to resolve name clashes when using multiple inheritance

Explain the purpose of polymorphic operations and how they can be implemented within a class hierarchy with virtual member functions

Identify the characteristics of an abstract class and explain its purpose1. Imagine a publishing company that markets both books and audio-cassette version of its works. Create a class Publication that stores the title (a string) and price (type float) of a publication. From this class derive two classes: Book, which adds a page count and Tape, which adds playing time in minutes. These classes should have getdata() function to get its data from the user and the putdata() function to display its data. Write a main() program to test the book and tape classes by creating instances of them, asking the user to fill in their data with getdata() and displaying the data with putdata().

2. An educational institution wishes to maintain a database to its employees. The database is divided into minimum information required for each class. Specify all the classes and define functions to create the database and retrieve individual information as and when required.

3. The database created in above exercise does not include educational information of the staff. It has been decided to add this information to teacher and officers (not for typists) which will help the management in decision making with regard to training, promotion, etc. Add another data class called Education that holds two pieces of education information, namely, highest qualification in general education and highest professional qualification. The class should be inherited by the class Teacher and Officer. Modify the program of above exercise to incorporate these additions. Include overloaded constructors in all above classes.

4. Consider the class hierarchy shown in the figure 3a. Define appropriate member functions (including constructors and destructors) to convert feet class object into inches class object and vice versa. Also the objects of the feet and inches constructors should construct their objects using the constructors of the height and width constructor which in turn call building constructor.

5. Consider the class hierarchy shown in the figure 3b. Define appropriate member functions (including constructors and destructors) to convert feet class object into inches class object and vice versa. Also construct the building class object using the constructors of the height and width constructor which in turn call feet and inches constructors.

PRACTICAL #5

File HandlingLearning outcomes

On successful completion of this module students should be able to:

Describe the structure and organization of the iostream facilities of the C++ standard library

Develop C++ applications that store and retrieve data in files and understand the shortcomings of this approach

Explain the differences between text and binary files and how they can be accessed using the iostream facilities of the C++ standard library

Describe the different places where buffering of data occurs when using the iostream library

1. Define a class Directory with members: name and phone number. Use the class object to store each set of data into a text file phone.txt. The names contain only one word and the names and telephone numbers are separated by white spaces. Write a program to read the file and output the list in two columns, such as: John

23456

Ahmed9876

2. Write an interactive, menu-driven program that will access the file created in above problem(1) and implement the following tasks:

a) Determine the telephone number of the specified person.

b) Determine the name if a telephone number is known.

c) Update the telephone number, whenever there is a change.

PRACTICAL #6Operator Overloading

Learning outcomes

On successful completion of this module you should be able to:

Develop operator overload functions for user-defined types for the following operators:

normal arithmetic, i.e. +, -, *, / assignment and composite arithmetic, i.e. +=, -=, *=, /=, = comparison, i.e. , ==, !=, = stream I/O, i.e. subscript, i.e. [ ] increment and decrement, i.e. ++ and --

Understand the difference between top-level and member operator overload functions and the use of friends Identify the circumstances under which the essential class facilities of a copy constructor, assignment operator overload and destructor will be required

Understand why the subscript operator overload generally requires a constant and a non-constant form1. Define a class Queue that contains elements of type integer. Define two operators on Queue, + to insert an element in it and to remove and element from it. Use the friend function approach first and then the one without friends.

2. A programmer wants to manipulate arrays. Two arrays are equal if (a) they have the same dimension, (b) are of the same size, and (c) contain identical values in their corresponding elements. Comparison is done using the operator = = which returns true or false. Also, arrays can be copied to one another using the operator =.Implement the foregoing using the friend function approach first and then the one without friends. Which one is preferable and why?

3. The istream class overloads the >> operator for the standard types [int, long, double, float, char]. For example, the statement

cin >> x ;

calls the appropriate >> operator function for the istream class defined in iostream.h and uses it todirect this input stream into the memory location represented by the variable x. Similarly, the ostream class overloads the and display the values of these members by using the output operator