C++ Programming Blog

 
 
 

Image

 # include <iostream.h>
 # include <fstream.h>
 # include <string.h>
 # include <stdlib.h>
 # include <conio.h>

 int main( )
    {
       clrscr( );

       fstream File(\"CP-05.txt\",ios::in|ios::nocreate);

       if(!File)
      {
         cout<<\"\\n Unable to open the input file.\"<<endl;
         cout<<\"\\n Press any key to exit.\";

         getch( );
         exit(EXIT_FAILURE);
      }

       char Number_of_strings[85]={NULL};
       char Strings[50][50]={NULL};
       char Temp[50]={NULL};

       int number_of_strings=0;

       File.getline(Number_of_strings,80);

       number_of_strings=atoi(Number_of_strings);

       int i=0;
       int j=0;

       for(i=0;i<number_of_strings;i++)
      File.getline(Strings[i],26);

       for(i=0;i<(number_of_strings-1);i++)
      {
         for(j=0;j<(number_of_strings-1);j++)
        {
           if(strcmpi(Strings[j],Strings[j+1])>0)
              {
             strset(Temp,NULL);
             strcpy(Temp,Strings[j]);
             strset(Strings[j],NULL);
             strcpy(Strings[j],Strings[j+1]);
             strset(Strings[j+1],NULL);
             strcpy(Strings[j+1],Temp);
              }
        }
      }

       cout<<\" *****  Ascending Order  *****\"<<endl;

       for(i=0;i<number_of_strings;i++)
      cout<<Strings[i]<<endl;

       for(i=0;i<(number_of_strings-1);i++)
      {
         for(j=0;j<(number_of_strings-1);j++)
        {
           if(strcmpi(Strings[j],Strings[j+1])<0)
              {
             strset(Temp,NULL);
             strcpy(Temp,Strings[j]);
             strset(Strings[j],NULL);
             strcpy(Strings[j],Strings[j+1]);
             strset(Strings[j+1],NULL);
             strcpy(Strings[j+1],Temp);
              }
        }
      }

       cout<<endl<<\" *****  Descending Order  *****\"<<endl;

       for(i=0;i<number_of_strings;i++)
      cout<<Strings[i]<<endl;

       getch( );
       return 0;
    }

    Related Post:
  1. Program that reads marks obtained by a student in a test of 100 marks and computes his grade

  2. Program that reads an expression consisting of two non-negative integer and an operator. Determine if either integer or the result of the expres......

  3. Program to illustrate the implementation of Scaling Transformation along a Fixed Point

  4. Program to draw a line using Bresenhams Line Algorithm (BLA) for lines with slopes positive and greater than 1

  5. Program to illustrate the use of call-by-refrence method using pointers

  6. Program to fill different types of geometric shapes using Boundary Fill Algorithm

  7. Program to illustrate the binary operator(-) overloading without creating an object of that class

  8. Program for electricity board charges calculation

  9. program to create a doubly link list

  10. Program to illustrate the implementation of Reflection Transformation about the line y=x and y=-x

  11. Program to read a Non-Linear equation in one variable, then evaluate it using Newton-Raphson Method and display its kD accurate root

  12. Program to illustrate the implementation of Reflection Transformation about x-axix, y-axis and w.r.t origin

  13. Shortest Path using kruskal algorithm

  14. Program to create heap

  15. Program of LL Parser

  16. Program to open file

  17. Program to illustrate the implementation of X-Direction Shear Transformation

  18. Program to compute nCr

  19. Program to create vector

  20. Program to construct Newtons Divided Difference Interpolation Formula from the given distinct data points and estimate the value of the function