[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]


    Search the Q&A Archives


what code in c++ do you use to alphabetize a list

<< Back to: C++ FAQ (part 1 of 10)

Question by grace
Submitted on 11/19/2003
Related FAQ: C++ FAQ (part 1 of 10)
Rating: Rate this question: Vote
what code in c++ do you use to alphabetize a list


Answer by Ross
Submitted on 4/15/2005
Rating: Not yet rated Rate this answer: Vote
# include <iostream.h>
# include <string.h>
# include <stdlib.h>


struct friend_data
{
   char last_name[20]; //key field
   char first_name[15];
   char phone_num[15];
};

main()
{
   friend_data firas[8];
   int x, y, z;

   for(x=0; x<8; x++)
   {
      cout << endl;
      cout << "Enter the first name of student number " << x + 1 << endl;
      cin.get(firas[x].first_name, 20);
      cin.ignore(80, '\n');
      cout << "Enter the last name of student number " << x + 1 << endl;
      cin.get(firas[x].last_name, 20);
      cin.ignore(80, '\n');
      cout << "Enter the phone number of student number " << x + 1 << endl;
      cin.get(firas[x].phone_num, 20);
      cin.ignore(80, '\n');
   }


   int smallest = 0;
   friend_data hold;

   for(z=0; z<8; z++)
   {

   for(x=7; x>0; x--)
   {
      for(y=0; y <= x; y++)
      {
         //find the smallest value in the string
         if(strcmp(firas[y].last_name, firas[smallest].last_name) > 0)
         {
            smallest = y;
         }
      }
      hold = firas[smallest];
      firas[smallest] = firas[x];
      firas[x] = hold;
   }

   }

   //use a for loop to output the strings in alphabetical order
   cout << "*********************************\nLast Name, First Name\nPhone Number\n*********************************\n";
   for (x=0; x<8; x++)
   {
      cout << firas[x].last_name << ", " << firas[x].first_name << endl << firas[x].phone_num << endl << endl;
   }

   return 0;
}

 

Answer by sup11
Submitted on 1/16/2006
Rating: Not yet rated Rate this answer: Vote
hey yeah what odes this lenguage  do?
i know html lenguage is to make web pages but c++ ? does that creats programs or does it go along with html to make web pages????? som one can explain me please

 

Answer by Stewy2
Submitted on 4/3/2006
Rating: Not yet rated Rate this answer: Vote
no clue

 

Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.


Your name or nickname:
If you'd like to create a new account or access your existing account, put in your password here:
Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.

 

FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.

 

<< Back to: C++ FAQ (part 1 of 10)


[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

© 2008 FAQS.ORG. All rights reserved.