Incrustar presentación
Descargar para leer sin conexión
![#include <iostream>
#include <iomanip>
#include <conio.h>
#include <string.h>
using namespace System;
using namespace std;
char NOMBRES [10][25];
void main ()
{
int r;
cout<<"n cuantas personas desea procesar: ";
cin>>r;
int x;
for (x=0;x<=r-1;x++)
{
cout<<"n digite el nombre de la person numero "<<x+1;
cin. ignore();
cin.getline (NOMBRES [x],25);
}
//ORDENAMIENTO DEL VECTOR TIPO CHAR
char temp[25];
for (int i=0;i<=r-2;i++)
{
for (int j=i+1;j<=r-1;j++)
{
if (strcmp (NOMBRES[i],NOMBRES[j])>0)
{
strcpy(temp,NOMBRES [i]);
strcpy(NOMBRES [i],NOMBRES [j]);
strcpy(NOMBRES [j],temp);
}
}
}
//IMPRESION DEL VECTOR ORDENADO
int u;
for (u=0;u<=r-1;u++)
{
cout<<"n"<<NOMBRES [u];
}
getch ();
}](https://image.slidesharecdn.com/feb28-130524191831-phpapp02/85/Feb28-1-320.jpg)
Este documento contiene código C++ que lee nombres de personas de la entrada estándar, los almacena en un arreglo de cadenas, los ordena alfabéticamente utilizando la función strcmp(), y luego imprime el arreglo ordenado. Primero solicita el número de nombres a procesar, luego lee cada nombre en un bucle for y lo almacena en el arreglo. Luego otro bucle for ordena el arreglo mediante comparaciones y swap de cadenas. Finalmente, imprime el arreglo ordenado.
![#include <iostream>
#include <iomanip>
#include <conio.h>
#include <string.h>
using namespace System;
using namespace std;
char NOMBRES [10][25];
void main ()
{
int r;
cout<<"n cuantas personas desea procesar: ";
cin>>r;
int x;
for (x=0;x<=r-1;x++)
{
cout<<"n digite el nombre de la person numero "<<x+1;
cin. ignore();
cin.getline (NOMBRES [x],25);
}
//ORDENAMIENTO DEL VECTOR TIPO CHAR
char temp[25];
for (int i=0;i<=r-2;i++)
{
for (int j=i+1;j<=r-1;j++)
{
if (strcmp (NOMBRES[i],NOMBRES[j])>0)
{
strcpy(temp,NOMBRES [i]);
strcpy(NOMBRES [i],NOMBRES [j]);
strcpy(NOMBRES [j],temp);
}
}
}
//IMPRESION DEL VECTOR ORDENADO
int u;
for (u=0;u<=r-1;u++)
{
cout<<"n"<<NOMBRES [u];
}
getch ();
}](https://image.slidesharecdn.com/feb28-130524191831-phpapp02/85/Feb28-1-320.jpg)