jueves, 14 de mayo de 2015

EJERCICIOS 01



EJERCICIOS 01
1)     Hacer un programa para que se ingresen 2 números y reporte su suma, resta y multiplicación.

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------

void __fastcall TForm1::SALIRClick(TObject *Sender)
{
Close ();
}
//--------------------------------------------------------------------

void __fastcall TForm1::CALCULARClick(TObject *Sender)
{
float A,B,s,r,m;
A= edA->Text.ToDouble();
B= edB->Text.ToDouble();
s=A+B;
r=A-B;
m=A*B;
edSuma->Text=s;
edResta->Text=r;
edMultiplicacion->Text=m;

}
//--------------------------------------------------------------------

void __fastcall TForm1::LIMPIARClick(TObject *Sender)
{
edA->Clear();
edB->Clear();
edSuma->Clear();
edResta->Clear();
edMultiplicacion->Clear();
edA->SetFocus();

}

2)     Calcular la altura que cae un objeto. Se debe ingresar el tiempo recorrido en segundos.
(H = 0.5 * G * T 2 .   G = 9.8 m/seg2)


#include <vcl.h>
#pragma hdrstop
#include <math.h>
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//--------------------------------------------------------------------

void __fastcall TForm1::btnCalcularClick(TObject *Sender)
{

//(H = 0.5 * G * T 2 .   G = 9.8 m/seg2)

Double tiempo,h;
const float G=9.81;
tiempo=edTiempo->Text.ToDouble();
h=0.5*G*pow(tiempo,2);
edAltura->Text=h;

}
//--------------------------------------------------------------------


void __fastcall TForm1::btnNuevoClick(TObject *Sender)
{
edTiempo->Clear();
edAltura->Clear();
edTiempo->SetFocus();

}
//--------------------------------------------------------------------void __fastcall TForm1::btnSalirClick(TObject *Sender)
{
Close();
}
     3)     La gaseosa en la planta embotelladora se almacena en tanques cilíndricos de un radio de 2 metros. Se necesita un programa que ingresando la altura hasta la que llega la gaseosa, calcule el volumen que se tiene (Volumen del cilindro = Pi * radio2* altura)
#include <vcl.h>
#pragma hdrstop
#include <math.h>

#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 Double altura,v;
 const float pi=3.1416;
 const float radio=2;
altura = edAltura->Text.ToDouble();
 v=pi*pow(radio,2)*altura;
 edVolumen->Text= v;

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
edAltura->Clear();
edVolumen->Clear();
edAltura->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Close();       
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{

}
  
    4)  La distancia entre dos puntos (x1, y1) y (x2, y2) de un plano se puede obtener sacando la raíz cuadrada de la expresión (x2 – x1)2 + (y2 – y1)2. Escribir un programa que dados dos puntos por el usuario, calcule la distancia entre estos dos puntos.
#include <vcl.h>
#pragma hdrstop
#include <math.h>
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//--------------------------------------------------------------------

void __fastcall TForm1::CLOSEClick(TObject *Sender)
{
Close();
}
//--------------------------------------------------------------------

void __fastcall TForm1::LIMPIARClick(TObject *Sender)
{
edX1->Clear();
edY1->Clear();
edX2->Clear();
edY2->Clear();
edDistancia->Clear();
edX1->SetFocus();

}
//--------------------------------------------------------------------

void __fastcall TForm1::CALCULARClick(TObject *Sender)
{
int X1,Y1,X2,Y2;  //declarando variables
float d;
X1=edX1->Text.ToInt();
Y1=edY1->Text.ToInt();
X2=edX2->Text.ToInt();
Y2=edY2->Text.ToInt();
d=(sqrt(pow(X2-X1,2))+(pow(Y2-Y1,2)));
edDistancia->Text=d;
}
//--------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{

}

    5) Calcular el interés generado por un capital depositado durante cierta cantidad de períodos a una tasa de interés determinada y expresada en porcentaje.

Aplicar la siguientes fórmulas:
                
Monto = Capital*(1 + tasa/100)NumeroPeríodos
Interés = Monto – Capital

