20 Vectores ordenamiento con vectores paralelos

Páginas: 3 (507 palabras) Publicado: 31 de mayo de 2016
VECTORES
(ORDENAMIENTO CON
VECTORES PARALELOS)

VECTORES (ORDENAMIENTO
CON VECTORES PARALELOS)
Cuando se tienen vectores paralelos y se ordena
uno de ellos hay que tener la precaución deintercambiar los elementos de los vectores
paralelos.
Problema 1:
 Confeccionar un programa que permita cargar los
nombres de 5 alumnos y sus notas respectivas.
Luego ordenar las notas de mayor a menor.Imprimir las notas y los nombres de los alumnos.
Programa:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PruebaVector16
{
class PruebaVector16
{
privatestring[] nombres;
private int[] notas;


VECTORES (ORDENAMIENTO
CON VECTORES PARALELOS)
public void Cargar()
{
nombres=new string[5];
notas=new int[5];
Console.WriteLine("Carga de nombres y notas");for(int f=0;f < nombres.Length;f++)
{
Console.Write("Ingese el nombre del alumno:");
nombres[f]=Console.ReadLine();
Console.Write("Ingrese la nota del alumno:");
string linea;
linea =Console.ReadLine();
notas[f]=int.Parse(linea);
}
}
public void Ordenar()
{
for (int k = 0; k < notas.Length; k++)
{
for (int f = 0; f < notas.Length - 1 - k; f++)
{
if (notas[f] < notas[f + 1])
{
int auxnota; auxnota =notas[f];
notas[f] = notas[f + 1];
notas[f + 1] = auxnota;
string auxnombre;
auxnombre = nombres[f];
nombres[f] = nombres[f + 1];
nombres[f + 1] = auxnombre;
}
}
}
}

VECTORES (ORDENAMIENTO
CONVECTORES PARALELOS)
public void Imprimir()
{
Console.WriteLine("Nombres de alumnos y notas de mayor a
menor");
for(int f=0;f < notas.Length;f++)
{
Console.WriteLine(nombres[f] + " - " + notas[f]);
}Console.ReadLine();
}
static void Main(string[] args)
{
PruebaVector16 pv = new PruebaVector16();
pv.Cargar();
pv.Ordenar();
pv.Imprimir();
}
}
}
Problemas propuestos
 Cargar en un vector los nombres de 5paises y en otro vector
paralelo la cantidad de habitantes del mismo. Ordenar
alfabéticamente e imprimir los resultados. Por último ordenar con
respecto a la cantidad de habitantes (de mayor a...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Ordenamiento De Vectores
  • vectores paralelos c++ ordenar alfabeticamente
  • Metodo de ordenamiento de vectores
  • Metodos para ordenar vectores
  • como ordenar un vector
  • Metodos De Ordenamiento De Matrices Y Vectores
  • Vectores Paralelos
  • Vectores

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS