Important questions of C++

🙀chapter wise important  questions of  C++

🙄Unit-I
✴️❗✳️❗✴️❗✳️❗✴️❗✳️❗✴️❗✳️❗

🔎Chapter-1:-🔍

  • 😻🔰Introduction to Oops.🔰😻


🤗1. Differences between C and C++. 


 CC++
1】C support procedural oriented programming paradigm for code development.1】C++ supports both procedural and object oriented programming paradigm.     
2】C supports top down approach.2】C++ supports bottom top approach.
3】When we compared to C++ ,c is a subset of C++3】 C++ superset of c
 4】C does not support object oriented programming paradigm. Therefore it has no support for polymorphism encapsulation and inheritance .4】Baingan object oriented programming language c++ supports polymorphism encapsulation and inheritance.
5】In C data and functions are separate entities therefore the mapping between functions is different and complex.5】In C++ data and functions are encapsulated together . Therefore the mapping between data and functions are easy.
6】In c data free entities and can be manipulted by the outside code . This is because of C does not support information hiding.6】In C++ encapsulation hides the data to ensure that the data is used as inheritation.

 7】C ,begins a procedural programming ,it is a function driven language.

7】C++, being an object oriented programming . It is an object driven language.
8】C uses functions for input and output .For example scanf and printf.8】C++ uses of objects for input and output . For example cin and  cout.
 9】C has no support of virtual and friend function.9】C++ supports a virtual and friend function
10】C provide maclloc() and calloc() functions for dynamic memory allocation and free for memory deallocation.10】C++ provides new operator for memory allocation and delete operator for memory deallocation
11】C obsen't provide support for error handling(Also call expectation handling)
11】C++ provide support for exception handling.
                                                                                

2.Applications of Oops(Object oriented programming).



                                                                

😲3. Concept of Oop's( object oriented programming)

Object oriented programming:-
>>As the name suggested object oriented programing used objects in programming.
>> object-oriented programming aims to implement the entities in programming.
>> The basic aim of oops is to bind together and function the operation on them. So, that no other part of the code can access this data except that function.

Basic concept (or) characteristics (or) features of oops.
The following are characteristics of oops
1.Class
2.Object
3.Encapsulation
4.Data abstraction
5.Inheritance
6.Polymorphism

💥💥】1.Class【💥💥
The concept of class is always used to developing the user defined data.
i] Class is a basic building block of object oriented programming.
ii] class hold its own  data members and member functions which can accessd and used by creating an instant of the class.
iii]Class is like a blueprint for an object.
iv] whenever we define a class there is no memory space for data members and associated methods of class.
Ex:- consider the CAR
>> there maybe many cars with different names and brands but all of them will share some common properties of will have four wheel, speed limit, mileage Range . So, here CAR is a class speed limit ,mileage range are properties and applications break increase speed etc.., are functions.

⚜️⚜️】2.Object【⚜️⚜️
An object is an instance of class . Instance is nothing but allocating sufficient memory for members of class.
i]whenever we define a class there is no memory space for data members and associated methods of class. When we create an object of a class memory space will be created for member of class.
ii] Real world entities are known as objects.
iii] Value from a class are known as objects.
Ex:- CAR-Class(absent-exist in real world).
       SWIFT CAR-Object(exist in real world).

✡️☯️】3.Data Obstruction【☯️✡️
Data abstraction represented to provide only  essential information to the outside world and finding their background details.
Ex:-if we consider a TV, we can turn off and on change ,the channels ,adjust the volume and add external components such as speaker and DVD player . But ,we don't know how they internally work.
➡️ In similar way in C + +, class provides great level of data abstraction they provide sufficient public methods to outside the world to play with the functions of the objects and to manipulate object data that is state without actually knowing how class has been implemented internally.
Ex:-Our program can make a call to the short() function. Without knowing what algorithms the functions available using for short() the given value.

✴️✳️】Encapsulation✳️✴️
Encapsulation is a process of combining data members and member functions into a single unit called class.
🖲️This is to prevent the access to the data directly the access to the data is provided through the function of class this is one of the popular future  of the object-oriented programming.

💢💥】5.Inheritance【💥💢
Inheritance is the capability of a class to acquire the properties and characters from another class.
♠️The class whose properties are inherited by another class is called parent (or) base (or) super class.
♠️ The class which inherited properties of another class is called child (or) derived (or) sub-class.
♠️When we inherited and exiting class, all its methods and Fields become available in the new class, hence the code is reduced.

