C++ Interview Questions

Showing Questions 321 - 340 of 350 Questions
First | Prev | Next | Last Page
Sort by: 
 | 
Jump to Page:
  •  

    Read the following code and then implement the following parts:

    Read the following code and then implement the following parts:

    class Point {
    public int xCoordinate;
    public int yCoordinate;
    }

    1. Derive a class from Point and call it DerivedPoint, the new class will contain two constructors, the first one takes no arguments, it assigns the point to the point (1,1) and the second constructor takes two parameters...

    kladarak

    • Nov 28th, 2015

    danarusus answer was pretty much there, but there are a few things that could be improved with it. - Display() doesnt output x and y coords in exactly the format requested. There should be no space...

    ThePurpleTwist

    • Nov 12th, 2015

    There is a mistake in the code submitted by chandra ;
    DerivedPoint : public Point instead of "::"

  •  

    Permutations

    Write a program to display all possible permutations of a given input string--if the string contains duplicate characters, you may have multiple repeated results. Here is a sample for the input cat
    cat,cta,act,atc,tac,tca

    Jin Hyuk Cho

    • Feb 3rd, 2016

    A working example

    Code
    1. #include <iostream>
    2. #include <string>
    3. #include <set>
    4. #include <sstream>
    5. // constructing remaining characters
    6. // constructing empty set for results
    7. //cout << onePermute << endl;
    8. " ""Done!"

    neha

    • Aug 27th, 2015

    plz see below code"cpp #include #include using namespace std; void Permutations(string str) { for(int i = 0; i < str.size(); i++) ...

  •  

    Solve this using C++ code

    Write a solution in any language to the following: Given a large list of integers (more than 1 000 000 values) find how many ways there are of selecting two of them that add up to 0

    Jin Hyuk Cho

    • Feb 8th, 2016

    O(n) solution"cpp #include #include #include #include #include #include // std::locale, std::isdigit #include #include #include #include int findTwoSu...

    dada

    • Feb 7th, 2016

    This solution is O(n)"cpp #include #include #include #include #include using namespace std; #define MAX_NUM 10000 int main() { vector in(MAX_NUM); //input data...

  •  

    Use of OOPs in C++

    What is the use of object oriented system?

    Aarish

    • Apr 20th, 2016

    An object-oriented operating system is an operating system that uses methods of object-oriented programming. An object-oriented operating system is in contrast to an object-oriented user interface or...

  •  

    What do you mean by inheritance?

    Inheritance is the process of creating new classes, called derived classes, from existing classes or base classes. The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of its own.  

    anamika

    • Jun 14th, 2016

    Multiple Inheritance is not used in Java

    shylu

    • Jun 22nd, 2012

    It is a process that one class can acquires the properties of another base class

  •  

    What is the difference between an object and a class?

     Classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects.  Ø      A Class is static. All of the attributes of a class are fixed before, during, and after the execution of a program. The attributes of a class don't change. Ø       The class to which an...

    Minh Nguyen

    • Jun 27th, 2016

    A class is an user-defined data structure and an object is an instance of that class.

    Jumana iqbal

    • Apr 24th, 2016

    Class is a user degined data type, the variables of class known as object, which are the central focus of object oriented programming

  •  

    Virtual Constructor

    Why constructor cannot be virtual in C++?

    James Thompson

    • Aug 23rd, 2016

    Because the virtual pointer table isnt initialised till after the constructor is complete.

    Aarish

    • Apr 20th, 2016

    Advanced C++ | Virtual Constructor Can we make a class constructor virtual in C++ to create polymorphic objects? No. C++ being static typed (the purpose of RTTI is different) language, it is meaningl...

  •  

    Array in Function

    Write C++ program tell the user
    Press 1 to change Row to Row and change (using Function ) output like that :
    1 1 1
    2 2 2
    3 3 3
    and press 2 to change Row to Col and change (using function) output like that :
    1 2 3
    1 2 3
    1 2 3
    and press 0 to End the Program

    mayank

    • Sep 7th, 2016

    Code
    1. #include <iostream>
    2. " ""
    3. "" ""
    4. "" enter the number 0,1,or 2:""
    5. Hello world!"

  •  

    Flowchart

    an electricity board charges the following rates to domestic users to discourage large consumption of energy:
    for the first 100 units - 10 paise per unit 
     for next 200 units - 20 paisa per unit
     beyond 300 units - 30 paisa per unit . if the total cost is more than 10 OMR then an additional surcharge of 15% is added.draw the flowchart and write the algorithm to calculate the...

    Ted

    • Oct 17th, 2016

    1 start
    2 Input U for unit
    3 If U

  •  

    What is the difference between class and structure?

    Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public. Class: Class is a successor of Structure. By default all the members inside the class are private.

    Star Read Best Answer

    Editorial / Best Answer

    sumitv  

    • Member Since Sep-2008 | Sep 4th, 2008


    Structure does support inheritance.

    try out the following code.

    #include<iostream>

    using namespace std;

    struct Base
    {
        int A;
    };

    struct Derived:public Base
    {
        int B;
        void display();
    };

    void Derived::display()
    {
        cout<<endl<<"A = "<<A<<endl;
    }

    int main()
    {
        Derived D;
        D.A = 111;
        D.display();
        getchar();
        return 0;
    }

    Try out private and protected inheritance as well. It works. :)

    Regards,
    Sumit

    Sajeed Ullah

    • Dec 2nd, 2016

    All data members of the class is by default private,
    Whereas all data members of structure is by default public.

    Ashish

    • Mar 24th, 2016

    Beware, whatever is supported by a class is also supported by struct whether its inheritance, polymorphism, encapsulation, data hiding etc. etc. as of C++ 11. Only difference is, for a class default access specifier is private whereas for struct its public.

  •  

    C++ Macros Functionality

    What is the main thing that C++ macros can do that cannot be done with functions? Give a realistically useful example of something of this kind.

    Macros have the distinct advantage of being more efficient than functions, because their corresponding code is inserted directly into your source code at the point where the macro is called. There is no overhead involved in using a macro like...

    Joe Fitzgerald

    • Jun 5th, 2017

    Use macros for an "include guard" only to avoid duplicate definition of types. Macros should be avoided in most other cases in C++ since they are not type safe, fail to respect scoping rules, and the...

    EigenCritic@gmail.com

    • Apr 6th, 2016

    People usually say that using macros in C++ should be avoided. But there are exceptions, especially regarding meta programming, debugging, profiling and for cross-platform code switches. You can use...

  •  

    What is Namespace?

    Girish

    • Jul 20th, 2017

    We cannot have two variables with the same name in the same scope. To resolve this namespace is introduced. Namespace is a declarative region that provides a scope to the identifiers inside it. Acces...

    dinu

    • Oct 3rd, 2016

    Suppose we have two libraries lib1 and lib2. let there is a function add() present in both of them, this function can have different meaning or functionality in both libraries but they have same name...

  •  

    What is polymorphism? Explain with an example?  

    "Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms of object. Example: function overloading, function overriding, virtual functions. Another example can be a plus ‘+’ sign, used for adding two integers or for using it to concatenate two strings.  

    Tech4 u

    • Jul 22nd, 2017

    The ability to define more than one function with the same name is called polymorphism.

    This provides the facility of sending the same message to objects of parent class and objects of the sub classes.

    sunil

    • Feb 26th, 2017

    Several forms having same name is called polymorphism.
    We have two types of polymorphism in C++.
    1) Compile time Polymorphism or function overloading
    2) Runtime Polymorphism or function overriding

  •  

    What is difference between copy constructor and constructor?

    Amiya Pani Kjr Odisa

    • Aug 17th, 2017

    Constructor create object. From scratch but Copy constructor create from existing object. Constructor creates new object. Copy constructor creates clone of existing object.

    Anurag Verma

    • Aug 7th, 2006

    Constructor is called when an object is created.Copy constructor is called when the copy of an object is made. For e.g. passing parameter to function by value, function returning by value. Copy constructor takes the parameter as const reference to the object.

  •  

    Abstract class - can we create pointer to abstract class?

    Sushant Narayan

    • Sep 7th, 2017

    Yes, we can create pointer to abstract class.

    matthew

    • Sep 27th, 2016

    No you can make a pointer to an instance of a concrete class that derives from the abstract class, but you cant have a pointer to a class itself unless you mean some sort of metaprogramming type logic.

  •  

    What is the difference between function overloading and operator overloading?

    Krishna Agrawal

    • Dec 7th, 2017

    In order to overload function ex: void add(int x=5, int y=8) now just call in mains add(), then call add(5), then call add(3,3) in three instances function will work accordingly but in operator overlo...

    Zebo Li

    • Jan 26th, 2017

    Is the following example a function overloading?
    double max(double, double)
    int max(int, int)
    They have different return types.

  •  

    Write Object into a File

    How will you write object into file using file concepts in C++?

    Arman

    • Jan 25th, 2018

    You can write the object into file after serializing it. It is important to note that there are two types of objects: "persistence" and "non persistence". persistence objects are those which can be serialized and saved in file system.

    hi

    • Nov 9th, 2016

    I think the final fobj.display_detail(); in your code needs to change to eobj.display_detail();

Showing Questions 321 - 340 of 350 Questions
First | Prev | Next | Last Page
Sort by: 
 | 
Jump to Page: