English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

this is wat i came up with hope u can expand on u. How can u store names in a array.

#include
using namespace std;

#define MAX 20

int main(){

char firstArray[MAX];

int counter = 0;
char yesNo;
while(1){
cout << "Enter a name to be stored in the array:";
cin >> firstArray[counter];
cout << "\nWhat to enter more names(y/n)";
cin >> yesNo;
if(yesNo == 'N' )
break;
else
counter++;
}
for(unsigned int loop = 0; loop <= (counter); loop++){
cout << int (firstArray[loop]) << endl;

}


system("PAUSE");
return(0);
}

2007-02-26 16:16:19 · answer #1 · answered by Best Helper 4 · 0 0

Coding, in any language centers around you knowing what you want to do and using the VERBS and Syntax of the language, in the correct order to accomplish what ever it is.

set up a counter/index set to 0, do the routine
Inside routine counter/index = itself plus 1
accept name from input source. If input source is blank and not at EOF End of file, repeat get name. Do not all 1 to index/counter.

If name > space, move to your name storage area (index/counter). Check if index/counter = 10.

if equal 10, sort name area and exit routine.
If less than 10 go to top of routine.

2007-02-26 16:04:43 · answer #2 · answered by Anonymous · 0 0

u need to first input 10 names and the sort them using any sorting algorithm like bubble sort, insertion sort, etc.
here is the program

// !! RAM !!
#include"iostream.h"
#include"string.h"
#define MAXLENGTH 100
char** ret(char *ptr[])
{
int sort=0;
while(sort < 9)
{
sort=0;
for( int i=0;i<9;i++)
{
if( strcmp(ptr[i], ptr[i+1]) >0 )
{
char*temp = ptr[i];
ptr[i]= ptr[i+1];
ptr[i+1] = temp;
}
else

sort++;
}
}
return ptr;
}
void main()
{
char*ptr[10];
for( int i=0;i<10;i++)
{
ptr[i]= new char[MAXLENGTH];
cout<<"enter "< cin>>ptr[i];
}
ret(ptr);
cout<<" the sorted names are::";
for( int j=0;j< 10;j++)
{
cout<<"\n"< }
}

2007-02-26 18:05:30 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers