Question #274045

Wap to create two Base class String1,String2 and private data members called str1,str2 respectively, And one derived class StringConcat derived from that two base class which concatenate that two base class's data members and display it. You use whatever member function which suit your program


Expert's answer

#include<iostream>
using namespace std;
class  String1{
	private:
	string	str1;
		public:
		void setS1(string d){
			str1 = d;
		}
		
		string getS1(){
			return str1;
		}
	
};


class  String2{
	private:
		string	str2;
	public:
		void setS2(string d){
			str2 = d;
		}
		
		string getS2(){
			return str2;
		}
};


class StringConcat:String1, String2 {
	private:
		
		string s3;
	public:
		
		StringConcat(string s, string a){
			setS1(s);
			setS2(a);
			s3 = getS1() +" "+getS2();
		}
		
		void display(){
			cout<<s3<<endl;
		}
		
}; 


int main(){
	StringConcat s("John", "Paul");
	s.display();
}
LATEST TUTORIALS
APPROVED BY CLIENTS