0% found this document useful (0 votes)
5 views2 pages

oops assignment 2

The document outlines an assignment on Object-Oriented Programming (OOP) covering core concepts, class declarations, member functions, access specifiers, object initialization, constructors, destructors, copy constructors, and key OOP principles like encapsulation, inheritance, polymorphism, and abstraction. It includes specific questions requiring code examples in C++, explanations of concepts, and the creation of various classes to demonstrate understanding. The assignment is structured to assess knowledge through practical coding tasks and theoretical explanations.

Uploaded by

dhakamonti20
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)
5 views2 pages

oops assignment 2

The document outlines an assignment on Object-Oriented Programming (OOP) covering core concepts, class declarations, member functions, access specifiers, object initialization, constructors, destructors, copy constructors, and key OOP principles like encapsulation, inheritance, polymorphism, and abstraction. It includes specific questions requiring code examples in C++, explanations of concepts, and the creation of various classes to demonstrate understanding. The assignment is structured to assess knowledge through practical coding tasks and theoretical explanations.

Uploaded by

dhakamonti20
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/ 2

Assignment: Introduction to Object-Oriented Programming (OOP) and Basic Concepts

Total Marks: 64 (8 marks each)


Instructions:

• Answer all questions.

• Provide code examples and explanations wherever required.

• Mention assumptions, if any.

Questions:

1. Introduction to OOP:
a) What is Object-Oriented Programming (OOP)? Explain its core principles.
b) How is OOP different from procedural programming? Give at least two examples to
support your answer.

2. Declaring Classes and Creating Objects:


Write a C++ program that:

o Declares a class Student with data members name and rollNumber.

o Defines a member function displayDetails() to display the student’s information.

o Creates an object of the Student class and calls the displayDetails() function.
Explain how objects are created and used in your program.

3. Member Functions, Data Members, and Inline Functions:


a) What are data members and member functions in a class? Explain with examples.
b) What is an inline member function? Modify the displayDetails() function from Question
2 to be an inline function and explain the benefits.

4. Access Specifiers and Access Control:


a) Explain the significance of public, private, and protected access specifiers in C++.
b) Create a class BankAccount with private data members accountNumber and balance,
and public member functions deposit() and displayBalance(). Demonstrate how access
specifiers control access to data.

5. Object Initialization and Initialization Lists:


a) How are objects initialized in C++?
b) Write a class Rectangle with data members length and width. Use an initialization list in
the constructor to initialize these members. Provide a code example and explain the
concept.

6. Constructors and Destructors:


a) What are constructors and destructors? Why are they important in OOP?
b) Write a class Car that includes:

o A default constructor that sets default values.

o A parameterized constructor to set specific values.

o A destructor to print a message when an object is destroyed.


Demonstrate how these are used in a program.
7. Copy Constructor and Its Significance:
a) What is a copy constructor? How is it different from an assignment operator?
b) Write a program with a class Book that uses a copy constructor to copy data from one
object to another. Explain when and why a copy constructor is called.

8. Encapsulation, Inheritance, Polymorphism, and Abstraction:


a) Define encapsulation, inheritance, polymorphism, and abstraction with real-world
examples.
b) Create a base class Shape with a virtual function area(). Derive two classes Circle and
Rectangle that override the area() function. Explain how polymorphism works in this
context.

You might also like