You are on page 1of 3

ANSWER 2

Multiple inheritance occurs when a class inherits from more than one
base class. So the class can inherit features from multiple base classes
using multiple inheritance. This is an important feature of object oriented
programming languages such as C++.
A diagram that demonstrates multiple inheritance is given below −

A program to implement multiple inheritance in C++ is given as follows −


Example

class B {
public:
int b = 10;
B() {
cout << "Constructor for class B" << endl;
}
class C: public A, public B {
public:
int c = 20;
C() {
cout << "Constructor for class C" << endl;
cout<<"Class C inherits from class A and class
B" << endl;
}
};
int main() {
C obj;
cout<<"a = "<< obj.a <<endl;
cout<<"b = "<< obj.b <<endl;
cout<<"c = "<< obj.c <<endl;
return 0;

}
Output
The output of the above program is given as follows −
Constructor for class A
Constructor for class B
Constructor for class C
Class C inherits from class A and class B
a = 5
b = 10
c = 20

ANSWER 3

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
int main(){
fstream file;
string input;
istringstream iss;
int thisCount = 0, theseCount = 0;
file.open("ARTICLE.TXT", ios::in);
if(file) while(getline(file, input)){
iss = istringstream(input);
while(iss>>input){
if(input[input.length() - 1] < 65) input
= input.substr(0, input.length() - 1); //remove !, .,
?
if(input == "this" || input == "This")
thisCount++;
else if(input == "these" || input ==
"These") theseCount++;
}
}
else{
cout<<"Error opening file!";
return -1;
}
file.close();
cout<<"Number of ""this"": "<<thisCount<<endl;
cout<<"Number of ""these"": "<<theseCount<<endl;
return 0;
}

You might also like