Answer to Question #274045 in C++ for Amit

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


1
Expert's answer
2021-12-08T08:31:54-0500
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment