C++ quick revision assignment question answer

C++  quick  revision assignment question answer

C++  quick  revision assignment ,C++ question answer , C++ most questions 

C++  quick  revision assignment ,C++ question answer , C++ most questions

Q 1. Explain different types of the manipulator in c++?

 Ans:- Manipulator:- Manipulators are helping functions that can modify the input or output stream. It

does not mean that we change the value of a variable, it only modifies the I/O stream using insertion

(<<) and extraction (>>) operators.

 Types of Manipulators:

1. Manipulators without arguments:- The most important manipulators defined by the IOStream

library are provided below.

·       endl: It is defined in ostream. It is used to enter a new line and after entering a new line it flushes the output stream.

·       ends: It is also defined in ostream and it inserts a null character into the output stream. 

·       flush: It is also defined in ostream and it flushes the output stream that is  it push or pull all the output written on the screen or in the file. 


2. Manipulators with Arguments: Some of the manipulators are used with the argument like setw (20),

setfill (‘*’) and many more. These all are defined in the header file. If we want to use these manipulators  then we must include this header file in our program. 


● Some important manipulators in <iomanip> are:

1. setw (val): It is used to sets the field width in output operations.

2. setfill (c): It is used to fill the character ‘c’ on output stream.

3. setprecision (val): It sets val as the new value for the precision of floating-point values.

4. setbase(val): It is used to set the numeric base value for numeric values.

5. setiosflags(flag): It is used to sets the format flags specified by parameter mask.

6. resetiosflags(m): It is used to resets the format flags specified by parameter mask.


● Some important manipulators in <ios> are:

1. Showpos: It forces to show a positive sign on positive numbers.

2. No showpos: It forces not to write a positive sign on positive numbers.

3. Show base: It indicates numeric base of numeric values.

4. Uppercase: It forces uppercase letters for numeric values.

5. No uppercase: It forces lowercase letters for numeric values.


6. fixed: It uses decimal notation for ?oating-point values.

7. scientific: It uses scientific floating-point notation.

8. hex: Read and write hexadecimal values for integers and it works the same as    the setbase(16).

9. dec: Read and write decimal values for integers i.e. setbase(10).

10.oct: Read and write octal values for integers i.e. setbase(10).

11.left: It adjusts output to the left.

12.right: It adjusts output to the right.



Q 2. Write a short note on - nested class, local class & abstract class?


Nested class:-

·       Class  inside  a class is called nested  class.

Class member  and  such  has  the  same  access   rights  as  any  other  member.


Example :-


using namespace std;

/* start of Enclosing class declaration */

class Enclosing {


int x;

/* start of Nested class declaration */

class Nested {

int y;

void NestedFun(Enclosing *e) {

cout<<”e->x”; // works fine: nested class can access

// private members of Enclosing class



}; // declaration Nested class ends here

}; // declaration Enclosing class ends here

int main()




Local class:-

 A class declared inside a function becomes local to that function and is called Local Class in C++.

For example, in the following program, Test is a local class in fun().



using namespace std;

void fun()


class Test // local to fun


/* members of Test class */



int main()


return 0;



Abstract class:-

 An abstract class is, conceptually, a class that cannot be instantiated and is usually implemented  as  a class that has one or more pure virtual (abstract) functions. In general, an abstract class is used to define  the implementation and is intended to be inherited from concrete classes.

 class AbstractClass

{ public:

virtual void AbstractMemberFunction() = 0; // Pure virtual function makes

// this class Abstract class.

virtual void NonAbstractMemberFunction1(); // Virtual function.

void NonAbstractMemberFunction2();



Q.3 How data hiding concept supports the c++? Justify your answer.


Data hiding concept:- In simple words, data hiding is an object-oriented programming  technique of hiding internal object details i.e. data members. Data hiding guarantees restricted data access to class members & maintain object integrity. Data hiding is a process of combining data and functions into a single unit. The ideology behind data hiding is to conceal data within a class, to  prevent its direct access from outside the class. It helps programmers to create classes with unique  data sets and functions, avoiding unnecessary penetration from other program classes.


There are three types of protection/access specifiers available within a class:-

 1. Private members/methods can only be accessed by methods defined as part of the class. Data is most  often defined as private to prevent direct outside access from other classes. Private members can be  accessed  by members of the class.

 2. Public members/methods  can  be  accessed  from  anywhere  in  the  program. Class methods  are  usually   public  which  is  used  to  manipulate  the  data  present  in  the class . As  a  general  rule, data should not be  declared public. Public members can be accessed by members and objects of the class.

 3. Protected member/methods are private within a class and are available for private access in the  derived class.

 Eg:- Data hiding-


using namespace std;

class Base{

int num; //by default private


void read();

void print();


void Base :: read(){

cout<<"Enter any Integer value"<<endl; cin>>num;


void Base :: print()


cout<<"The value is "<<num<<endl;


int main(){

Base obj;



return 0;



Output:-Enter any integer value 5

The value is 5


Post a Comment