Códigos Programacion C++
Códigos Programacion C++
Códigos Programacion C++
#include<iostream>//
//cout= imprimir
//cin = leer
{//inicio
cout<<"Digite un #"<<endl;
cin>>n1;
cout<<"Digite un #"<<endl;
cin>>n2;
nf=n1+n2;
system("pause");
}//fin
//datos de entrada double= n1, n2, n3, nf (double se utiliza para decimales)
#include<iostream>//
int main ()
cin>>n1;
cin>>n2;
cin>>n3;
nf=((n1*0.30)+(n2*0.30)+(n1*0.40));
system("pause");
}//fin
Si en el anterior caso piden nombre y programa asociado al estudiante se usa Char (solo se utiliza
para textos)
Código para sacar promedio de una persona de 6 materias diferntes (datos básicos+promedio
por materia + promedio final)
//nom-apelli-direccion-telefono-correo -int
//asignaturas( introduccion -logica) vistas en un modulo, teniendo en cuenta los tres cortes (30%-
30%-40%)/ promedio = double
{// inicio
//----------------------------------------------------------------------------------------------------
char apell[10];
char dire[10];
char correo[10];
char asig1[10];
char asig2[10];
char asig3[10];
char asig4[10];
char asig5[10];
char asig6[10];
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
cin>>nom;
//-----------------------------------------------------------------------------------------------------
cin>>apell;
//-----------------------------------------------------------------------------------------------------
cin>>dire;
//-----------------------------------------------------------------------------------------------------
cin>>tele;
//-----------------------------------------------------------------------------------------------------
cin>>correo;
//-----------------------------------------------------------------------------------------------------
cout<<"***********Materias vistas***********"<<endl;
//-----------------------------------------------------------------------------------------------------
cin>>asig1;
//-----------------------------------------------------------------------------------------------------
cin>>asig2;
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
cin>>asig4;
//-----------------------------------------------------------------------------------------------------
cin>>asig5;
//-----------------------------------------------------------------------------------------------------
cin>>asig6;
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
cin>>a1;
//-----------------------------------------------------------------------------------------------------
cin>>a2;
//-----------------------------------------------------------------------------------------------------
cin>>a3;
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
cin>>b1;
//-----------------------------------------------------------------------------------------------------
cin>>b2;
//-----------------------------------------------------------------------------------------------------
cin>>b3;
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
cin>>c1;
//-----------------------------------------------------------------------------------------------------
cin>>c2;
//-----------------------------------------------------------------------------------------------------
cin>>c3;
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
cin>>d1;
//-----------------------------------------------------------------------------------------------------
cin>>d2;
//-----------------------------------------------------------------------------------------------------
cin>>d3;
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
cin>>e2;
//-----------------------------------------------------------------------------------------------------
cin>>e3;
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
cin>>f1;
//-----------------------------------------------------------------------------------------------------
cin>>f2;
//-----------------------------------------------------------------------------------------------------
cin>>f3;
//-----------------------------------------------------------------------------------------------------
af=((a1*.30)+(a2*.30)+(a3*.40));
bf=((b1*.30)+(b2*.30)+(b3*.40));
cf=((c1*.30)+(c2*.30)+(c3*.40));
df=((d1*.30)+(d2*.30)+(d3*.40));
ef=((e1*.30)+(e2*.30)+(e3*.40));
ff=((f1*.30)+(f2*.30)+(f3*.40));
promedio=((af)+(bf)+(cf)+(df)+(ef)+(ff))/6;
//---------------------------------------------------------------------------
system("pause");
}//fin
________________________________________________________________________________
____________________________________
Explicación de códigos
IF (condicionales)
#include<iostream>
int main ()
cin>>edad;
if (edad>=18)
//Inicio-----------------------------------------
// fin-----------------------------------
system("pause");
}//fin
#include<iostream>
int main ()
{
int num;
//----------------------------------------
cin>>num;
//----------------------------------------
if(num> 0)
//---------------------------------------
if(num< 0)
//---------------------------------------
if(num==0)
//---------------------------------------
system("pause");
}//fin
Sentencia switch