#include <vcl.h>
#pragma hdrstop
#include <math.h>
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
Tcapital *capital;
//---------------------------------------------------------------------------
__fastcall Tcapital::Tcapital(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall Tcapital::SALIRClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall Tcapital::LIMPIARClick(TObject *Sender)
{
edCapital->Clear();
edTasa->Clear();
edPeriodo->Clear();
edInteres->Clear();
edCapital->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall Tcapital::CALCULARClick(TObject *Sender)
{
float periodo,tasa,capital,interes,monto;
capital=edCapital->Text.ToDouble();
tasa=edTasa->Text.ToDouble();
periodo=edPeriodo->Text.ToDouble();
monto=pow((1+tasa/100),periodo)*capital;
interes=monto-capital;
edInteres->Text=interes;

}
//---------------------------------------------------------------------------
void __fastcall Tcapital::FormCreate(TObject *Sender)
{

}

     6)  En una tienda han puesto en oferta la venta de todos sus artículos por cambio de estación ofreciendo un "15 % + 15 %" de descuento. El primer 15% se aplica al importe de la compra, mientras que el segundo 15% se aplica al importe que resulta de restar el importe de la compra menos el primer descuento. Dada la cantidad de unidades adquiridas de un mismo tipo de artículo por parte de un cliente y el precio unitario del artículo, diseñe un algoritmo que determine el importe de la compra, el importe del descuento y el importe a pagar

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
edCodigo->Clear();
edCantidad->Clear();
edPrecioUnitario->Clear();
edImporte->Clear();
edDescuento->Clear();
edTotalPagar->Clear();
edCodigo->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
float cant,punit,i,pd,sd,it,impor;
cant=edCantidad->Text.ToDouble();
punit=edPrecioUnitario->Text.ToDouble();
i=cant*punit;
edImporte->Text=i;
pd=i*15/100;
sd=(i-pd)*15/100;
impor=i-(pd+sd);
edDescuento->Text=pd+sd;
edTotalPagar->Text=impor;
//edTotalPagar("%impor.2f",float);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{

}

     7)  Una empresa paga a sus vendedores un sueldo básico mensual de S/.300. El sueldo bruto es igual al sueldo básico más una comisión, que es igual al 9% del monto total vendido. Por ley, todo vendedor se somete a un descuento del 11 %. Diseñe un programa que calcule la comisión, el sueldo bruto, el descuento y el sueldo neto de un vendedor de la empresa. Se debe ingresar el monto total vendido.

#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
edVendedor->Clear();
edMontoVendido->Clear();
edComision->Clear();
edSueldoBruto->Clear();
edDescuento->Clear();
edSueldoNeto->Clear();
edVendedor->SetFocus();

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
const float sbasico=300,comision=0.09,descuento=0.11;
float sbruto,sneto,mvendido,c,d;
mvendido=edMontoVendido->Text.ToDouble();
c=mvendido*comision;
edComision->Text=c;
sbruto=sbasico+c;
edSueldoBruto->Text=sbruto;
d=sbruto*descuento;
edDescuento->Text=d;
sneto=sbruto-d;
edSueldoNeto->Text=sneto;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{

}

    8) Ingrese un número que represente segundos y determinar a cuanto equivale en horas, minutos y segundos.
Ejemplo: Si se ingresa 9500 segundos el programa debería reportar: 2 horas, 38 minutos y 20 segundos.

#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();       
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
edCs->Clear();
edH->Clear();
edM->Clear();
edS->Clear();
edCs->SetFocus();

}
//---------------------------------------------------------------------------

void __fastcall TForm1::CALCULARClick(TObject *Sender)
{
int cs,h,m,s;
cs=edCs->Text.ToInt();
h=cs/3600;
cs=cs%3600;
m=cs/60;
s=cs%60;
edH->Text=h;
edM->Text=m;
edS->Text=s;

}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{

}
 9) Dada una cantidad de dinero en soles, diseñe un programa que descomponga dicha cantidad en billetes de S/. 100, S/. 50, S/.10 y monedas de S/. 5, S/. 2 y S/.1. Así, por ejemplo, S/. 3778 puede descomponerse en 37 billetes de S/. 100, mas 1 billete de S/. 50, mas 2 billetes de S/. 10, mas 1 moneda de S/. 5, mas 1 moneda de S/.2 y más 1 moneda de S/. 1.
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
edMonto->Clear();
edMont100->Clear();
edMont50->Clear();
edMont10->Clear();
edMont5->Clear();
edMont2->Clear();
edMont1->Clear();
edMonto->SetFocus();

}
//---------------------------------------------------------------------------

