domingo, 11 de mayo de 2014

Sacar Cantidad en c++

#include<iostream.h>
#include<conio.h>
void main()
{
int CANT, B20, B10, B5, B1;
clrscr();
cout<<"Ingrese cantidad: ";cin>>CANT;
B20 = CANT/20;
CANT = CANT%20;
B10 = CANT/10;
CANT = CANT%10;
B5 = CANT/5;
B1 = CANT%5;
cout<<"Billetes de 20: "<<B20;
cout<<"Billetes de 10: "<<B10;
cout<<"Billetes de 5: "<<B5;
cout<<"Billetes de 1: "<<B1;
getch();
}




Invertir numero en c++

#include<iostream.h>
#include<conio.h>
void main()
{
int NUM, NUMINV, U, D, C, AUX;
clrscr();
cout<<"Ingrese número: ";cin>>NUM;
AUX = NUM;
C = NUM/100;
NUM = NUM%100;
D = NUM/10;
U = NUM%10;
NUMINV = U*100 + D*10 + C;
cout<<"El numero es A es: "<<AUX;
cout<<"El invertido: "<<NUMINV;
getch();
}

Contador un poco difícil en c++

#include<iostream.h>
#include<conio.h>
void main()
{
int A, B, C,D, E, AUX1, AUX2;
clrscr();
cout<<"Ingrese A: ";cin>>A;
cout<<"Ingrese B: ";cin>>B;
cout<<"Ingrese C: ";cin>>C;
cout<<"Ingrese D: ";cin>>D;
cout<<"Ingrese E: ";cin>>E;
AUX1 = A;
AUX2 = D;
A = C;
D = B;
B = E;
E = AUX1;
C = AUX2;
cout<<"El valor de A es: "<<A;
cout<<"El valor de B es: "<<B;
cout<<"El valor de C es: "<<C;
cout<<"El valor de D es: "<<D;
cout<<"El valor de E es: "<<E;
getch();
}

Contador en c++

#include<iostream.h>
#include<conio.h>
void main()
{
int A, B, C, AUX;
clrscr();
cout<<"Ingrese A: ";cin>>A;
cout<<"Ingrese B: ";cin>>B;
cout<<"Ingrese C: ";cin>>C;
AUX = A;
A = B;
B = C;
C = AUX;
cout<<"El valor de A es: "<<A;
cout<<"El valor de B es: "<<B;
cout<<"El valor de C es: "<<C;
getch();
}

El área de un cubo en c++

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
float L1, L2, L3, S, Area;
clrscr();
cout<<"Lado 1: ";cin>>L1;
cout<<"Lado 2: ";cin>>L2;
cout<<"Lado 3: ";cin>>L3;
S = (L1 + L2 + L3) / 2;
Area = pow(S*(S-L1)*(S-L2)*(S-L3),0.5);
cout<<"El area es: "<<Area;
getch();
}

Suma de vectores en Java

