jueves, 26 de mayo de 2011

Practica # 10

Problema 1

1.- Inicio


ofstream archivo;
archivo.open("C:\\datos\\ejemplo.txt")
if(archivo.bad())
{
Print " No puede crear el archivo ejemplo.txt ";
}
else
{
archivo , 1 ,"  ", 50 , " Reprobado ";
archivo , 2 ,"  ", 0 , " Ausente ";
archivo , 3 ,"  ", 80 , " Aprobado ";
archivo , 4 ,"  ", 100 ," Aprobado ";
archivo.close()
}
Print " Datos guardados exitosamente "
Fin




Problema 2

1.- Inicio

ifstream arch1;
 calif,i           int
 cadena[10]      char
arch1.open("C:\\datos\\ejemplo.txt");
if(arch1.bad())
{
Print " Incapaz de crear o abrir el archivo ";
}
else
{
arch1 , i;
while(!arch1.eof())
{
Print  i ,"     ";
arch1 , calif;
Print calif ," \t ";
arch1 , cadena;
Print  cadena ;
arch1 , i;
}
arch1.close()
}

Fin



Problema 3

1.- Inicio

fstream f1;
 cadena[10],sigue,nombre[5][10];     char
 c1,c2,c3,c4,i=0;       int 
 promedio;      int
 opcion;     int
f1.open("C:\\datos\\ejemplo2.txt",ios::out);
do{
Print " 1) Almacenar datos del alumno : "<<endl;
Print " 2) Reporte de alumnos : "<<endl;
Print " 3) Salida de programa : "<<endl;
Print " Elige opcion : ";
Read opcion;
switch(opcion)
{
case 1:
do
{
Print " Nombre alumno : "<<(i+1)<<" : ";
Read  nombre[i];
Print " Calificacion 1 : ";
Read  c1;
Print " Calificacion 2 : ";
Read  c2;
Print " Calificacion 3 : ";
Read  c3;
Print " Calificacion 4 : ";
Read c4;
promedio = (c1+c2+c3+c4)/4;
f1,nombre," ",c1," ",c2," ",c3," ",c4," ",promedio," ;
if(promedio>=70)
{
f1,"Aprobado";
Print "*Aprobado";
}
else{
f1,"Reprobado"l;
Print "**Reprobado";
}
Print "Desea registrar a otro(s/n)";
Read sigue;
}
while(sigue=='s' || sigue=='S');
f1.close();
break;
case 2:
f1.open("C:\\datos\\ejemplo2.txt",ios::app);
Print "Nombre   Calif 1  Calif 2  Calif 3  Calif 4  Promedio";
if(f1.bad())
{
Print "Incapaz de crear o abrir el archivo";
}
else{
f1,nombre[i];
while(!f1.eof());
{
Print nombre[i+1]," ";
f1,c1;
Print c1,"\t";
f1,c2;
Print c2,"\t";
f1,c3;
Print c3, "\t";
f1>>c4;
Print c4,"\t";
f1,promedio;
Print promedio,"\t";
f1>>cadena;
Print cadena,"\t";
f1,nombre[i];
}
}
f1.close();
break;
case 3: Print"Salida Programa";
break;
default: Print ,"Error en Opcion";
break;
}
}
while(opcion !=3)
Fin.




Problema 4

Un archivo llamado polar.txt contiene las coordenadas pobres nesesarias en un programa de graficas.Actualmente este archivo contiene los siguientes datos.

                  Distancia (Pulgadas)          Angulo (Grados)      
             2.0                              45.0
             6.0                              30.0
            10.4                             45.0
             4.0                              60.0
            12.0                             55.0
             8.0                              15.0

a) Escriba u programa para crear este archivo.
b) Con base al archivo polar.txt escriba un programa que acepte del usuario los datos de distancia y angulo y los agregue al final del archivo.
c) Con el archivo polar. txt escriba u programa que lea este archivo y cree otro llamado xycord.txt las entradas al nuevo archivo deben contener las coordenadas rectangulares que corresponden a  las coordenadas polares.
x=ycosenohttps://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin2vsIMFoF56VPSuoLm9B3-uysq_eT5MFrzgc0MZDXqlZ5u0c1SRBG3pHRfxdK2OL5mUhizyekBbM4SUgZQNMzM_lsUpchR6ObbnFFU8ZAKY1Hl4gnfegstCy310xbbiV4EEbAzmC1rAyg/s1600/XGZvcmFsbFwgXHRoZXRhLFxwaGkgXGluIFxtYXRoYmJ7Un0%253D.png
y=rsenohttps://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin2vsIMFoF56VPSuoLm9B3-uysq_eT5MFrzgc0MZDXqlZ5u0c1SRBG3pHRfxdK2OL5mUhizyekBbM4SUgZQNMzM_lsUpchR6ObbnFFU8ZAKY1Hl4gnfegstCy310xbbiV4EEbAzmC1rAyg/s1600/XGZvcmFsbFwgXHRoZXRhLFxwaGkgXGluIFxtYXRoYmJ7Un0%253D.png

Donde r es la coordenada de distancia y https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin2vsIMFoF56VPSuoLm9B3-uysq_eT5MFrzgc0MZDXqlZ5u0c1SRBG3pHRfxdK2OL5mUhizyekBbM4SUgZQNMzM_lsUpchR6ObbnFFU8ZAKY1Hl4gnfegstCy310xbbiV4EEbAzmC1rAyg/s1600/XGZvcmFsbFwgXHRoZXRhLFxwaGkgXGluIFxtYXRoYmJ7Un0%253D.png es el equivalente en radianes a la coordenada del angulo en el archivo polar.txt.


1.- Inicio

void crearchivo()
{
fstream escribir;
escribir.open("C://datos//polar.txt",ios::out);
escribir , 2.0 ,"   ", 45.0; 
         , 6.0 ,"   ", 30.0 ;
         , 10.0 ,"   ", 45.0; 
         , 4.0 ,"   ", 60.0 ;
         , 12.0 ,"   ", 55.0 ;
         , 8.0 ,"   ", 15.0 ;
escribir.close();
}

void agregard()
{
 dist,angulo      float
 continuar      char
fstream escribir;
escribir.open("C://datos//polar.txt",ios::app);
do
{
Print " Distancia (Pulgadas): ";
Read dist;
Print " Angulo (Grados): ";
Read angulo;
escribir , dist ,"     ",angulo;
Print " Deseas registrar otro (S/N):";
Read continuar;
}
while (continuar=='S'||continuar=='s');
escribir.close();
}

void crearxycord()
{
float d,a,x,y,rad;
fstream f1;
fstream f2;
f1.open ("C://datos//polar.txt",ios::in);
f2.open ("C://datos//xycord.txt",ios::out);
f1,d;
while (!f1.eof())
{
f1,a;
rad = (a*3.1416)/180;
x = d*cos(rad);
y = d*sin(rad);
f2,x,"  ",y;
f1,d;
Print  x ," : ", y ;
}
f1.close()
f2.close()
}


void main()
{
crearchivo()
agregard ()
crearxycord ()
Fin.





Problema 5

Escriba los cuatro numeros reales 
                                                         92.65
                                                         88.72
                                                         77.46
                                                         82.93
en un archivo texto llamado resultados.Despues de escribir los datos en el archivo el programa debe leerlos determinar y desplegar el promedio de los cuatro numeros leidos. 

1.- Inicio

 num;    float
fstream archivo;
archivo.open("c://datos//resultados.txt",ios::out,ios::in);
archivo , 92.65 , "      ", 88.72 , "      ", 77.46 , "     " 82.93;
archivo.close();
float suma = 0;
archivo.open("c://datos//resultados.txt",ios::in);

for(int i=1;i<=4;i++)
{
archivo , num;
Print num,"  ";

suma = suma + num;
}
;
 promedio = suma/4.0;    float
Print " El promdio es : ",promedio;

Fin.




Problema 6

1.- Inicio

void ordenar (int n,char x[10][12])
{
 temp[12];     char
 i,elem;      int
for(elem=0;elem<(n-1);elem++)
{
for(i=elem+1;i<(n-1);i++)
{
if(strcmpi(x[elem],x[i])<0)
{
strcpy(temp,x[elem]);
strcpy(x[elem],x[i]);
strcpy(x[i],temp);
} } } }

void main ()
{
 i,n=0;     int
 x[10][12];    char
Print " Escribe fin para terminar ";
do
{
Print " Cadena ",(n+1)," : ";
Read x[n];
}
while(strcmpi(x[n++]," Fin "));
ordenar(--n,x);
Print " Lista Ordenar Cadena ";
for(i=0;i<n;i++)
{
Print x[i] ;
}
Fin.



miércoles, 25 de mayo de 2011

Tarea # 1Unidad 3

Problema 1


1.- Inicio

x,y     int
Linea [] = " | "    char
for (x=1 to 15 step x++)
{
y = pow ((x-8),2.0) +3
Linea [y] = " * ";
Print Linea;
Linea [y] = '  ';
}
Fin.



Problema 2

1.- Inicio

x,y     int
Etiqueta [ ] = "                         Eje Y";      char
Eje [ ] = "+----------------------------------------------------->";    char
Linea [ ] = " |                                                                        ";    char
Print Etiqueta;
Print Eje;
for (x=1 to 15 step x++)
{
y = pow ((x-8),2.0) +3

Linea [y] = " * ";
Print Linea;
Linea [y] = '  ';
}
Fin.





sábado, 14 de mayo de 2011

Practica # 9



Problema 1


1.- Inicio


void introdatos(int v[5][4]);
void sumarenglon (int v[5][4]);
void sumacolumna (int v[5][4]);
void imprimetabla(int v[5][4]);
void minimo (int v[5][4],int & min,int & posr,int & posc);
void maximo (int v[5][4],int & max,int & posr,int & posc);


void introdatos(int v[5][4])
{
 r,c;      Real
for (r=0; to 5 step ; r++)
{
for(c=0; to 4 step; c++)
{
Print "Datos" ,(r+1)," , ",(c+1)," :"
Read v[r][c];
}
}
}

void sumarenglon (int v[5][4])
{
 suma, r, c      Real
Print "               Suma de renglon";
for (r=0; to 5 step; r++)
{
suma = 0;
for(c=0; to 4 step ; c++)
{
suma = suma + v[r][c];
}
Print " Renglon  ",(r+1),":",suma;
}
}

void sumacolumna (int v[5][4])
{
 suma, r, c;    Real
Print "    suma de columnas : ";
for(c=0; to 4 step; c++)
{
suma = 0;
 for (r=0; to 5 step; r++)
{
suma = suma+v[r][c];
}
Print "La suma de la columna",(c+1),":","es:",suma;
}
}


void imprimetabla(int v[5][4])
{
 r, c;     Real
for (r=0; to 5 step; r++)
{
for(c=0; to 4 step; c++)
{
Print v[r][c],"\t";
}
Print        ;
}
}


void minimo (int v[5][4],int & min,int & posr,int & posc)
{
 r,c;     Real
min = v[0][0];
posr = 0;
posc = 0;
for(r=0; to 5 step ;r++)
{
for(c=0;to 4 step;c++)
{
if(v[r][c]<min)
{
min = v[r][c];
posr = r;
posc = c;
}
}
}
}


void maximo (int v[5][4],int & max,int & posr,int & posc)
{
 r,c;    Real
max = v[0][0];
posr = 0;
posc = 0;
for(r=0;to 5 step ;r++)
{
for(c=0;to 4 step;c++)
{
if(v[r][c]>max)
{
max = v[r][c];
posr = r;
posc = c;
}
}
}
}


void main ()
{
 valores[5][4]    Real
 pr1,pc1,pr2,pc2,max,min   Real

introdatos(valores)
sumarenglon(valores)
sumacolumna(valores)
imprimetabla(valores)
maximo(valores,max,pr1,pc1)
minimo(valores,min,pr2,pc2)
Print "Desplegar el valor maximo ",max;
Print "entre la posiscion",pr1,",",pc1;
Print "Desplegar el valor minimo ",min;
Print"entre la posiscion",pr2,",",pc2;

Fin





Problema 2



Escriba un programa que sume los elementos equiparables de los arreglos bidimensionales  
denominados “primero” y “segundo”. Ambos arreglos deben de tener 2 renglones y 3 columnas.
Por ejemplo los elementos [1][2] del arreglo que resulte deban ser la suma del primero y del segundo. 
Los arreglos “primero” y “segundo” deben son introducidos por el usuario




1.- Inicio



void introdatos(int a[2][3], int b[2][3])
{
 r,c;  Real
for (r=0; to 3 step; r++)
{
for(c=0; to 2 step; c++)
{
Print "Datos" ,(r+1)," , ",(c+1)," :"
Read a[r][c]
Print "Datos" ,(r+1)," , ",(c+1)," :"
Read b[r][c]
}
}
}


void imprimedatos(int a[2][3],int b[2][3],int d[2][3])
{
 r,c;    Real
Print "1er num.   +   2do num.";
cout<<endl;
for(r=0;to 3 step;r++)
{
for(c=0;to 2 step;c++)
{
Print a[r][c],"       +      ",b[r][c],"     =    ",d[r][c];
}
}
}

void sumardatos(int a[2][3],int b[2][3],int d[2][3])
{
 r,c;    Real
for(r=0;to 3 step;r++)
{
for(c=0;to 2 step;c++)
{
d[r][c] = a[r][c]+ b[r][c];
}
}
}

void main()
{
 primer[2][3],segundo[2][3],tercer[2][3]     Real
introdatos(primer,segundo);
sumardatos(primer,segundo,tercer);
imprimedatos(primer,segundo,tercer);

Fin






Problema 3


1.- Inicio



void introdatos(int m[4][4])
{
 r,c;    Real
randomize();
for(r=0;to 4 step;r++)
{
for(c=0; to 4 step;c++)
{
m[r][c]=random(10000)+1;
}
}
}

void imprimematriz(int m[4][4])
{
 r,c;    Real
for(r=0;to 4 step; r++)
{
for(c=0; to 4 step; c++)
{
cout<<m[r][c],"\t ";
}
}
}


void transpuesta(int m[4][4],int m1[4][4])
{
 r,c;    Real
for(r=0; to 4 step; r++)
{
for(c=0; to 4 step; c++)
{
m1[c][r] = m[r][c];
}
}
}

void main()
{
int a[4][4];
int a1[4][4];
introdatos(a);
transpuesta(a,a1);
imprimematriz(a);
imprimematriz(a);

Fin





Problema 4


1.- Inicio



void introdatos(int w[3])
{
 i;   Real
for(i=0; to 3 step; i++)
{
Print "w = ",(i+1);
Read w[i]
}
}


void introcalificacion(int m[5][3])
{
 r,c;    Real
for(r=0; to 5 step; r++)
{
for(c=0; to 3 step; c++)
{
Print "calificacion = ",(r+1),m[r][c];
}
}
}

void promedio(int m[5][3], int w[3], float c1[5])
{
 r,c,suma;   Real
for(r=0; to 5 step; r++)
{
suma=0;
for(c=0; to 3 step; c++)
{
suma = suma + m[r][c]*w[c];
}
c1[r] = suma/6.0;
}
}

void sumaw(int w[3])
{
 i,s;     Real
s=0;
for(i=0; o 3 step; i++)
{
s = s+w[i];
}
return s;
}


void rango(float c1[5], int r[5])
{
 e,i,mayor,name;    Real
for(e=0; to 5 step; e++)
{
mayor = 0;
for(i=0; to 3 step; i++)
{
if(c1[i]>mayor)
{
name = i;
mayor = c1[i];
}
}
r[name] = i;
c1[name] = 0;
}
}

void imprimir(int r[5])
{
 i;    Real
for(i=0; to 3 step; i++)
{
Print "No. estuduante: ",(i+1);
Print "suposicion en clase es : ",r[i];
}
}

void main()
{
int w[3];
int m[5][3];
float c1[5];
int r[5];
introdatos(w);
introcalificacion(m);
promedio(m, w, c1);
sumaw(w);
rango(c1, r);
imprimir(r);

Fin

Problema 5



Elaborar un programa que lea el nombre de  10 trabajadores y su produccion mensual por cada uno de los 12 meses del año, en dos arreglos uno para nombres y otro para produccion en los cuales las las "n" corresponden al trabajador.

Se requiere el siguiente reporte
Estacion                               Total Produccion
1                                                 xxxxxxx
2                                                 xxxxxxx
3                                                 xxxxxxx
4                                                 xxxxxxx
.
.
.
15                                               xxxxxxx

Total
Estacion mas productiva:________
Encargado de la Estación:__________
Cantidad Producida:___________



1.- Inicio




void calculoprodanual(int produccion[15][12],int prodtotal[15])
{
 i,j;      int
for(i=0;to 15 step;i++)
{
 suma=0    int
for(j=0;to 15 step;j++)
{
suma = suma+produccion[i][j]
Print produccion[i][j],"\t"
}

prodtotal[i] = suma
}
}

void introdatos(char nombre[15][20],int produccion[15][12])
{
 i,j;    int
randomize()
for(i=0;to 15 step;i++)
{

Print "Nombre del Encargado Estacion ",(i+1)," :"
Read nombre[i]
for(j=0;to 12 step;j++)
{

produccion[i][j] = random(50000)+1
Print produccion[i][j],"     ";
}

}
}

void mayorproductividad(int prod_total[15],int &mayor,int &pos)
{
 i;      int
mayor = prod_total[0]
pos = 0
for (i=1;to 15 step;i++)
{
if(prod_total[i]>mayor)
{
mayor = prod_total[i];
pos = i;
}
}
}

void main()
{
 prod[15][12]     int
 ptotal[15]        int
 nom[15][20]    char
 may,p1;      int
introdatos(nom,prod);
calculoprodanual(prod,ptotal);
mayorproductividad(ptotal,may,p1);
Print "La estacion mas productiva es:",(p1+1);
Print "Encargado de la estacion:",nom[p1];
Print "Cantidad producida:",ptotal[p1];

Fin.







Problema 6



Elaborar un programa que genere una matriz de 10x10 en la cual asigne ceros a todos los elementos excepto a los de la diagonal principal donde asignara unos, imprima dicha matriz.

1.- Inicio

void asignarvalores(int m[10][10])
{
 r,c;    Real
for(r=0; to 10 step; r++)
{
for(c=0; to 10 step; c++)
{
if(r==c)
{
m[r][c]=1;
}
else
{
m[r][c]=0;
}
}
}
}


void imprimematriz(int m[10][10])
{
 i,c;     Real
for(i=0; to 10 step; i++)
{
for(c=0; to 10 step; c++)
{
Print m[c][c]," ";
}
}
}

void main()
{
int matriz[10][10];
asignarvalores(matriz);
imprimematriz(matriz);

Fin




Problema 7



Elaborar un programa que de el informe de 10 trabajadores y su producción mensual los 12 meses en 2 arreglos. El informe debe de ir de la siguiente manera:
Nombre                                 Total de producción:
________                             ________________
________                             ________________
________                             ________________
Promedio de producción:______________

1.- Inicio

void introdatos(int produccion[10][13])
{
randomize ()
 i,j,suma;    real
for (i=0;to 10 step;i++)
{
suma = 0;
for (j=0;to 12 step;j++)
{
produccion[i][j] = random(5000)+1
suma = suma+produccion[i][j]
Print produccion[i][j],"\t";
}
produccion[i][12] = suma;
} }

void leernombres(char name[10][25])
{
int i;
for (i=0;to 10 step;i++)
{
Print "Nombre del Trabajador: ",(i+1)," : ";
cin.getline(name[i],25);
} }

void reporte(int produccion[10][13], char name[10][25])
{
 suma,i,prom;    real
Print " Analisis de Produccion  ";
Print " Nombre\t  Total Produccion ";
suma = 0;
for(i=0;to 10 step;i++)
{
Print name[i]," \t ",produccion[i][12]l
suma = suma+produccion[i][12]; }
prom = suma/10;
Print " Promedio de Produccion ",prom;
Print " Listado de Trabajadores Mayores a ",prom;
for (i=0;to 10 step;i++)
{
if (produccion[i][12]>prom)
{
Print name[i];
} } }

void main ()
{
 p[10][13]      real
 nom[10][25]      char
leernombres(nom)
introdatos(p)
reporte(p,nom)

Fin 






Problema 8


1.- Inicio



ifstream  entrada;
entrada.open("c://datos//grupos.txt");
 dato;   Real
for(int j=1; to 3 step; j++)
{
for(int j=1; to 4 step; j++)
{
entrada,dato;
Print dato,"\t";
}

}


ofstream  salida;
salida.open("c://datos//grupos.txt");
salida,"42  90  35  46",
salida,"28  76  31  92",

salida.close();
Print "datos almacenados";

Fin







Problema 9


Ejecute el archivo creado en el ejercicio 8 en un programa completo. Que realice la suma de los renglones y columnas de los valores dados en el archivo.


1.- inicio



void sumaren(int dato[3][4])
{
 suma,i,j;     real


Print "Suma de renglones: ";


for(i=0;to 3 step;i++)
{
suma = 0
for(j=0;to 4 step;j++)
{




suma = suma+dato[i][j]
}
Print "La suma del renglon: ",(i+1)," es: ",suma;
} }




void sumacol(int dato[3][4])
{
 suma,i,j;     real


Print "Suma de columnas: ";


for(j=0;to 4 step;j++)
{
suma = 0;
for(i=0;to 3 step;i++)
{
suma = suma+dato[i][j]
}
Print "La suma de las Columnas: ",(j+1)," es: ",suma;
} }




void imprimir(int dato[3][4])
{
 i,j;      real
ifstream entrada;
entrada.open("c://practica 9//prueba.txt");
for(i=0;to 3 step;i++)
{
for(j=0;to 4 step;j++)
{
entrada>>dato[i][j];
Print dato[i][j]<<"    ";
}


}
entrada.close();


void main ()
{
 dato[3][4]      real
imprimir(dato)
sumaren(dato)
sumacol(dato)


Fin













Problema 10


1.- Inicio



ofstream  f1;
f1.open("c://datos//grupos.txt");
f1,5;
f1,96;
f187;
f1,28;
f1,13;
f1,21;
f1,4;
f1,92;
f1,82;
f1,85;
f1,87;
f1,6;
f1,72;
f1,69;
f1,85;
f1,75;
f1,81;
f1,73;


f1.close();
Print "grupos almacenados";


 i;      Real
ifstream  f2;
f2.open("c://datos//grupos.txt");
 n,suma=0,numero;    Real

f2,n;
for(int j=1;j<=n;j++)
{
f2,numero;
suma = suma + numero;
}
 prom=suma/n;    Real
Print "El promedio del grupo",i,":",prom;
f2.close();

Fin






Problema 11


1.- Inicio



fstream archivo;

archivo.open("c://datos//voltios.txt",ios::out);
archivo,"120.3  122.7  90.3   99.8";
archivo,"95.3   120.5  127.3  120.8";
archivo,"123.2  118.4  123.8  116.6";
archivo,"122.4  95.1   118.2  120.0";
archivo,"123.5  130.2  123.9  124.4";
archivo.close();
Print "archivo voltios almacenadatos";

Fin



fstream arch;
 suma,num,prom;   Float
arch.open("c://datos//voltios.txt",ios::out);
for(int i=1; to 5 step;i++)
{

for(int j=1; to 4 step; j++)
{
arch,num;
suma = suma+num;
}
prom = suma/4;
Print "el promedio del registro",i,": ",prom;
}
arch.close();

Fin