void __fastcall TForm1::CALCULARClick(TObject *Sender)
{
int monto,cant100,cant50,cant10,cant5,cant2,cant1;

monto=edMonto->Text.ToInt();
cant100=monto/100;
cant50=monto%100/50;
cant10=monto%100%50/10;
cant5=monto%100%50%10/5;
cant2=monto%100%50%10%5/2;
cant1=monto%100%50%10%5%2/1;

edMont100->Text=cant100;
edMont50->Text=cant50;
edMont10->Text=cant10;
 edMont5->Text=cant5;
 edMont2->Text=cant2;
 edMont1->Text=cant1;

}
10)  Dado un número natural de cuatro cifras, diseñe un algoritmo que forme un número con la cifra de los millares y la cifra de las unidades, en ese orden. Así, por ejemplo, si se ingresara el número 8235, el número formado sería 85

#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
Close();       
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
edNumero->Clear();
edNformado->Clear();
edNumero->SetFocus();

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int m,c,d,u,n,nf;
n=edNumero->Text.ToInt();
m=n/1000;
c=n%1000/100;
d=n%1000%100/10;
u=n%1000%100%10;
nf=(m*10)+u;
edNformado->Text=nf;

}
11)  Dado un número natural de tres cifras, diseñe un algoritmo que permita obtener el revés del número. Así, si se ingresa el número 238 el revés del número es 832.


#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------



void __fastcall TForm1::CALCULARClick(TObject *Sender)
{
int n,ni,r;
n=edNumero->Text.ToInt();
//primer proceso
r=n%10;
n=n/10;
ni=r*10;
// segundo proceso
r=n%10;
n=n/10;
ni=(ni+r)*10;
ni=ni+n;
edNinvertido->Text=ni;

       
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SALIRClick(TObject *Sender)
{
Close();       
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LIMPIARClick(TObject *Sender)
{
edNumero->Clear();
edNinvertido->Clear();
edNumero->SetFocus();

}
12)   Dada una hora del día en el formato HH:MM:SS, diseñe un algoritmo que determine la hora del día luego de 200 segundos transcurridos. Por ejemplo, si la hora actual del día es 17:30:50, la hora de día luego de 200 segundos será 17:34:10.                                                                                     

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
int cs,h,m,s,ha,ma,sa;
const smas=200;
ha=edHa->Text.ToInt();
ma=edMa->Text.ToInt();
sa=edSa->Text.ToInt();
ha=ha*60*60;
ma=ma*60;
cs=ha+ma+sa+smas;
h=cs/3600;
cs=cs%3600;
m=cs/60;
s=cs%60;
edHd->Text=h;
edMd->Text=m;
edSd->Text=s;

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
Close();       
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
edHa->Clear();
edMa->Clear();
edSa->Clear();
edHd->Clear();
edMd->Clear();
edSd->Clear();
edHa->SetFocus();

}

13)   Diseñe un algoritmo que determine la duración de un viaje en el formato HH:MM:SS conociendo la horas de partida y de llegada, ambas en el formato HH:MM:SS.


#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
edHp->Clear();
edMp->Clear();
edSp->Clear();
edHl->Clear();
edMl->Clear();
edSl->Clear();
edHt->Clear();
edMt->Clear();
edSt->Clear();
edHp->SetFocus();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
int csp,csl,hp,mp,sp,hl,ml,sl;
int tiempo,hora,minutos,segundos;
hp=edHp->Text.ToInt();
mp=edMp->Text.ToInt();
sp=edSp->Text.ToInt();
hl=edHl->Text.ToInt();
ml=edMl->Text.ToInt();
sl=edSl->Text.ToInt();
hp=hp*60*60;
mp=mp*60;
csp=hp+mp+sp;
hl=hl*60*60;
ml=ml*60;
csl=hl+ml+sl;
tiempo=csl-csp;

hora=tiempo/3600;
tiempo=tiempo%3600;
minutos=tiempo/60;
segundos=tiempo%60;
edHt->Text=hora;
edMt->Text=minutos;
edSt->Text=segundos;


}

1 comentario: