Friday, 21 July 2017

PRACTICE EXERCISES

PRACTICE PAPER

1)a) Write and 2 characteristics of a constructor and a destructor.
b)     Are the default constructor and constructor with default parameter same?Give reason.
c)      Give any 2 differences between a constructor and a normal function.
d)     Given the following :

class Distance 
{
private:
int feet;
float inches;
public:
--------------
--------------
};
void main()
{
Distance dist1, dist3; //define two lengths
Distance dist2(11, 6.25); //define, initialize dist2
dist1.getdist(); //get dist1 from user
dist3 = dist1.add_dist(dist2); //dist3 = dist1 + dist2
cout << “\ndist1 = “; dist1.showdist(); // print dist1
cout << “\ndist2 = “; dist2.showdist(); // print dist2
}
Complete the above class description with necessary constructors and member function definitions.



e)                     Answer the questions (a) and (b) after going through the class definition:
class Force
{
int power;
public:
Force()  // constructor 1
{power=0;}
Force(int z) // constructor 2
{
power=Z;
}
Force(Force &F) // constructor 3
{power=F.power;}};

a) What type of constructor is constructor 3? Explain.
b) Write statement to declare object for 'Force' so that it invokes constructor 2.

f)                      Answer the questions (a) and (b) after going through the following class:
class cars
{
int noofwheels,capacity;
float mileage;       
cars();              // function 1
cars(int x, int y, float z); // function 2
cars(cars &c); // function 3
};
a) Write the definition of function 1, function 2 and function 3.
b) Create object to invoke function 1, function 2, function 3.

2) a) Define the following terms:
i) Abstract class
ii) Containership
b) Assume there is a class pony derived from base class horse. Both classes contain a member function jump() that takes no arguments. Write a statement that calls the member function jump() of class horse from the object of class pony.
c) Consider the following declarations and answer the questions (i to ii) that follow:
class CUSTOMER
{
int Cust_no;
char Cust_Name[20];
protected: 
void Register();
public:
CUSTOMER();
void Status();};
class SALESMAN
{
int Salesman_no;
char Salesman_Name[20];
protected:
float Salary;
public:
SALESMAN();
void Enter();
void Show();
};
class SHOP:private CUSTOMER, public SALESMAN
{
char Voucher_No[10],Sales_Date[8];
public:
SHOP();
void Sales_Entry();
void Sales_Detail();};

i) Write the names of data members which are accessible from objects belonging to class CUSTOMER.
ii) Write the names of all the member functions which are accessible from objects belonging to class SALESMAN.
iii) Write the names of all the members which are accessible from member functions of class SHOP.
iv) How many bytes will be required by an object belonging to class SHOP?

d) Answer the question (i) to (iv) based on the following:  

class Organization
{
char Address[20];
double Budget, Income;
protected:
void Compute( );
public:
Organization( );
void Get( );
void Show( );
};

class WorkArea : public Organization
{
char Address[20];
int Staff;
protected:
double Pay;
void Calculate( );
public:
WorkArea( );
void Enter( );
void Display( );
};
class ShowRoom : private Organization
{
char Address[20];
float Area;
double Sale;
public:
ShowRoom( );
void Input( );
void Show( );
};
(i) Name the type of inheritance illustrated in the above C++ code.
(ii) Write the name of members, which are accessible from member function Input() of class ShowRoom.
(iii) Write the name of all the member functions, which are accessible from objects belonging to class WorkArea.
(iv) How many bytes will be required by an object of class ShowRoom?

3 a) Write a function AECount() in C++, which should read each character of a text file NOTES.TXT, should count and display the occurrence of alphabets A and E (including small cases a and e too).  
Example :
If the file content is as follows :
CBSE enhanced its CCE guidelines further.
The AECount() function should display the output as
A:1
E:7

b) Write a function in C++ to read the content of a text file “Place.TXT” and display all those lines on screen which are either starting with “P” or starting with “S”.

c) Write the command to place the file pointer at the 10th and 4th record starting position using seekp() or seekg() command. File object is ‘file’ and record name is ‘STUDENT’.

c)Write a function LtoD() that that would display the corrected version of entire content of the file LINE.TXT with all alphabets  ‘D’ to be replaced as ‘L’, ‘d’ with ‘l’.
If the file contained the following text:
Dearn to dive and dive to dearn

Then it should display the following
Learn to live and live to learn

