Академический Документы
Профессиональный Документы
Культура Документы
}
// Calcula promedio
promGeneral = acumGeneral/4.0; cout << endl;
// Salidad de datos
cout << "Numero de aprobados ....... : " << nAprobados << endl;
cout << "Numero de desaprobados .... : " << nDesaprobados << endl;
cout << "Promedio General Alumnos .. : " << promGeneral;
getch();
return 0;
}
INGRESAR 6 NOTAS Y DECIR CUÁNTOS APROBARON Y CUANTOS PERDIERON CON
PORCENTAJES Y NUMEROS.
#include<iostream.h>
#include<conio.h>
int main()
{
const int MAX=6;
float notas[MAX];
float nAprobados=0;
float nDesaprobados=0;
float pAprobados=0.0;
float pDesaprobados=0.0;
// Ingreso de notas
for(int i=0;i<MAX; i++)
{
cout<<"Ingrese nota : ";
cin>>notas[i];
}
cout<<"\nFin de datos ";
//Proceso de los datos
for(int j=0;j<MAX; j++)
{
if (notas[j]> 2.95)
nAprobados=nAprobados+1;
else
nDesaprobados=nDesaprobados+1;
}
pAprobados=float(nAprobados)/MAX;
pDesaprobados=float(nDesaprobados)/MAX;
//Salida de resultados
cout<<"\n\n El numero de aprobados es ...... : " << nAprobados;
cout<<"\n\n El numero de desaprobados es ... : " << nDesaprobados;
cout<<"\n\n El porcentaje de aprobados es .. : " << (pAprobados * 100) <<"%";
cout<<"\n\n El porcentaje de desaprobados es : " << (pDesaprobados * 100) <<"%";
getch();
return 0;
}
SUMA 2 VECTORES.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int main()
{
const int MAX=6;
int a[MAX]; int b[MAX]; int c[MAX];
// Ingreso de datos del arreglo a
cout<<"Ingrese datos del arreglo a\n\n";
for(int i=0;i<MAX; i++)
{
cout<<"Ingrese numero : ";
cin>>a[i];
}
// Ingreso de datos del arreglo b
cout<<"\nIngrese datos del arreglo b\n\n";
for(int j=0;j<MAX; j++)
{
cout<<"Ingrese numero : ";
cin>>b[j];
}
cout<<"\nFin de datos\n ";
//Calcular la suma de los arreglos a y b
for(int k=0;k<MAX; k++)
{
c[k]=a[k]+b[k];
}
//cout<<"\n\ A\t B\t\t C ";
for(int l=0;l< MAX; l++ )
{
cout<<"\n a["<<(l+1)<<"] ";
cout<<setw(5);
cout<<a[l];
cout<<"\tb["<<(l+1)<<"] ";
cout<<setw(5);
cout<<b[l];
cout<<"\t\tc["<<(l+1)<<"] ";
cout<<setw(5);
cout<<c[l];
}
getch();
return 0;
}
INGRESA 2 NUMEROS Y DI CUAL ES MAYOR.
#include<iostream.h>
#include<conio.h>
#include<string.h>
int main ()
{
int n1, n2;
char Mensaje1[50];
char Mensaje2[50];
cout << "\nIngrese 2 numeros enteros\n\n";
cout << "Primer numero .... : ";
cin >> n1;
cout << "Segundo numero ... : ";
cin >> n2;
// Comparación de números
if (n1==n2)
{
strcpy(Mensaje1, "Los numeros son iguales");
strcpy(Mensaje2, "");
}
else
{
if (n1>n2)
strcpy(Mensaje2, "El primer numero es mayor");
else
strcpy(Mensaje2, "El Segundo numero es mayor");
strcpy(Mensaje1, "Los numeros son diferentes");
}
cout << "\n" << Mensaje1;
cout << "\n" << Mensaje2;
getch();
return 0;
}
INGRESA APELLIDO PATERNO, INGRESA APELLIDO MATERNO, INGRESA NOMBRES Y
ORGANIZA EL NOMBRE COMPLETO.
#include<iostream.h>
#include<string.h>
#include<conio.h>
int main()
{
char apellidoP[50];
char apellidoM[50];
char nombres[50];
char Valor[100];
cout << "\nINGRESO DE DATOS\n";
cout << "----------------\n\n";
cout << "Ingrese su Apellido Paterno .... : "; cin >> apellidoP;
cout << "Ingrese su Apellido Materno .... : "; cin >> apellidoM;
cin.ignore();
cout << "Ingrese su Nombre .............. : "; cin.getline(nombres, sizeof(nombres));
strcpy(Valor, nombres); strcat(Valor, ", ");
strcat(Valor, apellidoP); strcat(Valor, ", ");
strcat(Valor, apellidoM);
cout << "\nNombre Completo : " << Valor;
getch();
return 0;
}
ORGANIZA UNA MATRIZ DE 3 POR 4 (UNO INGRESA LOS NUMEROS POR FILAS).
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
int main()
{
int num[3][4];
// lectura por filas
for (int a=0; a<3; a++)
{
for (int b=0; b<4; b++)
{
cout << "Numero [" << a+1 << "], [" << b+1 << "] : ";
cin >> num[a][b];
}
}
// Salida de datos
cout << "\n\n";
for(int c=0; c<3; c++)
{
for(int d=0; d<4; d++)
cout<<setw(5)<<num[c][d] << " ";
cout << endl;
}
getch();
return 0;
}
ORGANIZA UNA MATRIZ DE 3 POR 4 (POR COLUMNAS).
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
int main()
{
int num[4][3];
for (int a=0; a<4; a++)
{
for (int b=0; b<3; b++)
{
cout << "Número [" << b+1 << "], [" << a+1 << "] : ";
cin >> num[a][b];
}
}
cout << "\n\n";
for(int c=0; c<3; c++)
{
for(int d=0; d<4; d++)
cout<< setw(5)<<num[d][c] << " ";
cout << endl;
}
getch();
return 0;
}
ORGANIZA UNA MATRIZ DE 3X3 Y UBICA EL INDICE MAYOR DANDO LA UBICACIÓN DE
SU COLUMNA Y LA FILA.
#include <iostream.h>
#include <conio.h>
int main()
{
double mayor;
double num[3][3];
cout<<"Ingrese una matriz de 3 x 3 " << "\n\n";
for(int m = 0; m < 3; m++)
{
for(int n = 0; n < 3; n++)
{
cout << "Ingrese numeros de la matriz cuadrada [ ";
cout << m + 1 << " ],[ " << n + 1 << " ]: ";
cin >> num[m][n];
}
cout << "\n";
}
for(int a=0; a < 3; a++)
{
for(int b=0; b < 3; b++)
{
cout<<num[a][b]<<"\t";
}
cout<<"\n";
}
mayor=num[0][0];
for(int p=0; p < 3; p++)
{
for(int q = 0; q < 3; q++)
{
if(num[p][q] > mayor)
mayor = num[p][q];
}
}
cout << "\nEl mayor valor es : " << mayor;
cout << " con respecto a los indices :" << "\n";
for(int z = 0; z < 3; z++)
{
for(int v = 0; v < 3; v++)
{
if(num[z][v] == mayor)
{
cout << "\nSe ubica en la fila " << z + 1 << "\n";
cout << "se ubica en columna " << v + 1 << "\n";
}
}
}
getch();
return 0;
}
}
cout << endl;
for(int g=0; g<3; g++)
cout <<"El mayor elemento de la fila " << g+1
<< " " << "es : " << mayorf[g] << "\n";
for(int h=0; h<2; h++) // Mayor elemento por columnas
{
for(int i=0; i<3; i++)
{
if(num[i][h]>mayorc[h])
mayorc[h]=num[i][h];
}
}
cout << endl;
for(int j=0; j<2; j++)
cout <<"El mayor elemento de la columna " << j+1
<<" "<<"es : "<<mayorc[j]<<"\n";
getch();
return 0;
}
REALIZA UN ARREEGLO DANDO LA UBICACIÓN EN ORDEN DE NUMEROS INGRESADOS Y
REALIZA UN HISTOGRAMA.
#include<iostream.h>
#include<iomanip.h>
#include<String.h>
#include<conio.h>
int main()
{
const int elementos = 5;
int numero = 0;
char datos[35][elementos];
int matrix[elementos];
cout << "Valores para el arreglo\n\n";
for (int a=0; a<elementos; a++)
{
cout << "x[" << a+1 << "] = "; cin >> matrix[a];
for (int g = 0; g < matrix[a];g++)
strcpy(datos[g], "*");
}
cout << "\nSalida de resultados\n\n";
cout << setiosflags(ios::left);
cout << setw(10)<< "Elemento" << setw(10) << "Valor";
cout << setw(10) << "Histograma" <<endl;
for (int d=0; d < elementos; d++)
{
cout << setw(10)<< d+1 << setw(10)<< matrix[d];
for (int t = 0; t < matrix[d];t++)
{
cout << datos[t];
}
cout << endl;
}
getch();
return 0;
}
DIGITE NOMBRE DEL LIBRO, DIGITE NOMBRE DEL AUTOR, DIGITA NOMBRE DE LA
EDITORIAL Y LA FECHA DE PUBLICACION; ARROJA TODOS LOS DATOS DE MANERA
ORDENADA.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
struct Fecha_edicion
{
unsigned int dia;
unsigned int mes;
unsigned int anyo;
};
struct Datos_libro
{
char nombre[50];
char autor[30];
char editorial[30];
Fecha_edicion fecha;
};
struct Libro
{
Datos_libro Datos_libro;
double costo;
};
int main()
{
Libro lib;
cout << "\nNombre del Libro.... : "; cin.getline(lib.Datos_libro.nombre,51);
cout << "Nombre del autor.... : "; cin.getline(lib.Datos_libro.autor,31);
cout << "Nombre del editorial : "; cin.getline(lib.Datos_libro.editorial,31);
cout << "\n\nFecha de edicion del libro\n";
cout << "Dia : "; cin >> lib.Datos_libro.fecha.dia;
cout << "Mes : "; cin >> lib.Datos_libro.fecha.mes;
cout << "Año : "; cin >> lib.Datos_libro.fecha.anyo;
cout << "\n\nLISTADO DE DATOS\n";
cout << "----------------\n\n";
cout << setiosflags(ios::left);
cout << setw(20) << "LIBRO";
cout << setw(20) << "AUTOR";
cout << setw(20) << "EDITORIAL";
cout << setw(15) << "FECHA EDICION\n\n";
cout << setw(20) << lib.Datos_libro.nombre;
cout << setw(20) << lib.Datos_libro.autor;
cout << setw(20) << lib.Datos_libro.editorial;
cout << lib.Datos_libro.fecha.dia;
cout << "/" << lib.Datos_libro.fecha.mes;
cout << "/" << lib.Datos_libro.fecha.anyo;
cout << endl;
getch();
return 0;
}
INGRESO DE DATOS, CODIGO, NOMBRE, CANTIDAD Y PRECIO Y LOS COLOCA EN LISTA
CON EL PRECIO TOTAL DE LA COMPRA.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
struct Ventas
{
char cod_producto[50];
char nombre_producto[50];
double precio;
int cantidad;
double importe;
};
int main()
{
const int numero = 2;
Ventas mante_ventas[numero];
cout << "INGRESOS DE PRODUCTOS" << endl;
cout << "---------------------" << endl;
for (int i=0; i < numero; i++)
{
cout << "\ndatos del producto " << i+1 << endl;
cout << "\nCodigo....: "; cin >> mante_ventas[i].cod_producto;
cout << "Nombre....: "; cin >> mante_ventas[i].nombre_producto;
cout << "precio....: "; cin >> mante_ventas[i].precio;
cout << "Cantidad..: "; cin >> mante_ventas[i].cantidad;
mante_ventas[i].importe = (mante_ventas[i].cantidad * mante_ventas[i].precio);
}
cout << "\nREPORTE DE PRODUCTOS" << endl;
cout << "--------------------\n\n";
cout << setiosflags(ios::left);
cout << setw(10) << "Codigo";
cout << setw(15) << "Nombre";
cout << setw(10) << "Precio";
cout << setw(12) << "Cantidad";
cout << setw(3) << "Importe" << endl;
for (int c=0; c<numero; c++)
{
cout << setw(10) << mante_ventas[c].cod_producto;
cout << setw(15) << mante_ventas[c].nombre_producto;
cout << setw(10) << mante_ventas[c].precio;
cout << setw(12) << mante_ventas[c].cantidad;
cout << setw(3) << mante_ventas[c].importe << endl;
}
getch();
return 0;
}
REALIZAR UN MENU CON 6 ENTARDAS.
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
char opcion_menu;
enum Menu
{
Nuevo = '1',
Editar = '2',
Grabar = '3',
Cancelar = '4',
Eliminar = '5',
Salir = '6',
};
void menu ()
{ clrscr();
cout << "\nMENU PRINCIPAL\n";
cout << "\n[1] Nuevo";
cout << "\n[2] Editar";
cout << "\n[3] Grabar";
cout << "\n[4] Cancelar";
cout << "\n[5] Eliminar";
cout << "\n[6] Salir";
cout << "\n\nIngrese su opcion : ";
do
{
opcion_menu = getch();
} while (opcion_menu < '1' || opcion_menu == '7' );
cout << opcion_menu;
}
int main ()
{
int salir = 0;
while (salir != 1)
{
menu();
clrscr();
switch (opcion_menu)
{
case Nuevo:
cout << "Nueva opcion"; break;
case Editar:
cout << "Editar opcion"; break;
case Grabar:
cout << "Grabar opcion"; break;
case Cancelar:
cout << "Cancelar opcion"; break;
case Eliminar:
cout << "Eliminar opcion"; break;
case Salir:
cout << "Presione cualquier tecla para salir";
salir = 1;
break;
}
getch();
}
return 0;
}
INGRESAR 3 NUMEROS Y DECIR CUAL ES EL MENOR.
#include<iostream.h>
#include<conio.h>
// función calcula menor de tres números
int menor(int x, int y, int z);
int main()
{
int a,b,c;
clrscr();
cout<<"\nIngrese el primer numero .... : ";
cin >> a;
cout<<"Ingrese el segundo numero ... : ";
cin >> b;
cout<<"Ingrese el tercer numero .... : ";
cin >> c;
// llama a la función menor y le pasa los tres números ingresados
cout << "\n\nEl numero menor es : " << menor(a,b,c) << endl;
getch();
return 0;
}