Skip to main content

C++ Important questions OOP's and Data Structures (Assignment Questions)


PAPER 1st

QUESTION:1

 Explain Features of OOP's


There are a few principle concepts and features that form the foundation of object-oriented programming −

Object

This is the basic unit of object oriented programming. That is both data and function that operate on data are bundled as a unit called as object.

Class

When you define a class, you define a blueprint for an object. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object.

Abstraction

Data abstraction refers to, providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details.

For example, a database system hides certain details of how data is stored and created and maintained. Similar way, C++ classes provides different methods to the outside world without giving internal detail about those methods and data.

Encapsulation

Encapsulation is placing the data and the functions that work on that data in the same place. While working with procedural languages, it is not always clear which functions work on which variables but object-oriented programming provides you framework to place the data and the relevant functions together in the same object.

Inheritance

One of the most useful aspects of object-oriented programming is code reusability. As the name suggests Inheritance is the process of forming a new class from an existing class that is from the existing class called as base class, new class is formed called as derived class.

This is a very important concept of object-oriented programming since this feature helps to reduce the code size.

Polymorphism

The ability to use an operator or function in different ways in other words giving different meaning or functions to the operators or functions is called polymorphism. Poly refers to many. That is a single function or an operator functioning in many ways different upon the usage is called polymorphism.

Overloading

The concept of overloading is also a branch of polymorphism. When the exiting operator or function is made to operate on new data type, it is said to be overloaded.

[SUBSCRIBE]

QUESTION:2

What is Class? Write a Program to demonstrate the use of a class

class in C++ is a user defined data type or data Structures declared with keywords class that has data and functions (also called members variables and member functions) as its members whose access is governed by the three access specifier privateprotected or public. By default access to members of a C++ class is private


C++ Program to Demonstrate the use of a class


// Program to illustrate the working of

// objects and class in C++ Programming

#include <iostream>

using namespace std;

// create a class

class Room {

   public:

    double length;

    double breadth;

    double height;

    double calculateArea() {

        return length * breadth;

    }

    double calculateVolume() {

        return length * breadth * height;

    }

};

int main() {

    // create object of Room class

    Room room1;

    // assign values to data members

    room1.length = 42.5;

    room1.breadth = 30.8;

    room1.height = 19.2;

    // calculate and display the area and volume of the room

    cout << "Area of Room = " << room1.calculateArea() << endl;

    cout << "Volume of Room = " << room1.calculateVolume() << endl;

    return 0;

}


Output

Area of Room = 1309

Volume of Room = 25132.8


[SUBSCRIBE]




QUESTION:3

What is Friend functions? Explain with the Help of an Example

A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.

A friend can be a function, function template, or member function, or a class or class template, in which case the entire class and all of its members are friends.


Example:-

// C++ program to demonstrate the working of friend function

#include <iostream>

using namespace std;

class Distance {

    private:

        int meter;   

        // friend function

        friend int addFive(Distance);

    public:

        Distance() : meter(0) {} 

};

// friend function definition

int addFive(Distance d) {

    //accessing private members from the friend function

    d.meter += 5;

    return d.meter;

}

int main() {

    Distance D;

    cout << "Distance: " << addFive(D);

    return 0;

}


Output

Distance: 5

[SUBSCRIBE]

QUESTION:4

What is Operator Overloading? Explain with an Example?

Operator overloading is a compile-time polymorphism in which the operator is overloaded to provide the special meaning to the user-defined data type. Operator overloading is used to overload or redefines most of the operators available in C++. It is used to perform the operation on the user-defined data type.


Example:-

// Overload ++ when used as prefix

#include <iostream>

using namespace std;

class Count {

   private:

    int value;

   public:

    // Constructor to initialize count to 5

    Count() : value(5) {}

    // Overload ++ when used as prefix

    void operator ++ () {

        ++value;

    }

    void display() {

        cout << "Count: " << value << endl;

    }

};

int main() {

    Count count1;

    // Call the "void operator ++ ()" function

    ++count1;

    count1.display();

    return 0;

}


Output

Count: 6

[SUBSCRIBE]

QUESTION:5

Discuss Various File Modes

Type of Modes are:-

ios::in

This ios prefix is used to open a file to read input from the user.

ios::out

This ios prefix is used to open a file to write the output from the user.

ios::ate

This ios prefix is used to open a file without truncating and allows data to be written anywhere in the mentioned file.

ios::trunc

 This ios prefix is used to truncate the existing file.

ios::app

This ios prefix is used to open a file and append it to the end.

ios::binary

This ios prefix is used to treat the given file as a binary format.

Comments

Popular posts from this blog

Physics assignment Paper 1 (Important questions)

QUESTION:1   Explain the fermet's Principle Fermat's principle , also known as the  principle of least time , is the link between  ray optics  and  wave optics . In its original "strong" form,  Fermat's principle states that the path taken by  a ray  between two given points is the path that can be traversed in the least time. In order to be true in all cases, this statement must be weakened by replacing the "least" time with a time that is " stationary " with respect to variations of the path — so that a deviation in the path causes, at most, a  second-order  change in the traversal time. To put it loosely, a ray path is surrounded by close paths that can be traversed in  very  close times. It  can be shown  that this technical definition corresponds to more intuitive notions of a ray, such as a line of sight or the path of a narrow beam. QUESTION:2 Find the Resultants Amplitude and Intensity of the Princip...

What is HTML or HTML tags

HTML 1) HTML stands for Hyper Text Markup Language 2) Created by Ten Berners-Lie in 1991 but published in 1995 3) It is Client side web technology. 4) It has predefined elements are called tags, used to"markup" a text documents. HTML TAGS 1 <html>_____</html>     Declare the Web page to be written in HTML. 2 <head>_____</head>       Delimits the pages head. 3 <title>______</title>       Defines the title.(not display on the page) 4 <body>_____</body>      Delimits the pages body. 4 <hn>_____</hn>      Delimits a level in heading. 5 <b>_____</b>      Set in boldface 6 <i>_____</i>       Set in italics. 7 <center>_____</center>      Center on the page horizontal. 8 <ul>_____</ul>     ...

क्या 21 जून को खत्म हो जाएगी दुनिया ― News

क्या 21 जून को खत्म हो जाएगी दुनिया दिनांक― 21 जून 2020 कोरोना वायरस महासंकट के बीच एक और दावा किया जा रहा है कि 21 जून को खत्म हो जाएगी दुनिया। हमारे भविस्यवक्ताओं का कहना है कि 21 जून को दुनिया खत्म हो जाएगी।यहां कोरोना ने पूरी दुनिया में तबाही मचाई है, अब दूसरी खबर आ रही है कि 21 जून को खत्म हो जाएगी दुनिया।                         इस दावे के पीछे का कारण ग्रेगोरियन कैलेंडर बता रहें हैं। अथवा ग्रेगोरियन कैलेंडर के अनुसार 21 जून दुनिया के लिए विनाशकारी है। इस कैलेंडर को 1752 में लागू किया गया था।         वहीं दूसरी ओर अगर हम जूलियन कैलेंडर को फ़ॉलो करें तो हम अभी 2012 में ही हैं। वैज्ञानिक पाओलो तगलोगुइन के ट्वीट के अनुसार 21 जून को दुनिया तबाह हो जाएगी। अब यह बात कहां तक सत्य है, यह कहना मुश्किल है।