Computer Science, asked by nitish171999, 4 months ago

Q3. Write a program which has a class called String, appropriate member functions to get input
into an array of strings and arrange them according to reverse lexicographical order. [5]
Sample Input:
def, abc, ghi
Sample Output:
ghi, def, abc​

Answers

Answered by sauravhathi
1

Answer:

#include <iostream>

using namespace std;

class String{

   public:

   int a(int i, string str[]){

       cout << "Enter 3 words: " << endl;

   for(i = 0; i < 3; ++i)

   {

       cin>>str[i];

   }

   }

};

int main()

{

   String s;

   string str[3], temp;

   int i;

   s.a(i,str);

   for(i = 0; i < 2; ++i)

      for( int j = i+1; j < 3; ++j)

      {

         if(str[i] > str[j])

         {

           temp = str[i];

           str[i] = str[j];

           str[j] = temp;

         }

   }

   cout << "lexicographical order: " << endl;

   for(i = 0; i < 3; ++i)

   {

      cout << str[i] << endl;

   }

   return 0;

}

Input:

Enter 3 words:

def

abc

ghi

Output:

lexicographical order:

abc

def

ghi

Similar questions