Q.
1 can constant object access the none constant member function of
each class?
Const objects can access only const member functions
[Link] is simple association and and composition?
The two interacting objects have no intrinsic relationship with other object is called
simple association.
Q3. Explain the deference between the static variable of a class with none
static variable?
A non static member is tied to an instance of a class although a static member is
tied to the class, and not to a particular instance. A static member is shared by all
instances of a class
[Link] is interface give two real life examples?
Interface is a set of functions of an object that he wants to expose to other objects.
Q5. What is aggregation give example?
contained object is called
aggregation
The relationship between the container and the contained object is called
aggregation.
Q.6 What is an abstract class?
Taking part of the objects and
their functions that is related
to the problem and ignore all
other irrelative
characteristic called
abstraction
Taking part of the objects and their functions that is related to the problem and
ignore all other irrelative characteristic called abstraction
Q6. Friend functions increase „Programming bugs‟. What is your opinion?
Yes friend functions can increase programming bugs some time.
Q7. What are Accessor Functions, Explain with an example?
Accessor functions are used to access private data of the object, we provide
accessor functions to get and set private data members of the class.
Q8. Friend functions minimize "Encapsulation", What is your opinion?
Friend functions minimize encapsulation as we can access private data of any class
using friend functions,
Q9. write code with correct data types?
int age = 25;
float height = 5.9;
char grade = 'A';
bool isPassed = true;
Q10. Tangible object & intangible object?
Tangible objects have physical existence and can be touched or felt, such as books,
chair, or table.
Q11. Constructor declaration one and two parameter?
Class MyClass{
public:
MyClass(); \\Default
MyClass(intx); \\one parameter
MyClass(intx, Inty); \\two parameter
};
Q12. Event, Time and Date three classes?
class Event{
\\code for Event class
};
class Time{
\\code for Time class
};
class Date{
\\code for Date class
};
Q13. write int Rollno setter and getter functions?
class Student{
Private:
intRollno;
public:
void setRollno(int r){
Rollno = r;
}
int getRollno(){
return Rollno;
}
};
Q14. Suppressed form & Normal Form?
Suppressed form refers to form of a function or method where no implementation
details are provided, only the declaration is present.
Q15. Header file write in .cpp?
#include "header_file.h"
Q16. Write a class?
class MyClass{
\\Class members and methods here
};
Q17. What is Base and Derived class?
class Base{
\\Base Class members and methods
};
class Derived : Public Base {
\\Derived Class members and methods
};
Q18. What is Constructor?
class MyClass{
public:
MyClass(){
\\Constructor code
};
Q19. Create array of object having size 2 and initialize array of given
class?
MyClass object[2] = { MyClass(), MyClass() };
Q20. *this pointer?
*this pointer refers to the current object instance wihtin a member function. It is a
pointer that holds the memory address of the current object.
Q21. Define Encapsulation?
Encapsulation referes to the bundling of data methods that operate on the data into
a single unit or. It hides the internal state of the object and only expose the
necessary functionalities to the outside word, thereby providing data security and
preventing unauthorized access.
Q22. Write a code on Operator Overload?
class MyClass{
public:
int operator+(int num){
return num + data;
}
private:
int data;
};
Q23. Write code c++ code void distance?
void distance(int x1, inty1, int x2, int y2){
\\Code to calculate distance between two points
};
Q23. Write code double length and double breadth?
class Rectangle{
public:
double length;
double breadth;
};
Q24. Explain Common attributes and common behavior?
Attributes: pen, pencil, bag
Behavior: play()
Q25. Write a inheritance code?
class Vehicle{
\\Vehicle class definition
};
class Car : Public Vehicle {
\\Car class definition
};
class Bike : Public Vehicle {
\\Bike class definition
};
Q3. Give c++ code to overloaded unary "--" oprators to comples member
class?
class Complex{
...
Complex operator -- (int);
// friend Complex operator --(const
Complex &, int);
}
Complex Complex::operator -- (int)
{
complex t = *this;
real - = 1;
return t;
}
Complex operator -- (const
Complex & h, int){
complex t = h;
[Link] - = 1;
return t;
}
class Complex{
...
Complex operator -- (int);
// friend Complex operator --(const
Complex &, int);
}
Complex Complex::operator -- (int)
{
complex t = *this;
real - = 1;
return t;
}
Complex operator -- (const
Complex & h, int){
complex t = h;
[Link] - = 1;
return t;
}
class Complex{
...
Complex operator -- (int);
// friend Complex operator --(const
Complex &, int);
}
Complex Complex::operator -- (int)
{
complex t = *this;
real - = 1;
return t;
}
Complex operator -- (const
Complex & h, int){
complex t = h;
[Link] - = 1;
return t;
}
class Complex{
Complex operator -- (int);
// friend Complex operator --(const Complex &, int);
}
Complex Complex::operator -- (int){
complex t = *this;
real - = 1;
return t;
}
Complex operator -- (const Complex & h, int)
{
complex t = h;
[Link] - = 1;
return t;
};
Q Write c++ of overloading ^ operator in complex numbers class.
If we have two objects of complex number class as follows,
Complex obj1,obj2;
and we write statement,
Complex obj3 = obj1 ^ obj2;
obj3 real and imaginary parts will be,
[Link] = ([Link]) [Link] and [Link] = ([Link]) [Link]
Hint: You can use c++ built in function power(x,y) that returns the result
of x y.
Class complex
{
Private:
Double val;
Complex operator ^(complex c1)
{
Return Power(val,[Link]);
}
};