🎄⚜️】6.Polymorphism【⚜️🎄
The word polymorphism means many forms.
Ex:-A person possesses different behaviour in a different situation ,at a some time is a father ,a husband ,an employee this is called the polymorphism.
In C++ polymorphism is mainly divided into types.
1.Compiler time polymorphism
2.Run time polymorphism.

🌲🌲i.Compiler time polymorphism
This type of polymorphism is achieved by function overloading (or) operator overloading.
♠️ function overloading means function with a same name . But, with a different number of augment (or) a type of augment (or) order of augment.

💥💥ii]Run time Polymorphyshism
This type of polymorphism is achieved by function overriding.
♠️ function overloading on other hand occurs  where we derived class has a define for one of the Member function of the base class. The base function is said to be overriding

                                                                                

】🔎Chapter-II 🔍


  • 😻🔰Introduction Of C++🔰😻

😘1.Datatype in C++

>>Datatype is a key word
>>Its main purpose is to allocate the memory for variable.
>> Datatypes specify the types of variable to be stored in the memory location.

Data types are three types
 I】Primitive (or) fundamental (or) Bullet in the datatype.
II】Derived data type.
III】User defined data type.

I】Primitive Data types 

It is the data type whose variables can store maximum 1 value.
 Primitive data types are mainly 4 types :
i]Integral data 
ii]Float datatype data type 
iii]Double datatype 
iv]Character data type

😜I]Integral data😜
>>It Can be identified with the keyword.
>>It can you should the handle integer values
>>Size of an entity type is 2 bytes
Range of int data type is - 2 ^15 2 + 2 ^ 15-1.(-32,768 to+32,767).
 ∆ Range represent the minimum and maximum value that are accepted by data type.
Ex:-int a=5;

😳ii]Float datatype data type😳
>> It can be identified with a float keyword
>> It can be used to identify a real data
>> Size of float data type is 4 bytes
>> Ranger funny float data type is - 2 ^ 32 ^ to+ 2^32
Ex:-float a=7.4;

😅iii]Double datatype😅 
>> It can be identified with double keyboard
>> It can be used to identify real data
>> Size of a double data type is 8 bytes
>> Range of funny double data type is 2 ^ 63to+2 ^ 63 - 1
Ex:-double a=1.6936

🙄iv]Character data type🙄
>>It  can be identified with char keyword
>>It can be used to identify the character data type.
>>Size of char data type is 1 bytes
>>Rang character data type -2 ^ 7to2^7 - 1
Ex:-char a='3';
       char a='z';

>> Character data type can handle single character directly what is the difference between float and double.
>> float occupies 4 bytes memory whereas double occupies 8 bytes in memory
>> float accept minimum 6 and maximum 8 extra fractions values where as double accept minimum and maximum 16 extra fractional values.
👽Data modifiers/Qualifier👽
These are the keywords used to change current property of datatypes.

💐Size Qualifiers:-
Type qualifiers altis the size of the basic data type that key words long and short after two size qualifiers
long:-
long is a keyboard which can be used before the in tour and it will add two bytes to the current data type size
Ex:-long int a=10;
(or)                   >>occupies 4bytes of memory
long a=10;
long double b=5.7987     >>Occupies 10 bytes
short:-
short is a keyword which can be used to allocate 2 bytes of memory irrespective of operating system 2bytes of memory in Windows operating system and 4 bytes of memory in Lunix operating system if be used short keyword before the into data type it can be allocated to bytes of memory in any operator system.
Ex:-short int a=10;
(or)        >>it occupies 2bytes of  memory in any operating system
short a=10;

💐Sign Qualifiers:-
Whether a variable can be hold only +ve value (or) both values specified by a sign qualifier. The keywords signed and unsigned are the two sign qualifiers.
Ex:-singned int a=10;
(or)
singned int a=-10;

💐Unsigned:-
Unsigned is a Keyword which will accept only positive values
Ex:-unsigned int a=10;
(Or).      >>a=10,a=-10 stories same value
unsigned int a=-10;

Derived Data types:-
>>Derived data types are the data types which variable can store more than one value of similar type.
>> Derived data types can be achieved by using array.
Array:- Array is collection of similar (or) homogenous data type.

User defined data types:-
These are the data types which variable can store more than one values of disimilar type.
TypeSize in bytes
char1
unsigned char1
signed char1
int2 (or) 4
unsigned int2 (or) 4
signed int2 (or) 4
short int2
long int4
unsigned short int2
signed short int2
long int4
unsigned long int4
signed long int4
float4
double8
long double10
                                                                                