1) d)
class Distance 
{
private:
int feet;
float inches;
public:
Distance()
{
feet=12;inches=5.5;}
Distance(int x, float y)
{
feet=x;
inches=y;
}
void getdist()
{
cin>>feet>>inches;
}
Distance add_dist(Distance d2)
{Distance d3;
d3.feet=feet+d2.feet;
d3.inches=inches+d3.inches;
return d3;
}
void showdist()
{
cout<<feet<<" "<<inches;
}
};
void main()
{
Distance dist1, dist3; //define two objects
Distance dist2(11, 6.25); //define, initialize dist2
dist1.getdist(); //get dist1 from user
dist3 = dist1.add_dist(dist2); //dist3 = dist1 + dist2
cout << “\ndist1 = “; dist1.showdist(); // print dist1
cout << “\ndist2 = “; dist2.showdist(); // print dist2
}

e)
a) Copy constructor because the object is passed by reference that is used to initialize another object with its values.
b) Force f(5) ;

f) a)cars::cars() // function 1
{
noofwheels=4;
capacity = 1500;
mileage = 5000;}
cars::cars(int x, int y, float z) // function 2
{
noofwheels=x;
capacity=y;
mileage=z;
}
cars::cars(cars &c) // function 3
{
noofwheels=c.noofwheels;
capacity=c.capacity;
mileage=c.mileage
}
void main()
{
cars c1, c2(5,1000,10000);  // object declaration
cars c3=c1;
}

2) c)
i) None
ii)Enter(), Show()
iii) Data Members: Voucher_No[10],Sales_Date[8],Salary
     Member functions : Register(), Enter(), Show(), Sales_Entry(),Sales_Detail()
iv) 66 bytes

d)
i) Hierarchical
ii) Data members -
    Address[20],Area,Sale
    Member functions - Compute(), Get(), Organization::Show(), Show()
iii)Enter(), Display()
iv)68 bytes


2. (a) Differentiate between protected and private members of a class in context of Object Oriented Programming. Also give a suitable example illustrating accessibility/non-accessibility of each using a class and an object in C++.
(b) Observe the following C++ code and answer the questions (i) and (ii).
Note : Assume all necessary files are included.

class TEST
{
long TCode;
char TTitle[20];
float Score;
public:
TEST() //Member Function 1
{
TCode=100;strcpy(TTitle,"FIRST Test");Score=0;
}
TEST(TEST &T) //Member Function 2
{
TCode=E.TCode+1;
strcpy(TTitle,T.TTitle);
Score=T.Score;
}
};
void main()
{
_______________ //Statement 1
_______________ //Statement 2
}
(i) Which Object Oriented Programming feature is illustrated by the Member Function 1 and the Member Function 2 together in the class TEST ?  
(ii) Write Statement 1 and Statement 2 to execute Member Function 1 and Member Function 2 respectively.




Answer the questions (i) to (iv) based on the following :  
class First
{
int X1;
protected:
float X2;
public:
First();
void Enter1(); void Display1();
};
class Second : private First
{
int Y1;
protected:
float Y2;
public:
Second();
void Enter2();
void Display();
};

class Third : public Second
{
int Z1;
public:
Third();
void Enter3();
void Display();
};
void main()
{
Third T; //Statement 1
___________________; //Statement 2
}



  

i)Which type of Inheritance out of the following is illustrated in the above example ?
Single Level Inheritance, Multilevel Inheritance, Multiple Inheritance
(ii) Write the names of all the member functions, which are directly accessible by the object T of class Third as declared in main() function.
(iii) Write Statement 2 to call function Display() of class Second from the object T of class Third.
(iv) What will be the order of execution of the constructors, when the object T of class Third is declared inside main() ?








Wednesday, 12 July 2017

Text File Handling

A file is a bunch of bytes stored on some storage device like disk.

Need: To store data permanently and in large quantities.

Types of data files:

Text file and binary file.

A text file is also called as an ascii file. Character conversions take place in the text file and it includes EOL end of line marker at the end of every line.

No such conversions take place in binary file. It saves data in binary form .A binary file is a file stored in binary format. A binary file is computer-readable but not human-readable. All executable programs are stored in binary files, as are most numeric data files. In contrast, text files are stored in a form (usually ASCII) that is human-readable.


Stream - sequence of bytes - acts as an interface between program and I/O devices.

Stream that reads data from the file - Input stream

Stream that writes data on to the file - output stream.

Classes for file stream operations

I/O system of C++ contain as set of classes that defines file handling methods. This includes fstream, ifstream, ofstream.

iostream.h -> related to console I/O
fstream.h-> related to file I/O

Declaring a file stream
File Stream is a data type which is used to declare an object of stream. It may be input file stream or output file stream.

Syntax
file_stream_class  stream_object;

eg:ifstream fin;// for input operation
     ofstream fout;// for outupt operation

Opening a file

Before a file is used, it should be opened. There are 2 methods to open a file.

i) By using constructor function of the class
       ifstream f1("story.txt");
ii) By using open method.

    ifstream f1;
    f1.open("story.txt");

Steps to read a text file and process it

i) Declare the stream(ifstream or fstream)
ii) Determine the buffer size
iii) Declare and initialize variables if any
iv) check if file exists, otherwise display error message
v) use while loop(to check end of file condition)
vi) determine the input method(to get the content into the buffer)
     for eg if f1 is the object
     f1.get(ch);// will get a single character from the file
     f1.get(ch,50);// will get ch as a string from the file
     f1>>ch;// will get ch as a string thereby ignoring space and other whiteline characters
     f1.getline(ch,50);// will get one line of content at a time in the buffer
v) check for condition if any and process(using ctr)
vi) end the loop
vii) Print the required output

Steps to write data on to text file  

i) Declare the stream(ofstream or fstream)
ii) Determine the buffer size
iii) Declare and initialize variables if any
iv) use do while loop
v) Input values from user within the body
vi) use one of the following to write the values into the file
    if f1 is the object
      f1<<str;// will write str as string into f1
      f1.put(str);// will write str as a single character into the file.
vii) input continue variable
viii) end the while loop


Different file modes

ios::in - to read the file
ios::out - to write the file
ios::app - to add data at the end of the file
ios::ate- to write data anywhere in the file
ios::nocreate - open fails if file does not exist
ios::noreplace - open fails if file already exists
ios::trunc - deletes contents of file if exists
ios::binary - opens file in binary mode

random reading of files

f1.seekg(5,ios::beg);// moves file pointer 5 bytes forward starting from the beginning of the file.
f1.seekg(-5,ios::cur); // moves file pointer backwards from the current position.
f1.seekg(0,ios::end); moves the file pointer to end of file position.
f1.tellg();// tells the location of the pointer in the file
f1.seekp();// places the file pointer before writing
f1.tellp();// tells the location of the pointer while writing (if the object is opened in the output mode)

Exercises:

1)       Write a program that accepts a file name as a variable and displays the size of a file in bytes.    
2)       Write a function COUNT() to count the presence of a word “to” as independent word in a text file “NOTES.TXT”.                                                       
For eg: if the content of the file contains
It is very important to know that
Smoking is an injurious tool to health
Let us take initiative to stop it.

The output should be:
Count of “to”: 3    

3)       Write a program using a  function to count the number of alphanumeric words present in a text file:             
For eg, if the file contains
Attention 12C students, the vehicle no TN9022 is parked wrongly at B3.
The output should be :3

4)       Write programs(using functions) to
a)       Read a text file story.txt and count no of alphabets, digits and special characters in that file and display the same.
b)       Read a text file lines.txt and prints count of lines that has the word “you” in a line.
For eg:
If the file has
Take risks in life.
If you win, you can lead!
If you lose, you can guide!

Output: 2

#include <fstream.h>
#include <string.h>
#include <conio.h>
void main()
{
ifstream f1("dream.txt");
char str[25];
int ctr=0;
while(!f1.eof())
{f1>>str;
 if(strcmpi(str,"you")==0)
 {
 ctr++;
 f1.getline(str,25);
 }
}
cout<<ctr;

}

c)       Read a text file case.txt and convert all the text to upper case and write it in another file uppercase.txt
For eg if the file contains following text:
Dream, dream, dream
Dreams transform into thoughts and thoughts result in action.

The output file should contain
FOR EG IF THE FILE CONTAINS FOLLOWING TEXT:
DREAM, DREAM, DREAM DREAMS TRANSFORM INTO THOUGHTS AND THOUGHTS RESULT IN ACTION.  

Solution:
#include <fstream.h>
#include <string.h>
#include <conio.h>
void main()
{
ifstream f1("dream.txt");
ofstream f2("out.txt");
char str[25];
while(!f1.eof())
{f1>>str;
 f2<<strupr(str)<<" ";
}}


d)       Read the text file WORDS.TXT and print those words that does not end with a vowel.
Eg: If the file contains

If you want to shine like a sun, first burn like a sun.

