Q1. Discuss the unique features of C++, also illustrate how C++ is better than C
Language.
Ans:
C++ is a complied language.and an object oriented programming language.its main purpose was to
make writing good program easily which will be more pleasant for individual user . C++ is a
suspect of c.in addition to feature provided by c ,c++ provides flexible and efficient feature to set
out new types (classes). C++ is based on the concept of oops(object oriented programming), so oops
provide data hiding.and in the other hand in the c language function gets more importance than
data.but in c++ data get more importance than function.so c++ is better than c .
Features of C++
Abstraction supports data hiding so that only relevant information is exposed to the user and rest of the
information remains hidden from the user.
Encapsulation: Encapsulation is the mechanism that binds together code and the data it manipulates, and
keeps both safe from outside interference and misuse.
Polymorphism: In simple terms, polymorphism is the attribute that allows one interface to control access
to a general class of actions.
Inheritence : A class may then be inherited by other, more specific classes, each adding only those things
that are unique to the inheriting class.
ans. If we declare a function with the keyword inline, thecompiler does not create a one copy of real: it
copies the code where the function call have been made. In inline fnction, if the function is called 5 times,
the code of functin is copied into the calling function each of those 5 time. It will improve the speed of
the program but increase the size of the executable program.
Inline function-header
Function body
Function over loading is a logical method of calling several function by same name, with different
argument and data types which basicallyt perform identical things.
For exmple, we may create a function call copy which would work with char, int and float data types as
given below:
char* copy(char*);
int copy(int);
float copy(float);
the above three function use the same name copy() but work with different data types.it shows that the
function copy() is overloaded therby meaning that it has more than one implementation.
Q3.Discuss with the help of an example various parts of the Class Specification.
Ans class is an expanded form of a data structure:instead of holding data, it can hold both data and
functions. An object is an instantiaion of a class. In terms of variable, aclass would be the type, and an
object would be the variable.
Private:
Private accesibility means that member within a class can only be accessed by that class.
Protected:
Protected accessibility means that members within in a class can be accessed by member function
declared by that class any classes “inherited” from that class.
Public;
Public accessibility means that members within a class can be access by any part of a program.
Classes are generally declare using the keyword class, with tha following foemat:
Class class_name
private :
Function declarations;
Protected:
Function declarations;
Public:
Function declarations;
for example:
class student
Int id_no;
Protected:
Int roll_no;
Public:
Void getdata(void;)
Void display(void)
Q4. Justify the use of the various Access Specifiers, Is there any particular order in
Private :- A section function can only be called by another function that is a member of its class. By
default, all tha members of a class are private. Such a class is hidden from the world and do not serve
any purpose.
Public :- a public function can be accessed by a function outside class by the help of an object. Usually,
all the functions are to be declared as public.
Protected:-It can only be called by another function that is the member of the class like private. But it
can be inherited too.
There is no defined order in which the access specifiers have to be used. Once an access specifier has been used, it
remains in effect until either another access specifier is encountered or the end of the class declaration is reached.
For example, we may switch to public for some declarations and then switch back to private again.
PART B
Q5. Give a comparison between Private Section and Protected Section in a Class with
ans:
Private section
Protected section
Public section
class Abs
private:
int x;
protected:
int y;
public:
int z;
void initial()
x=10;
y=30;
z=40;
};
void main()
Abs Z;
Z.initial();
Z.z=22;
}
in private section,
private members of a class are accessible only from within other members of the same class or
from their friend.
It is visible to member functions
In protected section,
Protected members are accessible from members of their same class and from their friends but
also from members of their derived classed.
It is visible to member functions of its own and derived class.
Data member:
Accesion no.
Author name
Publisher
Member of function;
Answer:
#include<iostream.h>
#include<conio.h>
class book
private:
int accesion_no;
char title;
char author_name;
char publisher;
public:
void get_info(void);
void display(void);
};
void book::get_info(void)
cin>>accesion_no;
cin>>title;
cin>>author_name;
cin>>publisher;
void main()
clrscr();
book b;
int i=0;
b.get_info();
clrscr();
cout<<"_";
cout<<"\n
";
b.display();
getch();
OUTPUT:
Q7. Discuss the various applications of Scope Resolution Operator in various
Circumstances.
Ans: Scope resolution operator is used to define a member of a class from outside the class declaration
itself.
We need to use the scope resolution operator (::) along with the class name in the header of the function
definition. Then only the scope operator identifies the fnction as a member of a perticular class. Without
the use of scope operator, the function definition would create a ordinary function, subject to the usual
function rules of access and scope.
The scope operator (::) specifies the class to which the member being declared belongs, granting exactly
the same scope properties as if this function definition was directly included within the class definition.
Scope resolution operator (::) let us access a global variabe even if a local variable uses the same name.
The syntex requires the placement of the double colon, ::, immidiatly in front of the globally referenced
identufier.
We use the scope resolution operator (::) to override a local variable name.
Example :
int x=5;
void main()
int x=10;
cout<<x<<” ”<<::x;
Q8. Give a Comparison between the Class and an Object, with the help of a small
example.
Class is expanded concept of data structure. Class is consist of data member and data function.
Basically , a class is a way to bind data.
But object is an instantiation of a class. In terms of variable, a class would be the type, and an object
would be the variable.
For example: hour, minute , second are the member of class time. If time defined as a class, then the
synrax is Time hour;
Will creat an object hour belonging to class time. The general form of representing a class is
Class class_name
private :
Variable declarations;
Function declarations;
Public:
Variable declarations;
Function declarations;
}object_names;
But object are the basic run time entities in an Object oriented system. They may represent a person, a
place, a bank account or any item that the program has to handle.
#include <iostream.h>
#include <stdio.h>
class employee
{
char name[80]; // private by default
public:
void getname();
};
void employee::putname()
cout<<”Name: “<<name;
void employee::getname()
cout<<”Enter name: “;
gets(name);
void main()
employee ted;
ted.getname();
ted.putname();