Section 1: A2 A)
Section 1: A2 A)
Section 1: A2 A)
A)
A friend function of a class is defined outside that class' scope but it has
the right to access all private and protected members of the class. Even
though the prototypes for friend functions appear in the class
definition, friends are not member functions. A friend can be a function,
function template, or member function, or a class or class template, in
which case the entire class and all of its members are friends. To declare
a function as a friend of a class, precede the function prototype in the
class definition with keyword friend
Must have access to source code for the class to make a function
into friend.
Conceptually messy
B)
Constructors
#include<iostream>
class Cube {
public:
int side;
side=10;
side=x;
side=c.side;
};
int main()
return 0;
output is 10,15,15
section1 :A5
A)
1) Single Inheritance
In this type of inheritance one derived class inherits from only one base
class. It is the most simplest form of Inheritance.
2) Multiple Inheritance
In this type of inheritance a single derived class may inherit from two or
more than two base classes.
3) Hierarchical Inheritance
Multilevel Inheritance
In this type of inheritance the derived class inherits from a class, which
in turn inherits from some other class. The Super class for one, is sub
class for the other.
B)
Example
Class A
{
int a;
public:
A()
{
a = 1;
}
virtual void show()
{
cout <<a;
}
};
Class B: public A
{
int b;
public:
B()
{
b = 2;
}
virtual void show()
{
cout <<b;
}
};
int main()
{
A *pA;
B oB;
pA = &oB;
pAshow();
return 0;
}
Section 1:A7
#include <iostream>
#include <string>
struct Books {
char *title;
char *author;
char *subject;
int book_id;
};
int main( ) {
Book1.book_id = 6495407;
return 0;
Section 2: B1
#include<iostream>
int main( )
char str[80];
cin.getline(str,80);
words++;
}
cout << "The number of words = " << words+1 << endl;
return 0;
section2:B2
#include <iostream>
class Shape {
public:
Shape(int a,int b) {
};
protected:
int width;
int height;
public:
height=a;
width=b;
int getArea() {
};
int main(void) {
return 0;