Output:
If want sun first burn sun

e)       Read a text file story.txt and print all three letter words starting with a capital letter.
f)        Read  a text file called lines.txt and print all the strings that are palindromes.
        (Hint: Use strrev() function)

Note: A palindrome is a string that is same as its reverse. Eg: madam


Predict the output problem given the following code assuming the text file contains the following content:

she sells sea shells in the sea shore.

The code:

#include <fstream.h>
#include <string.h>
#include <conio.h>
void main()
{
clrscr();
ifstream f1("dream.txt");
char s[20],ch;
f1.seekg(1);
f1>>ch;
cout<<ch<<endl;
f1.seekg(4);
f1.seekg(10);
f1.get(s,10);
cout<<s<<endl;
f1.seekg(-15,ios::end);
f1.getline(s,20);
cout<<s<<endl;

}

Output:


h

sea shell

 the sea shore.

Identify the errors in the following code and rewrite the corrected code and underline it.
(Assume necessary header files are included).

void main()
{
clrscr();
ifstream f1("dream.txt",ios::in);
char s[30]="Honesty is the best policy";
f1<<s;
f1.seekg(0);
f1.gets(s);
while(f1)
{
f1.get(s);
if(strcmp(s,"to")==0) ctr++;
}

}

Solution


void main()
{
clrscr();
fstream f1("dream.txt",ios::in|ios::out);
char s[30]="Honesty is the best policy";
int ctr=0;
f1<<s;
f1.seekg(0);
f1.get(s,20);
while(f1)
{
f1.get(s,20);
if(strcmp(s,"to")==0) ctr++;
}
}

BOARD PAPER - 2017

Write function definition for SUCCESS( ) in C++ to read the content of a text file
STORY.TXT, count the presence of word SUCCESS and display the number of
occurrence of this word. 2
Note :
– The word SUCCESS should be an independent word
– Ignore type cases (i.e. lower/upper case)
Example :
If the content of the file STORY.TXT is as follows :
Success shows others that we can do it. It is possible to achieve success with hard work. Lot of money does not mean SUCCESS.
The function SUCCESS( ) should display the following :

3

Ans:

void SUCCESS()
{
int count=0;
ifstream f("STORY.TXT");
char s[20];
while (!f.eof())
{

f>>s;
count++;
}
cout<<count;
f.close();

}


Inheritance

Inheritance 

Inheritance is the capability of one class to acquire properties and characteristics from another class.
The class whose properties are inherited by other class is called the Parent or Base or Super class.
And, the class which inherits properties of other class is called Child or Derived or Sub class.

Inheritance makes the code reusable.
When we inherit an existing class, all its methods and fields become available in the new class, hence code is reused.

Types of inheritance

Single Inheritance




















class animal
{
char type[20];// mammal or reptile
public:
...
};
class dog : public animal
{
char breed[25]; // Pug or Golden retriever
public:
...
};

Multiple Inheritance













class mammal
{
char type[20],respiration[20];
char gender;
int no_of_vertebrates;
public:
....
};
class WingedAnimal
{
char feather_color[25],beak_color[20];
public:
...
};
class bat:public mammal, public WingedAnimal
{

float wingspan;
char location[25];
public:
...
};

Multilevel Inheritance

























class A
{int x;
public:
void read();
void print();
};
class B: public A
{
int y;
public:
void Bread();
void Bprint();
};
class C: public B
{
int z;
public:
void Cread();
void Cprint();
};

Hierarchical Inheritance























class A
{int x;
public:
void read();
void print();
};
class B:  public A
{
int y;
public:
void Bread();
void Bprint();
};
class C: public A
{
int z;
public:
void Cread();
void Cprint();
};

Access specifiers with a class - private, public, protected

Private members of a class cannot be accessed by any other derived class or the object of the class.
Protected members of a class can be accessed only by the derived class and not the object of the class.
Public members of a class can be accessed both by the derived classes and the object of the class.

Visibility Modes

If the visibility mode is public, public members of the base class become public members of the derived class and protected members become protected members of the derived class.

eg
class B: public A
{ };

If the visibility mode is protected, public and protected members of the base class become protected members of the derived class.

eg
class B:protected A
{ };

If the visibility mode is private, public and protected members of the base class become private members of the derived class.

eg
class B:private A
{ };

Function Overriding/Shadowing

When a derived class function has the same name as that of its base class's member function , the derived class's member function hides/shadows the base class's inherited function. This situation is known as function overriding or shadowing.

