Answer to Question #273872 in C++ for SUNIL

Question #273872

Write a program to declare three classes a1, a2, a3. The classes have private data member variable of string type. Assign the first name and surname of a student to member variable of class a1 and a2 respectively. Perform concatenation of two strings and store it to data member variable of class a3. Print the full name to the output screen using member function. 


1
Expert's answer
2021-12-05T13:07:56-0500
#include<iostream>
using namespace std;
class a1{
	private:
		string first_name;
	public:
		void setFirst(string first){
			first_name = first;
		}
		
		string getFirst(){
			return first_name;
		}
};


class a2{
	private:
		string surname;
	public:
		void setSurname(string first){
			surname = first;
		}
		
		string getSurname(){
			return surname;
		}
};


class a3{
	private:
		a1 first;
		a2 second;
	public:
		void setFull(string a, string b){
			first.setFirst(a);
			second.setSurname(b);
			
		}
		
		string getFull(){
			return first.getFirst() +" "+second.getSurname();
		}
	
};


int main(){
	a3 third;
	third.setFull("John", "Terry");
	cout<<third.getFull()<<endl;
}

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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS