Hello every body..............
any one can help me about this program. I want to create a simple program in C++ i want
When the program runs they prompt
"Enter the Names:"
for example:
Name1: Abc
Name2: Cup
Name3: Altavista
Name4: Yahoo
Name5: Mbni
Name6: Sun
Name7: Mani
Name8: Google
Name9: Pakisan
Name10: Watan

Then tey asort these numbers and prompted.
"The Sorted names in ascending order are as:

Abc
Altavista
Cup
Google
Mani
Mbni
Pakistan
Sun
Watan
Yahoo

and thene they prompt

"Press any key to continue......."
and when i press any key then the program is exit.

Remember i have use a Dev-C++ editor to create a program so Please provide me codes in .cpp format and they run correctly in Dev-C++ editor. Because I am a very bigining in C++.
Thanks.
Ali.

alikoli, is the program always going to prompt the user for 10 inputs (and only 10 inputs) or are there a variable number of inputs (as defined by the user)? Because if the user is always expected to input 10 names, then we can simply define an array with a defined size of 10 and then sort it from there. But if the user can enter any number of names as he/she wishes, this might be more involved (but not hard). If it's a variable number of names, then we might have to define some sentinel value, such as "Press 'e' to indicate that the user has finished entering all the names" and then sort the array from there. Of course, since array dimensions can't be calculated dynamically, we must define the array to have a default size of 100, for instance. I don't think anyone is going to do this assignment for you, but we are willing to help you if you actually try it. If you try and still get problems, post the errors and we'll try to assist you. Hope this helps!

> Because I am a very bigining in C++.
So do the very beginning thing of reading in 10 names and printing them out again.

That at least would mean you've made a start, and not just another homework sponge looking for a free ride through life.
Also, read all the forum rules, which you obviously missed the first time around.

Please take this help lightly , don't be a sponge actually try to understand why the function I show you works and you will be better off. All programs can be written using regular conditional statements but this usually takes a long time to write. Try to think about what you want to do first on paper, then try to translate it into code. The more functions and implementations you know how to use helps alot so google functions you don't know and try to understand them so you can use in the future. Now on to your problem.

There are many sorting algoritims( google this) out there that you can use to do this.
look up the command strcmp()(google this), and know your logic(conditional statements(google this).

Definition

sorting - an operation that segregates items into groups according to a specified criterion;

in your situaton you want to segerate the names into groups accoding to alphabetical order.

Simple case

Names

B
A
C

should be

A
B
C

implementation of strcmp()

string letters[3] = { "B", "A","C" };

int i,j, min, min_pos;
char min_name[5], temp[5];

for(i=0;i<3;i++)
{
        strcpy(min_name, letters[i]);//takes the first letter as the index
        min_pos=i;
        for(j=i;j<3;j++)
        {
              	if ((strcmp(min_name, letters[j])>0))
	{
		strcpy(min_name,letters[j]);
		min_pos=j;// rember position
	}
        }
        strcpy(temp,letters[i]);
        strcpy(letters[i],letters[min_pos]);
        strcpy(letters[min_pos],temp);
}

Now if you cout or output into a file the letters array it should be in alphabetical order.

This article has been dead for over six months. Start a new discussion instead.