Eg
class A
{
int x;
public:
void read();
void display();
};
class B:public A
{
int y;
public:
void read();
void display();
};

Whenever object of B is declared in main, the member functions that can be accessed by the object will be as follows:
read(), display() functions of class B
A::read(), A::display() functions of class A

Here the derived class B overrides the member functions of class A as there is same name for both the member functions.


Containership or Aggregration

When a class contains objects of other class types as its member, it is referred to as Containersip or Aggregation.

class A
{
int x;
public:
A();
void read();
void disp();
};
class B
{
int y;
A a1;// object of class A
public:
void check();
};

Parameterized Constructors used in Inheritance 

#include <iostream.h>
#include <conio.h>
class A
{
int x,y;
public:
A(int a, int b)
{
x=a;
y=b;
}
};
class B
{
int z;
A a1;
public:
B(int c,int a,int b):A(a,b)
{
z=c;
}
};
void main()
{
B b1;
}

Virtual Base Class

In a hierarchical inheritance, more than 1 derived class inherit from a single base class. In this situation a copy of base class will be maintained in each of the derived class. When one more derived class derives from these two classes, there will be ambiguity as to which copy of base class will be used. In order to overcome this ambiguity, virtual keyword is prefixed to visibility mode for each of the derived class, so that one copy of base will be present when the object of the final derived class is created.

class A
{
public:
int a;
...};
class B: virtual public A
{
public:
int b;
........
};
class C: virtual public A
{
public:
int c;
.........
};
class D:public B, public C
{
public:
int total;
....
};

Size of the object will be total number of size of data types of all base classes and its own class (in bytes).
char - 1, int - 2, float - 4, long- 4, double - 8

Text book Unsolved problems - P 291

1) a)MNC
    b)129 bytes
    c)Enter(), Output(), Association(), Add(), Show(), EnterDate(), DisplayData()
    d) Country[25]

2) a) CEO
    b) 20 bytes
    c) display(),INDATA(), OUTDATE(), input(), output()
    d) yes

2017 - Board - QP
Answer the questions (i) to (iv) based on the following :
class First
{
int X1;
protected:
float X2;
public:
First();
void Enter1(); void Display1();
};
class Second : private First
{
int Y1;
protected:
float Y2;
public:
Second();
void Enter2();
void Display();
};
class Third : public Second
{
int Z1;
public:
Third();
void Enter3();
void Display();
};
void main()
{
Third T; //Statement 1
___________________; //Statement 2
}
(i) Which type of Inheritance out of the following is illustrated in the above example ?
Single Level Inheritance, Multilevel Inheritance, Multiple Inheritance

Multilevel

(ii) Write the names of all the member functions, which are directly accessible by the object T of class Third as declared in main() function.

Member functions : Enter2(), Second::Display(), Enter3(), Third::Display()

(iii) Write Statement 2 to call function Display() of class Second from the object T of class Third.

T.Second::Display();

(iv) What will be the order of execution of the constructors, when the object T of class Third is declared inside main() ?

First()-> Second()->Third()


Tuesday, 11 July 2017

Constructors and Destructors

Constructors and Destructors

·         A constructor is a member function of a class whose function name is same as the name of the class.
·         It is used to initialize the values of data members.
·         It does not return a value nor is it void.
·         It may contain parameters.
·         It will be invoked whenever the object of the class is created.
·         The memory for the class will be allocated only when the object is created.
·         When no constructors are used explicitly by the programmer, the contructor constructs garbage value into its data members.

Eg of defining a constructor:
class sample
{
int x;
public:
sample()
{
cout<<"constructing..";
x=5;
}
...
};
void main()
{

y=s.y;
}
};
void main()
{
sample obj1,obj2(150,100); // statement to invoke the default and parameterized constructors
sample obj3=obj2; // statement to invoke the copy constructor
}
Function 1,2 and 3 together are constitute constructor overloading.

In Object oriented Programming structure, this concept is called as polymorphism.

Calls to the constructor may be implicit or explicit.

Implicit - sample s(13,14);
Explicit - sample s=sample(13,14);
The explicit call to a constructor allows you to create a temporary instance
Temporary instance - A temporary instance is an instance that is instantiated by a class to invoke a member function or functions and is immediately discarded.


eg:
class sample
{int i,j;
public:
sample(int a, int b)
{
i=a;j=b;}
void print()
{cout<<i<<" "<<j;}
};
void test()
{
sample s1(2,5);
s1.print();
sample(100,200).print();
}

In order to use temporary instance, a parameterized constructor should have been present.



What is destructor?
Destructor is a member function which destructs or deletes an object.

When is destructor called?
A destructor function is called automatically when the object goes out of scope:
(1) the function ends
(2) the program ends
(3) a block containing local variables ends
(4) a delete operator is called 

How destructors are different from a normal member function?
Destructors have same name as the class preceded by a tilde (~)
Destructors don’t take any argument and don’t return anything.

Exercises

Answer the questions(i) and (ii) after going through the following
class:
class planet
{
 char name[20];char distance[20];
public:
 planet() //Function 1
 {
 strcpy(name, "Venus");
 strcpy(distance,"38 million km");
 }
 void display(char na[],char d[]) //Function 2
 {
 cout<<na<<"has "<<d<<" distance from Earth"<<endl;
 }
 planet(char na[], char d[]) //Function 3
 {
 strcpy(name,na);
 strcpy(distance,d);
 }
 ~planet() //Function 4
 {
 cout<<"Planetarium time over!!!"<<endl;
 }
};
I. What is Function 1 referred as? When will it be executed?
Default constructor. It will be executed when the object is created.

II. Write suitable C++ statement to invoke Function 2. 

planet p;
p.display("Mars","20 million km");Observe the following C++ code and answer the questions (i) and (ii).
Note : Assume all necessary files are included.
class TEST
{
long TCode;
char TTitle[20];
float Score;
public:
TEST() //Member Function 1
{
TCode=100;strcpy(TTitle,"FIRST Test");Score=0;
}
TEST(TEST &T) //Member Function 2
{
TCode=E.TCode+1;
strcpy(TTitle,T.TTitle);
Score=T.Score;
}
};

void main()
{
_______________ //Statement 1
_______________ //Statement 2
}
(i) Which Object Oriented Programming feature is illustrated by
the Member Function 1 and the Member Function 2 together
in the class TEST ?  
(ii) Write Statement 1 and Statement 2 to execute Member
Function 1 and Member Function 2 respectively.

Observe the following C++ code and answer the questions (i) and (ii).
 Note : Assume all necessary files are included.
 class EXAM
 {
 long Code;
 char EName[20];
 float Marks;
 public:
 EXAM() //Member Function 1
 {
 Code=100;strcpy(EName,"Noname");Marks=0;
 }
 EXAM(EXAM &E) //Member Function 2
 {
 Code=E.Code+1;
 strcpy(EName,E.EName);
 Marks=E.Marks;
 }
 };
 void main()
 {
 _____________ //Statement 1
 _____________ //Statement 2
 }
 (i) Which Object Oriented Programming feature is illustrated by the Member
Function 1 and Member Function 2 together in the class EXAM ? 1
 (ii) Write Statement 1 and Statement 2 to execute Member Function 1 and
Member Function 2 respectively. 

Observe the following C++ code and answer the questions (i) and (ii). Assume all
necessary files are included :
 class FICTION
 {
 long FCode;
 char FTitle[20];
 float FPrice;
 Public: 
FICTION() //Member Function 1
 {
 cout<<”Bought”<<endl;
 FCode=100;strcpy(FTitle,”Noname”);FPrice=50;
 }
 FICTION(int C,char T[],float P) // Member Function 2
 {
 FCode=C;
 strcpy(FTitle,T);
 FPrice=P;
 }
 void Increase(float P) // Member Function 3
 {
 FPrice+=P;
 }
 void Show() // Member Function 4
 {
 cout<<FCode<<”:”<<FTitle<<”:”<<FPrice<<endl;
 }
 ~FICTION() // Member Function 5
 {
 cout<<”Fiction removed!” <<endl;
 }
 };
 void main() //Line 1
 { //Line 2
 FICTION F1,F2(101,”Dare”,75); //Line 3
 for (int I=0;I<4;I++) //Line 4
 { //Line 5
 F1.Increase(20);F2.Increase(15); //Line 6
 F1.Show();F2.Show(); //Line 7
 } //Line 8
 } //Line 9
 (i) Which specific concept of object oriented programming out of the following
is illustrated by Member Function 1 and Member Function 2 combined
together ? 1
 • Data Encapsulation
 • Data Hiding
 • Polymorphism
 • Inheritance
 (ii) How many times the message “Fiction removed!” will be displayed
after executing the above C++ code ? Out of Line 1 to Line 9, which line is

responsible to display the message “Fiction removed!” ?