import java .io.*;
public class Sumavec
{
public static void main (String args[])
{
InputStreamReader s=new InputStreamReader (System.in);
BufferedReader va=new BufferedReader (s);

try 
{
int [] vec1;
vec1 = new int [10];
int [] vec2;
vec2 = new int [10];
int [] vecsum;
vecsum = new int [10];

System.out.println ("Dame diez numeros..");
for (int k=0; k<10; k++)
{
int n = Integer.parseInt (va.readLine());
vec1[k]= n;
}
System.out.println ("dame diez numeros");
for (int k=0; k<10; k++)
{
int n= Integer.parseInt (va.readLine());
vec2[k]= n;

for ( int k=0; k<10; k++)
{
vecsum[k] = vec1[k]+ vec2[k];
}
for (int k=0; k<10; k++)
{
System.out.println ("la suma de vector uno y vector dos es: "+vecsum[k]);

}//cierra try
catch (Exception e)
{
e.printStackTrace ();
}
}
}

Para sacar distancia y velocidad en c++

#include<iostream.h>
#include<conio.h>
void main()
{
int MIN, SEG, CEN;
float DIST, TIEMSEG, VELOKH;
clrscr();
cout<<"Min: ";cin>>MIN;
cout<<"SEG: ";cin>>SEG;
cout<<"CEN: ";cin>>CEN;
cout<<"Distancia: ";cin>>DIST;
VELOKH = (DIST/(MIN*60+SEG+CEN/100))*3.6;
cout<<"Distancia: "<<DIST/1000<<" km";
cout<<"Velocidad: "<<VELOKH<<" (K/H)";
getch();
}





Hallar el área,altura,radio,volumen de una circunferencia en c++

#include<iostream.h>
#include<conio.h>
#include<math.h>
#define PI 3.1416
void main()
{

float RADIO, ALTU, Area, Vol;
clrscr();
cout<<"Ingrese Radio: ";cin>>RADIO;
cout<<"Ingrese Altura: ";cin>>ALTU;
Area = 2 * PI * RADIO * ALTU;
Vol = PI * pow(RADIO,2) * ALTU;
cout<<"El area es: "<<Area;
cout<<"El volumen es: "<<Vol;
getch();
}

Convertidor de dolares a soles peruanos en c++

#include<iostream.h>
#include<conio.h>
void main()
{
float CANT;
clrscr();

cout<<"Ingrese cantidad $: ";cin>>CANT;
CANT = CANT * 3.25;
cout<<"Cambio en Soles : "<<CANT;
getch();
}

Sacar peso,longitud en c++

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
char NOM[50];
float PES, LON;
clrscr();

cout<<"Ingrese nombre del dinosaurio: ";cin>>NOM;
cout<<"Ingrese su peso en libras: ";cin>>PES;
cout<<"Ingrese su longitus en pies: ";cin>>LON;
PES = PES * 0.4535924;
LON = LON * 0.3048006;
cout<<"El Dinosaurio es : "<<NOM;
cout<<"su peso en KG es : "<<PES;
cout<<"Su lngituda en metros es : "<<LON;
getch();
}

Para sacar nota a nivel simple en c++

#include<iostream.h>
#include<conio.h>

void main()
{
float NOTA;
clrscr();
cout<<"Ingrese su nota por favor| ";
cin>>NOTA;
if(NOTA>=0 & NOTA<=10)
{
if(NOTA==10)
{cout<<"Matricula de honor";}
if(NOTA>=8.5 & NOTA<10)
{cout<<"Sobresaliente";}
if(NOTA>=6.5 & NOTA<8.5)
{cout<<"Notable";}
if(NOTA>=5 & NOTA<6.5)
{cout<<"Aprobado";}
if(NOTA>=0 & NOTA<5)
{cout<<"Suspenso";}
}
else
{cout<<"Nota invalida";}
getch();
}

Para sacar el Radio,área de una circunferencia en c++

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
float R,A,PI;
PI=3.1416;
clrscr();
cout<<"Ingrese radio: ";cin>>R;
A = PI * pow(R,2);
cout<<"El área es: "<<A;
getch();
}

Para sacar altura,base,perímetro y superficie de un Rectángulo

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
float B, A, PER, SUP;
clrscr();
cout<<"Ingrese altura del rectangulo: ";cin>>A;
cout<<"Ingrese base del rectangulo: ";cin>>B;
PER = (B + A) * 2;
SUP = B * A;
cout<<"El perímetro es: "<<PER;
cout<<"La superficie es: "<<SUP;
getch();
}

Arreglos con ejemplo de caracteres en c++

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>

class Persona
{
private:
char Nombre[26];
char Apellido[26];
char Direccion[31];
char Telefono[8];

public:
Persona();
Persona(char n[], char *a, char *d, char *t);
void Leer();
void Imprimir();
};

class Estudiante : public Persona
{
private:
char Univ[20];
char Espe[20];

public:
Estudiante();
void Leer();
void ImprimirDatos();
};

Estudiante::Estudiante(): Persona("X","Y","Z","Z")
{
Univ[0]=0;
Espe[0]=0;
}
void Estudiante::Leer()
{
Persona::Leer();
cout<<"Universidad: ";gets(Univ);
cout<<"Especialidad: ";gets(Espe);
}
void Estudiante::ImprimirDatos()
{
Imprimir();
cout<<"\nUniversidad : "<<Univ;
cout<<"\nEspecialidad: "<<Espe;
}
Persona::Persona()
{
Nombre[0]=0;
Apellido[0]=0;
Direccion[0]=0;
Telefono[0]=0;
cout<<"Por defecto se inicializa los arrays " <<endl;
};
Persona::Persona(char n[], char *a, char *d, char *t)
{
strcpy(Nombre,n);
strcpy(Apellido,a);
strcpy(Direccion,d);
strcpy(Telefono,t);

};
void Persona::Leer()
{
cout<<"DATOS DE LA PERSONA "<<endl;
cout<<"Nombre: ";
gets(Nombre);
cout<<"Apellidos: ";
gets(Apellido);
cout<<"Direccion: ";
gets(Direccion);
cout<<"Telefono: ";
gets(Telefono);
};
void Persona::Imprimir()
{
cout<<"\nREPORTE DE PERSONA :";
cout<<"\nNombre : "<<Nombre ;
cout<<"\nApellido : "<<Apellido ;
cout<<"\nDireccion: "<<Direccion ;
cout<<"\nTelefono : "<<Telefono ;
};

