b) Declare an integer data for taking value of radius of that circle and take that input through get input() function
c) Find out the area of circle using another member function
Answer
[2016]
a) Write a program in C++ that accepts two number as input and find the sum using class and object
Answer:
b) What is Polymorphism? Explain with example
Answer:
polymorphism is an important concept of object-oriented programming.it means having many forms. Inheritance lets us inherit attributes and methods from another class. Polymorphism uses those methods to perform different tasks. This allows us to perform a single action in different ways.
Example:
[2017]
a) Write a program in C++ to check an integer whether it is odd or even using class and object?
Answer:
b) What do you mean by Data Member? Give example?
Data Members are variable which are declared in any class by using any fundamental data types
(like int, char, float etc) or derived data type (like class, structure, pointer etc.).
There are two types of data member
1) Private 2) Public
Example:
OR
a) Give the difference between public and private member of the class in C++
Answer:
Public
Private
1. All the class members and functions are available to everyone.
1.The class members can be accessed only by the functions inside the class.
2. The public member can be accessed from anywhere in the program using the dot operator(.)with the object of that class.
2.the member functions or the friend functions are allowed to access the private data members of a class
Example: class Subtraction { public: int a,b; int calculate(){ return (a-b); } }; int main(){ Substraction obj; // accessing public data member outside class obj.a=20; obj.b=10; cout<<"Substraction is: " << obj.calculate(); return 0; }
Example: class Subtraction { private: int a,b; private: void calculate(int x,int y){ a=x; b=x; int result=a-b; cout<<"Substraction is="<<result; } }; int main(){ Substration obj; obj.calculate(20,10); return 0; }
b) Describe the characteristic of destructor in C++
Answer:
The destructor has the same name as that of the class prefixed by the tilde character ‘~’.
The destructor cannot have parameters.
It has no return type
there can be only one destructor in a class
The destructor is executed automatically when the control reaches the end of the class scope to destroy the object
c) What do you mean by "get from" Operator in C++? Give example?
Ans: Extraction Operator (>>) sometimes known as "get from" operator which is usually used for input data from the user.
[2018]
a) Write a program in C++ using class and object to check an integer whether is a prime number or not.
Answer:
b) What is the member function? Give example?
A member function of a class is a function that has its definition or its prototype within or outside the class. member function knows as a method also.
There are two way to define a function
1) inside the class-defined directly
2) outside of the class- using scope resolution operator(::) along with class name
Example:
OR
a) Write a program in C++ to find out the factorial of a given integer (N!= 1x2x3x........N)
Answer:
b) How a member function can be declared outside of the class? Give example?
Anwser:
A member function can be declared outside of the class using the scope resolution operator (::) along with the class name.
Example:
[2019]
a) Write a program in C++ using class and object to find out the sum 1 to N where N is an integer given as input.
Answer:
b)Write a function of setw and endl manipulator.
Answer:
endl
This manipulator has the same functionality as ‘\n’(newline character). But this also flushes the output stream.
setw()
This manipulator declare in imanip.h . it changes the width of the output field. When used in an expression out << setw(n)output field.
Example:
OR
a) Write a program in C++ to print the reverse of given number.
Answer:
b) what do you mean by reference variable? Give example?
Answer:
When a variable is declared as a reference, it becomes an alternative name for an existing variable. A variable can be declared as a reference by putting '&' in the declaration.