Site icon T4Tutorials.com

Virtual base class C++ Program to print a string in reverse order

Write a program in C++ to print a string in reverse order by using the virtual base class in Object Oriented Programming.

#include<iostream>
using namespace std;
class A
{
	public:
		string str=" Welcome to T4Tutorials.";
	};
	class B:virtual  public A
	{
		public:
			int i;
	};
	class C: public B
	{
		public:
			int show()
			{
				for( i=str.length()-1;i>=0;i--)
				{
					cout<<str[i];
				}
			}
	};
	int main()
	{
		C obj;
		obj.show();
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	

Output

Welcome to T4Tutorials.

.slairotuT4T ot emoclew

FAQ

how to reverse a string in c++ using strrev by using the virtual base class in OOP.
reverse a string in c++ without using library function by using the virtual base class in OOP.
c++ program to reverse a string using arrayby using the virtual base class in OOP.
reverse words in a string in C++ by using the virtual base class in OOP.
reverse a sentence in C++ by using the virtual base class in OOP.
program to reverse a string in C++ by using the virtual base class in OOP.
C++ program to print alphabets in reverse order by using the virtual base class in OOP.

 

Exit mobile version