😜2.Operators with Program.

→All 'C'-Operature are valid in C++ also in addition c++ introduce some new operators they are

Operator Symbol Operator Name
<<Insertion
 >>Extraction
:: Scope resolution
::*Pointer to member declaration
→*Pointer to member operator memory allocation operator
newMemory allocation operator
delete memory deallocation operator
endlline feed operator new line
setwfield width operator

i】Insertion operator(<<) & Extraction operator(>>):-
This two operators are used to insert and display the values as like as printf () and scanf().
Syntax:-
Extraction operator:-
cin>>variable-name;
Insertion
cout<<variable_name;
  • Program on Insertion & Extrration operatore.

#include<iostream.h>
int main()
{
int a;
cout<<"Enter a value\n";//Insertion operator
cin>>a; //Extraction operator
cout<<"a="<<a;
return 0;
}
Out put:-
Enter a value
8
a=8

ii】Scope Resolution Operator

This operator is used to access the Global variable but also has a local variable with a same variable name.

Syntax:-
::Variable_name;
 Return type<class_name>::method_name()
{
State_1;
State_2;
:
:
}
↣It used to define number of functions outside of the class.                         
Ex:-
#include<iostream.h>
int a=30;
int main()
{
int a=20;
cout<<"::a="<<::a<<"\n";
cout<<"a="<<a;
return 0;
}
Out put:-
::a=30
a=20

New operator:-
It is used to allocate memory dynamically

Syntax:-
Pointer variable= new operator data_type;
⇒ The new operator can be used an object of any data type
⇒ In the pointer variable is a point of type data type then new operator allocate memory to hold a data objects of type data type.
Ex:-p=new int;
Program on new operator
#include<iostream.h>
#include<conio.h>
int main()
{
int *p,n,i;
clrscr();
cout<<"Enter size\n";
cin>>n;
p=new int[n];
cout<<"Enter"<<n<<"value\n";
for(i=0;i<n;i++)
cin>>*(p+i);
for(i=0;i<n;i++)
cout<<"\n Enter value is"<<*(p+i);
getch();
}
Out put:-
Enter size
3
Enter 3 value
5
7
9

 Enter value is5
 Enter value is7
 Enter value is9
[Program finished]

Delete operator
:-
⇒It is used to release dynamic allocate memory.

Syntax:-
detete [] variable;
Ex:-delete []a;
Program on delete operator
#include<iostream.h>
#include<conio.h>
int main()
{
int *p,n,i;
clrscr();
cout<<"Enter size\n";
cin>>n;
p=new int[n];
cout<<"Enter"<<n<<"value\n";
for(i=0;i<n;i++)
cin>>*(p+i);
for(i=0;i<n;i++)
cout<<"\n Enter value is"<<*(p+i);
delete [] n;
getch();
}
Out put:-
Enter size
3
Enter 3 value
5
7
9

 Enter value is5
 Enter value is7
 Enter value is9
[Program finished]

Manipulators in CPP:-
⇒ manipulators are used to manipulate or change the output
⇒ manipulators are endl,setw()
The head file for manipulators is iomanip.h
endl:-
endl is used to new line fetch
#include<iostream.h>
#include<conio.h>
int main()
{
int a,b;
clrscr();
cout<<"Enter a,b values"<<endl;
cin>>a>>b;
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
getch();
}
Out put:-
Enter a,b values
4
7
a=4
b=7

[Program finished]
Setw ():-
setw() sets the number of characters to be used as the field width for the next enseration operation.
⇒setw() is declared inside iomaip.h
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
cout<<"with out setw()"<<endl;
cout<<"1"<<endl<<"11"<<endl;
cout<<"111"<<endl;
cout<<"with setw()"<<endl;
cout<<setw(4)<<"1"<<endl;
cout<<setw(4)<<"11"<<endl;
cout<<setw(4)<<"111"<<endl;
return 0;
}
Out put:-
with out setw()
1
11
111
with setw()
     1
   11
 111

[Program finished]
                                                                            
😲3.Type casting.{short}

Reference variable:-
Reference variable produces an aliens ( alternative name) feel a precously defined variable.
Syntax:-
data type &reference_variable_nm=variable_nm;
Ex:-int sum=100;
int &total=sum;
⇒ handsome is the inter type variable that has already been declared and total is the alternative name declared to the present variable sum.
cout<<sum;
cout<<total;
⇒ Both statement prints the value 100
Sum=sum+20;
Will change the value of both total and sum.
⇒A reference variable must be initialised at the time of declaration.
⇒Hence, both the variable sum and the total reference to the same letter object in the memory.
⇒Hence, "&" percent is not an address operator.
Program on reference variable.
#include<iostream.h>
int main()
{
int sum=200;
int & total=sum;
cout<<"sum="<<sum<<"\ntotal="<<total;
sum=sum+30;
cout<<"\nsum="<<sum<<"\ntotal="<<total;
    total=total+30;
    cout<<"sum="<<sum<<"\ntotal="<<total;
    return 0;
}
Out put:-
sum=200
total=200
sum=230
total=230
sum=260
total=260
[Program finished]

                                                                                

🙄Unit-II
✴️❗✳️❗✴️❗✳️❗✴️❗✳️❗✴️❗✳️❗

🔎Chapter-3:-🔍

  • 😻🔰Classes & Object,Arrays🔰😻
1.Scope Resolution operator with Program{short}.
Scope Resolution Operator

This operator is used to access the Global variable but also has a local variable with a same variable name.

Syntax:-
::Variable_name;
Return type<class_name>::method_name()
{
State_1;
State_2;
:
:
}
↣It used to define number of functions outside of the class.
Ex:-
#include<iostream.h>
#include<conio.h>
class maximum
{
int a,b;
public:
void accept()
{
cout<<"Enter a,b values\n";
cin>>a>>b;
}

void max();
};
void maximum::max()
{
if(a>b)
cout<<"a is maximum";
cout<<"b is maximum";
}
int main()
{
maximum m;
m.accept();
m.max();
getch();
}
Out put:-
Enter a,b values
7
4
a is maximumb is maximum
[Program finished]
2.Example program with class{short}
#include<iostream.h>
#include<conio.h>
class maximum
{
int a,b;
public:
void accept()
{
cout<<"Enter a,b values\n";
cin>>a>>b;
}

void max();
{
if(a>b)
cout<<"a is maximum";
cout<<"b is maximum";
}
};
int main()
{
maximum m;
m.accept();
m.max();
getch();

}
Out put:-
Enter a,b values
7
4
a is maximumb is maximum
[Program finished]
✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️
3,4,5,6 questions are their in c++ labprogram so I provide a link bellow with 8,9,10,14 in that blog..
Click on this link:-3)Array of object-8 /4)Bubble sort -9 /5)linear search-10 /6)matrix multiplication-14
✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️✍️

                                                                               

🔎Chapter-4:-🔍
🔰😻Introduction to Array😻🔰
1.Pass by valu, pass by reference , call by reference
a】Call by value

⇒ In Call by Value the value that is fast is not changed after foming some operations on it.
⇒ In Call by Value it creates at caps of the variable into stack memory or stack section
⇒ when the value is changes the change value create a copy with actual value remaining the change
Ex:-
#include<iostream.h>
#include<conio.h>
class abc
{
public:
void add(int a,int b)
{
int c;
c=a+b;
cout<<"c="<<c;
}
};
int main()
{
abc s;
clrscr();
s.add(4,5);
getch();
}
b】pass by reference

⇒In Call by Reference function we pass the arguments with reference variable by using emperent
⇒In Call by Reference, actual value is passed as the argument ,it argument is changed after forming some options on it
⇒When Call by Reference it use it create the Call by Reference a copy of reference into the copy of the reference into the Stark section of memory.
⇒In Call by Reference if the value is modified than the actual value is also modified.
⇒In Call by Value it an independent passing of argument is an dependent passing by argument.
#include<iostream.h>
class test
{
int a;
public:
void change(int &a)
{
a=6;
cout<<"a="<<a<<endl;
}
};
int main()
{
test t;
int a=9;
t.change(a);
cout<<"a="<<a<<endl;
return 0;
}
c】call by reference 

 In call by address is a new process introduced in C + +
⇒ In call by address with pass pointer variable as an argument and it invoke the function call by reference address of respective Pointer variable such type of calling function is known as call by address
⇒ In call by address we use pointer variable to send exact memory address.
⇒ call by address is similar to the call by reference.
#include<iostream.h>
class test
{
int a,b,t;
public:
void change(int *a,int *b)
{
    t=*a;
    *a=*b;
    *b=t;
}
};
int main()
{
test s;
int a=9,b=7;
  cout<<"Before swap\na="<<a<<"\nb="<<b;
s.change(&a,&b);
cout<<"\nafter swap\na="<<a<<"\nb="<<b;
return 0;
}
2.Inline function{short} 
Inline function:-
⇒ One of the objective of the using function in the programming is to save memory space
⇒ If we call the same some functions in many times for moving of cursor here and there to overcome this problem c++ introduce a new concept called inline
⇒ inline is a Keyword which replaces the function call with function definition
⇒ Situation where inline function not works.

  1. If function contain condition statement 
  2. If function return values ,if a return statement exists 
  3. Function contain static variable.
  4. If inline function are recursive. 

Syntax:-
inline data_type  function_name()
{
Function body;
}
Ex:-
inline int sq(int a)
{
return (a*a);
}
                                                                                
3.Function Overloading

 ⇒In  C++ function overloading is any polymorphism is a represented Static Binding or compile time polymorphism function overloading is Defined by defined some functions and name multiple times and different sisnitures is known as function overloading.
⇒It is the process of using the same function name for different functions.
 Rules for function Over loading:- 

⇒In function overloading same function is define more than one time or multiple times.
⇒In function overloading process overloading function differ in passing arguments.
⇒In overloading function Defined by the differentiating in return type function overloading.
Note:-
⇒In function overloading whenever function is called prototype suitable to function is such type of function is known as the function polymorphism.
Syntax:-
Return_type  function_name()
{
Function body;
}
Return_type fun_nm(argumentes list)
{
Function body;
}
Ex:-
void f1()
{
cout<<"hello";
}
int f1(int x)
{
return x;
}
char f1(char ch)
{
return ch;
}
Sample program:-

#include<iostream.h>
class test
{
int a,b;
public:
void sum()
{
int a=5,b=8;
cout<<(a+b)<<endl;
}
int sum(int x,int y)
{
return x+y;
}
float sum(float x,float y,float z)
{
return (x+y+z);
}
};

int main()
{
test t;
t.sum();
cout<<"call 2:"<<t.sum(3,5);
cout<<"\n call 3:"<<t.sum(2.5,5.6,7.3);
        return 0;

}
Out put:-
13
 call 2:8
 call 3:15.4
[Program finished]
                                                                                

It completed answer will be uploaded soon.
4.Object as function argument's .
⇒In C++ we pass arruguments as objects with in specified function name.
⇒In C++ we define object as an arrugument
Using respective class name.
Syntax:-
Return_type  function_name(class_nm obj_nm);
Ex:-
Void disp (demo obj);
 ⇒In passing argument as an object into method we access the specified method by using object and by passing object.
Syntax:-
Class name obj_nm;
Return_type  function_name(class name);
Ex:-
Obj.disp(obj)

                                                                                

🔎Chapter-5:-🔍
🔰😻constructors and destructors inheritance 😻🔰
1.Type of Constructors.

⇒In C++  a constructor is an special Member function which automatically gets called . Whenever, the object of a class is initialised.
⇒The constructor is defined by defining the Member function or method name and class name are same or similar.
↦There are four types of constructors . They are
A】Default Constructor
⇒Constructor are accessed automatically, when the object is initialised or created.
⇒ one's object is created constructors are invoked automatically.
Syntax:-
Class_name <object_name>;
Ex:-A.obj;
  • Sample program
#include<iostream.h>
class x
{
public:
x()
{
cout<<"Hi shashi";
}};
int main()
{
x a;
return 0;
}
B】Parameterized Constructor

⇒In C++, Parametrized Constructor is as like as default constructor .But, the constructor which has the arruguments is known as the Parameterized Constructor.
  • Sample program
#include<iostream.h>
class area
{
public:
area(double r)
{
cout<<"area of circle="<<(r*r*3.14)<<endl;
}};
int main()
{
area a(3.5);
return 0;
}
C】Copy Constructor
⇒A copy constructor is a Member function which initializes an object using another object of the same class.


  • Sample program

#include<iostream.h>
class emp
{
int id;
public:
emp();
emp(int s)
{
id=s;
}
emp(emp &a)
{
id=a.id;
}
void show()
{cout<<id; }
};
int main()
{
  emp x(50);
  emp y(x);
  emp z=x;
  emp t=x;
  cout<<"id of x=";
   x.show();
  cout<<"\nid of y=";
    y.show();
  cout<<"\nid of z=";
    z.show();
  cout<<"\nid of t=";
    t.show();
return 0;
}

Remaining questions are present in other blog{online classes blog} 
That link is provided here 👉Click here

Comments

Popular posts from this blog

History of C language

Lab programs of C

Algorithm Pseudopods Flow-chat