<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV>He visto gente iniciada en C++ nueva en la lista de correo; incluyo este
programa sencillo (es mi primer programa y tendrá mil maneras de mejorarlo) pero
puede valer para que vean a través de ejemplos como he logrado lo que el
programa básicamente hace.</DIV>
<DIV> </DIV>
<DIV>Estableces un sueldo, conceptos de gastos (ejemplo : coche, luz, comida
etc) y luego estableces los valores de gastos de cada cosa, luego a través del
menú te ofrece un mini informe.</DIV>
<DIV> </DIV>
<DIV>Espero lo disfruten, se aceptan sugerencias.</DIV>
<DIV> </DIV>
<DIV>un saludo.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<META name=GENERATOR content="LibreOffice 3.4 (Win32)">
<META name=CREATED content=20111024;9105492>
<META name=CHANGED content=20111024;9124326>
<STYLE type=text/css>
<!--
@page { margin: 2cm }
p { margin-bottom: 0.21cm }
-->
</STYLE>
<DIV><FONT face="Courier New">#include <iostream></FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">using namespace std;</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">class gastos</FONT></DIV>
<DIV><FONT face="Courier New">{</FONT></DIV>
<DIV><FONT face="Courier New"> private:</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> int sueldo;</FONT></DIV>
<DIV><FONT face="Courier New"> int vgastos;</FONT></DIV>
<DIV><FONT face="Courier New"> int ng;</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> struct gasto {</FONT></DIV>
<DIV><FONT face="Courier New"> char
concepto[50];</FONT></DIV>
<DIV><FONT face="Courier New"> int
valor;</FONT></DIV>
<DIV><FONT face="Courier New"> };</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> public:</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> gasto
losgastos[9];</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> void menu();</FONT></DIV>
<DIV><FONT face="Courier New"> void
establecerg();</FONT></DIV>
<DIV><FONT face="Courier New"> void
establecervg();</FONT></DIV>
<DIV><FONT face="Courier New"> void informe();</FONT></DIV>
<DIV><FONT face="Courier New"> void
establecesueldo(int);</FONT></DIV>
<DIV><FONT face="Courier New"> int sueldoacero();</FONT></DIV>
<DIV><FONT face="Courier New"> int gastosacero();</FONT></DIV>
<DIV><FONT face="Courier New">};</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">void gastos::menu()</FONT></DIV>
<DIV><FONT face="Courier New">{</FONT></DIV>
<DIV><FONT face="Courier New">char eleccion;</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">cout << "Elige la opci\xa2n :" <<
endl;</FONT></DIV>
<DIV><FONT face="Courier New">cout << "---------------------" <<
endl;</FONT></DIV>
<DIV><FONT face="Courier New">cout << "1.- Establecer sueldo." <<
endl;</FONT></DIV>
<DIV><FONT face="Courier New">cout << "2.- Establecer conceptos de
gastos." << endl;</FONT></DIV>
<DIV><FONT face="Courier New">cout << "3.- Establecer valores de gastos."
<< endl;</FONT></DIV>
<DIV><FONT face="Courier New">cout << "4.- Mostrar informe." <<
endl;</FONT></DIV>
<DIV><FONT face="Courier New">cout << "5.- Salir del programa." <<
endl;</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">cout << endl;</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">cin >> eleccion;</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> switch
(eleccion)</FONT></DIV>
<DIV><FONT
face="Courier New">
{</FONT></DIV>
<DIV><FONT
face="Courier New">
case '1':</FONT></DIV>
<DIV><FONT
face="Courier New">
int valor;</FONT></DIV>
<DIV><FONT
face="Courier New">
cout << "Introduce el valor del sueldo en euros : "; cin >> valor;
cout << endl;</FONT></DIV>
<DIV><FONT
face="Courier New">
establecesueldo(valor);</FONT></DIV>
<DIV><FONT
face="Courier New">
menu();</FONT></DIV>
<DIV><FONT
face="Courier New">
break;</FONT></DIV>
<DIV><FONT
face="Courier New">
case '2':</FONT></DIV>
<DIV><FONT
face="Courier New">
if(sueldo == 0)</FONT></DIV>
<DIV><FONT
face="Courier New">
{</FONT></DIV>
<DIV><FONT
face="Courier New">
cout << "Error, debes establecer un sueldo primero.\n";</FONT></DIV>
<DIV><FONT
face="Courier New">
menu();</FONT></DIV>
<DIV><FONT
face="Courier New">
break;</FONT></DIV>
<DIV><FONT
face="Courier New">
}</FONT></DIV>
<DIV><FONT
face="Courier New">
else</FONT></DIV>
<DIV><FONT
face="Courier New">
{</FONT></DIV>
<DIV><FONT
face="Courier New">
establecerg();</FONT></DIV>
<DIV><FONT
face="Courier New">
losgastos[0].valor = 1;</FONT></DIV>
<DIV><FONT
face="Courier New">
menu();</FONT></DIV>
<DIV><FONT
face="Courier New">
break;</FONT></DIV>
<DIV><FONT
face="Courier New">
}</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT
face="Courier New">
case '3':</FONT></DIV>
<DIV><FONT
face="Courier New">
if(losgastos[0].valor == 0)</FONT></DIV>
<DIV><FONT
face="Courier New">
{</FONT></DIV>
<DIV><FONT
face="Courier New">
cout << "Error, debes establecer un concepto de gastos
primero.\n";</FONT></DIV>
<DIV><FONT
face="Courier New">
cout << losgastos[0].valor << endl;</FONT></DIV>
<DIV><FONT
face="Courier New">
menu();</FONT></DIV>
<DIV><FONT
face="Courier New">
break;</FONT></DIV>
<DIV><FONT
face="Courier New">
}</FONT></DIV>
<DIV><FONT
face="Courier New">
else</FONT></DIV>
<DIV><FONT
face="Courier New">
{</FONT></DIV>
<DIV><FONT
face="Courier New">
establecervg();</FONT></DIV>
<DIV><FONT
face="Courier New">
menu();</FONT></DIV>
<DIV><FONT
face="Courier New">
break;</FONT></DIV>
<DIV><FONT
face="Courier New">
}</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT
face="Courier New">
case '4':</FONT></DIV>
<DIV><FONT
face="Courier New">
if(sueldo == 0)</FONT></DIV>
<DIV><FONT
face="Courier New">
{</FONT></DIV>
<DIV><FONT
face="Courier New">
if(losgastos[0].valor == 0)</FONT></DIV>
<DIV><FONT
face="Courier New">
{</FONT></DIV>
<DIV><FONT
face="Courier New">
cout << "Error, debes establecer un sueldo, conceptos y valores
primero.\n";</FONT></DIV>
<DIV><FONT
face="Courier New">
menu();</FONT></DIV>
<DIV><FONT
face="Courier New">
break;</FONT></DIV>
<DIV><FONT
face="Courier New">
}</FONT></DIV>
<DIV><FONT
face="Courier New">
}</FONT></DIV>
<DIV><FONT
face="Courier New">
else</FONT></DIV>
<DIV><FONT
face="Courier New">
{</FONT></DIV>
<DIV><FONT
face="Courier New">
if(losgastos[0].valor == 0 || losgastos[0].valor == 1)</FONT></DIV>
<DIV><FONT
face="Courier New">
{</FONT></DIV>
<DIV><FONT
face="Courier New">
cout << "Error, debes establecer un sueldo, conceptos y valores
primero.\n";</FONT></DIV>
<DIV><FONT
face="Courier New">
menu();</FONT></DIV>
<DIV><FONT
face="Courier New">
break;</FONT></DIV>
<DIV><FONT
face="Courier New">
}</FONT></DIV>
<DIV><FONT
face="Courier New">
informe();</FONT></DIV>
<DIV><FONT
face="Courier New">
menu();</FONT></DIV>
<DIV><FONT
face="Courier New">
break;</FONT></DIV>
<DIV><FONT
face="Courier New">
}</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT
face="Courier New">
case '5':</FONT></DIV>
<DIV><FONT
face="Courier New">
return;</FONT></DIV>
<DIV><FONT
face="Courier New">
default:</FONT></DIV>
<DIV><FONT
face="Courier New">
cout << "Escoge una opci\xa2n de las que ofrece el men\xa3..." <<
endl;</FONT></DIV>
<DIV><FONT
face="Courier New">
cout << endl;</FONT></DIV>
<DIV><FONT
face="Courier New">
menu();</FONT></DIV>
<DIV><FONT
face="Courier New">
break;</FONT></DIV>
<DIV><FONT
face="Courier New">
}</FONT></DIV>
<DIV><FONT face="Courier New">}</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">void gastos::establecesueldo(int a)</FONT></DIV>
<DIV><FONT face="Courier New">{</FONT></DIV>
<DIV><FONT face="Courier New"> sueldo = a;</FONT></DIV>
<DIV><FONT face="Courier New">}</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">void gastos::establecerg()</FONT></DIV>
<DIV><FONT face="Courier New">{</FONT></DIV>
<DIV><FONT face="Courier New"> cout << "\xa8" <<
"Cu\xa0ntos gastos quieres declarar? escoje un n\xa3mero del 1 al 10 : "; cin
>> ng;</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> if(ng <= 10)</FONT></DIV>
<DIV><FONT face="Courier New">
{</FONT></DIV>
<DIV><FONT
face="Courier New">
int i, j;</FONT></DIV>
<DIV><FONT
face="Courier New">
for(i = 0, j = 1; i < ng; i++, j++)</FONT></DIV>
<DIV><FONT
face="Courier New">
{</FONT></DIV>
<DIV><FONT
face="Courier New">
cout << "Establece un concepto de gasto (" << j << "/10) : ";
cin >> losgastos[i].concepto; cout << endl;</FONT></DIV>
<DIV><FONT
face="Courier New">
}</FONT></DIV>
<DIV><FONT face="Courier New">
}</FONT></DIV>
<DIV><FONT face="Courier New"> else</FONT></DIV>
<DIV><FONT face="Courier New"> {</FONT></DIV>
<DIV><FONT face="Courier New"> cout
<< "Error, debes introducir un numero del 1 al 10...\n";</FONT></DIV>
<DIV><FONT face="Courier New">
establecerg();</FONT></DIV>
<DIV><FONT face="Courier New"> }</FONT></DIV>
<DIV><FONT face="Courier New">}</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">void gastos::establecervg()</FONT></DIV>
<DIV><FONT face="Courier New">{</FONT></DIV>
<DIV><FONT face="Courier New"> int i;</FONT></DIV>
<DIV><FONT face="Courier New"> for(i = 0; i < ng;
i++)</FONT></DIV>
<DIV><FONT face="Courier New"> {</FONT></DIV>
<DIV><FONT face="Courier New"> cout
<< "Establece valor de gasto en euros para " <<
losgastos[i].concepto << " : "; cin >> losgastos[i].valor; cout
<< endl;</FONT></DIV>
<DIV><FONT face="Courier New"> }</FONT></DIV>
<DIV><FONT face="Courier New"> cout <<
endl;</FONT></DIV>
<DIV><FONT face="Courier New">}</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">void gastos::informe()</FONT></DIV>
<DIV><FONT face="Courier New">{</FONT></DIV>
<DIV><FONT face="Courier New"> cout << "Gastos de este
mes :" << endl;</FONT></DIV>
<DIV><FONT face="Courier New"> cout <<
"--------------------" << endl;</FONT></DIV>
<DIV><FONT face="Courier New"> cout <<
endl;</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> int i;</FONT></DIV>
<DIV><FONT face="Courier New"> for(i = 0; i < ng;
i++)</FONT></DIV>
<DIV><FONT face="Courier New"> {</FONT></DIV>
<DIV><FONT face="Courier New"> cout
<< losgastos[i].concepto; cout << " : "; cout <<
losgastos[i].valor; cout << endl;</FONT></DIV>
<DIV><FONT face="Courier New"> }</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> vgastos = 0;</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> for(i = 0; i < ng;
i++)</FONT></DIV>
<DIV><FONT face="Courier New"> {</FONT></DIV>
<DIV><FONT face="Courier New"> vgastos
+= losgastos[i].valor;</FONT></DIV>
<DIV><FONT face="Courier New"> }</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> cout <<
endl;</FONT></DIV>
<DIV><FONT face="Courier New"> cout << "Sueldo : "
<< sueldo << endl;</FONT></DIV>
<DIV><FONT face="Courier New"> cout << "Gastos : "
<< vgastos << endl;</FONT></DIV>
<DIV><FONT face="Courier New"> cout << "Te sobra : "
<< (sueldo - vgastos) << endl;</FONT></DIV>
<DIV><FONT face="Courier New"> cout <<
endl;</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">}</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">int gastos::sueldoacero()</FONT></DIV>
<DIV><FONT face="Courier New">{</FONT></DIV>
<DIV><FONT face="Courier New"> return sueldo = 0;</FONT></DIV>
<DIV><FONT face="Courier New"> losgastos[0].valor =
0;</FONT></DIV>
<DIV><FONT face="Courier New">}</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">int gastos::gastosacero()</FONT></DIV>
<DIV><FONT face="Courier New">{</FONT></DIV>
<DIV><FONT face="Courier New"> return losgastos[0].valor =
0;</FONT></DIV>
<DIV><FONT face="Courier New">}</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">int main()</FONT></DIV>
<DIV><FONT face="Courier New">{</FONT></DIV>
<DIV><FONT face="Courier New"> gastos
objetodeclase;</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">
objetodeclase.sueldoacero();</FONT></DIV>
<DIV><FONT face="Courier New">
objetodeclase.gastosacero();</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">
objetodeclase.menu();</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> return 0;</FONT></DIV>
<DIV><FONT face="Courier New">}</FONT></DIV>
<P style="MARGIN-BOTTOM: 0cm"><BR><FONT color=#548dd4><FONT
face="Arial, sans-serif"><FONT
size=2><I><B>Oscar</B></I></FONT></FONT></FONT><BR><FONT color=#e36c09><FONT
face="Tahoma, sans-serif"><FONT size=2>Administrador de sistemas
Linux.</FONT></FONT></FONT></P></DIV></DIV></DIV></BODY></HTML>