int main()
{
Estudiante Individuo[10];
int n;
int i;
getch();
clrscr();
cout<<"¨Cuantos datos a evaluar ? ==> ";
cin>>n;
for(i=0;i<n;i++)
Individuo[i].Leer();
getch();
clrscr();
for(i=0;i<n;i++)
Individuo[i].ImprimirDatos();
getch();
return 0;
}






Para sacar los números imaginarios en c++

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define PI 3.141592653

class Complejo
{
float r;
float i;
public:
Complejo ();
Complejo (float Real, float Imaginario);
Complejo operator + (Complejo C);
Complejo operator - (Complejo C);
Complejo operator * (Complejo C);
Complejo operator / (Complejo C);
float operator ! ();
float operator & ();
Complejo Conju(Complejo C);
void Leer();
void Escribir();
};
Complejo::Complejo()
{
r=0;
i=0;
}
Complejo::Complejo(float Real, float Imaginario)
{
r=Real;
i=Imaginario;
}
Complejo Complejo::operator + (Complejo C)
{
Complejo Z;
Z.r=r + C.r;
Z.i=i + C.i;
return Z;
}
Complejo Complejo::operator - (Complejo C)
{
Complejo Z;
Z.r=r - C.r;
Z.i=i - C.i;
return Z;
}
Complejo Complejo::operator * (Complejo C)
{
Complejo Z;
Z.r=r*C.r - i*C.i;
Z.i=r*C.i + i*C.r;
return Z;
}
Complejo Complejo::operator / (Complejo C)
{
Complejo Z;
float Denom = C.r*C.r + C.i*C.i;
Z.r=(r*C.r + i*C.i)/Denom;
Z.i=(-r*C.i + i*C.r)/Denom;
return Z;
}
float Complejo::operator ! ()
{
return sqrt(r*r + i*i);
}
float Complejo::operator & ()
{
float c,ang;
c = (180/PI)*atan(i/r);
if (i>0 && r>0) ang = c;
if (i>0 && r<0) ang = 180+c;
if (i<0 && r<0) ang = 180+c;
if (i<0 && r>0) ang = 360+c;
return ang;
}
Complejo Complejo::Conju(Complejo C)
{
C.r = C.r;
C.i = -C.i;
return C;
}
void Complejo::Leer()
{
cout<<"\nNumero Complejo = ";
cin>>r; cin>>i;
}
void Complejo::Escribir()
{
cout<<r <<" + " <<i <<"i";
}
void main()
{
clrscr();
Complejo A,B,C,D,E,F,AA,O;
float f,h;
A.Leer();
cout<<"Complejo A = ";
A.Escribir();
B.Leer();
cout<<"Complejo B = ";
B.Escribir();
C = A + B;
cout<<"\n\nC = A + B = ";
C.Escribir();
D = A - B;
cout<<"\nD = A - B = ";
D.Escribir();
E = A * B;
cout<<"\nD = A * B = ";
E.Escribir();
F = A / B;
cout<<"\nD = A / B = ";
F.Escribir();
f = !A;
cout<<"\n\nModulo de A = " <<f;
h = &A;
cout<<"\nAngulo de A = " <<h;
AA = O.Conju(B);
cout<<"\nConjugada de A = ";
AA.Escribir();
getch();
}

Para que saque la fecha en c++

#include<iostream.h>
#include<conio.h>
#include<math.h>

void main()
{

int amo, A, B, C, D, E, N, M;
clrscr();
cout<<"Ingrese el amo: ";
cin>>amo;
A = amo % 19;
B = amo % 4;
C = amo % 7;
D = ( 19*A + 24 ) % 30;
E = ( 2*B + 4*C + 6*D + 5 ) % 7;
N = ( 22 + D + E );
M = N - 31;
if(N>31)
{cout<<"el domingo de pascua es el "<<M<<" de Abril";}
else
{cout<<"el domingo de pascua es el "<<N<<" de Marzo";}
getch();
}

Numero mayor en c++

#include<stdio.h>
#include<conio.h>

void main()
{
int A,B,C,mayor;
clrscr();
printf("Ingrese tres numeros enteros| ");
scanf("%d %d %d",&A,&B,&C);
if(A>B)
 if(A>C)
 mayor = A;
 else
 mayor = C;
else if(B>C)
mayor = B;
 else
 mayor = C;
printf("El mayor es %.d",mayor);
getch();
}