V.Vidhya Logo

V.Vidhya

Classes, Member Functions & Access Specifiers (OOP)


Q1.

Analyze the given programs below, predict their outputs and determine whether they follow the principles of object-oriented programming correctly.


Q2.

What will be the output of the following programs?

You have to predict the output yourself without running/executing the code.


Q3.

A mobile shop wants to maintain information about different mobile phones.

Create a program that:

Instructions
  • Create a class for Mobile-Phone.
  • The class should store the following details:
    • Brand name (e.g., Samsung, Apple)
    • Model name (e.g., Galaxy S25, iPhone 16)
    • Price (e.g., rs.65000, rs.80000)
  • Add member functions to:
    • Set details of a phone.
    • Update the price of a phone.
    • Display the phone’s details.
Expected Output
Phone Details:
Brand: Apple
Model: iPhone 16
Price: rs.85000

// After updating the price
Phone Details:
Brand: Apple
Model: iPhone 16
Price: rs.72500

Q4.

A library wants to keep track of the books available for readers.

Create a program that:

Instructions
  • Create a class for Book.
  • The class should store the following details:
    • Title (e.g., “The Book of Mirdad”, “Siddhartha”)
    • Author (e.g., “Mikhail Naimy”, “Hermann Hesse”)
    • ISBN Number (e.g., “8743273565”, “1161120084”)
    • Availability Status (Available / Borrowed)
  • Add member functions to:
    • Set details of a book.
    • Borrow a book (mark it as “Borrowed”).
    • Return a book (mark it as “Available”).
    • Display the book’s details.
Expected Output
Book Details:  
Title: The Book of Mirdad  
Author: Mikhail Naimy
ISBN: 8743273565  
Status: Available  

// After borrowing the book  
Book Details:  
Title: The Book of Mirdad
Author: Mikhail Naimy
ISBN: 8743273565  
Status: Borrowed  

// After returning the book    
Book Details:  
Title: The Book of Mirdad
Author: Mikhail Naimy
ISBN: 8743273565  
Status: Available  

Q5.

What will be the output of the following programs?

You have to predict the output yourself without running/executing the code.


Q6.

Write a class named Point3d to represent a point in 3D cartesian coordinates.


Prev Post
Structure
Next Post
Access Functions, Constructor & Destructor (OOP)