PDA

Ver la Versión Completa : Sumar los números asignados a una palabra


anonymous
28-05-2015, 22:01:21
Buenas .. Me pidieron un trabajo donde por medio de el click de un button Ingresando el usuario un Nombre y Apellido ( DIEGO ARMANDO MARADONA ) Cada letra tiene su valor ya la carge con un contador hize la suma de las palabras pero no puedo descomponerlas , es decir no se como hacer para sumar los numeros de cada palabra entre si ..

anonymous
28-05-2015, 22:06:12
ESTE ES MI CODIGO POR LAS DUDAS NO SE SI ESTA ALGO BIEN O MAL

unit JEBUS;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;

type
TForm3 = class(TForm)
BitBtn1: TBitBtn;
Edit1: TEdit;
Memo1: TMemo;
Label1: TLabel;
EdNom: TEdit;
Label2: TLabel;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.BitBtn1Click(Sender: TObject);
Var i, cant ,cant1,cont,cont1,suma,suma1,resultado,sumav,sumac: Integer;
nom, linea,linea1,linea2,linea3,linea4: string;
begin
Memo1.Visible:=true;
nom := EdNom.Text;
linea := '';
cant := 0;
for i:=1 to length(nom) do
if nom[i] in ['A','E','I','O','U','a','e','i','o','u'] then begin
linea := linea + nom[i] +' ';
cant := cant + 1;
end;
case nom [i] of
'A':cont:=1;
'E':cont:=5;
'I':cont:=9;
'O':cont:=6;
'U':cont:=3;
end;

Memo1.clear;
Memo1.Lines.add('Su nombre contiene las vocales');
Memo1.Lines.Add(linea);
Memo1.Lines.Add('Total de vocales= '+ IntToStr(Cant));

linea := '';
cont1:= 0;
for i := 1 to length (nom) do
if nom [i] in ['B','C','D','F','G','H','J','K','L','M','Ñ','O','P','Q','R','S','T','V','W','X','Y','Z','b','c','d', 'f','g','h','j','k','l','m','n','ñ','p','q','r','s','t','v','w','x','y','z'] then
begin
linea1 := linea1 + nom[i] +' ';
cant1 := cant1 + 1;
case nom [i] of
'J','S':cont1:= 1;
'B','K','T':cont1:= 2;
'C','L':cont1:=3;
'D','M','V':cont1:= 4;
'N','W':cont1:=5;
'F','X':cont1:=6;
'G','P','Y':cont1:=7;
'H','Q','Z':cont1:=8;
'R':cont1:=9;
end;
end;
linea4:=linea4+inttostr(cont)+' ';
linea3:=linea3+nom[i]+' ';
cant1:=cant1+1;

Memo1.Lines.add('-------------------------------- ');
Memo1.Lines.add('Cantidad de Consonantes');
Memo1.Lines.Add(linea1);
Memo1.Lines.Add('Total de Consonantes= '+ IntToStr(Cant1));

linea := '';
cant := 0;
for i:=1 to length(nom) do
begin
if nom[i] in ['A','E','I','O','U','a','e','i','o','u'] then
begin
linea := linea + nom[i] +' ';
cant := cant + 1;


begin

if nom [i] in ['A'] then
sumav:=sumav+1;
if nom [i] in ['E'] then
sumav:=sumav+5;
if nom [i] in ['I'] then
sumav:=sumav+9;
if nom [i] in ['O'] then
sumav:=sumav+6;
if nom [i] in ['U'] then
sumav:=sumav+3;


end;
end;
end;


Memo1.Lines.add('-------------------------------- ');
Memo1.Lines.Add('ESENCIA (lo que usted Quiere)');
Memo1.Lines.Add(linea);
Memo1.Lines.Add(inttostr(sumav));

Memo1.Lines.add('-------------------------------- ');
Memo1.Lines.Add('IMAGEN (como lo ven los demas)');
Memo1.Lines.Add(linea);
Memo1.Lines.Add(inttostr(cont1));

end;

end.

nlsgarcia
28-05-2015, 22:16:58
anonymous,

¡Bienvenido al Club Delphi! :D

Nelson

anonymous
28-05-2015, 22:48:26
anonymous,

¡Bienvenido al Club Delphi! :D

Nelson

GRACIASSS !

aposi
29-05-2015, 11:50:34
Hola,
vamos a centrarnos en el primer for:

tu tienes


Memo1.Visible:=true;
nom := EdNom.Text;
linea := '';
cant := 0;
for i:=1 to length(nom) do begin // te falta el begin, sin el el case solo se ejecuta una vez
if nom[i] in ['A','E','I','O','U','a','e','i','o','u'] then begin
linea := linea + nom[i] +' ';
cant := cant + 1;
end;
case uppercase(nom[i]) of // Con el uppecase conviertes la letra a mayusculas y el case actua tanto en maysculas y minusculas
'A':cont:=1;
'E':cont:=5;
'I':cont:=9;
'O':cont:=6;
'U':cont:=3;
end;
end; // End del for
Memo1.clear;
Memo1.Lines.add('Su nombre contiene las vocales');
Memo1.Lines.Add(linea);
Memo1.Lines.Add('Total de vocales= '+ IntToStr(Cant));


A partir de aqui mira que es lo que te falla

anonymous
04-06-2015, 21:21:56
BUENAS TENGO UN PROBLEMITA ME QUEDE ATASCADO EN DONDE DICE : Imagen ( Como lo ven los demas ) 3188
No se como descomponer los numeros para hacer la suma no se si me entienden ... 3189
CADA LETRA VALE UN NUMERO .. PERO A LA HORA DE DESMENUZAR LAS LETRAS NO SE HACER LA SUMA
este es mi codigo :
unit JEBUS;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;

type
TForm3 = class(TForm)
BitBtn1: TBitBtn;
Edit1: TEdit;
Memo1: TMemo;
Label1: TLabel;
EdNom: TEdit;
Label2: TLabel;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;

implementation

{$R *.dfm}




procedure TForm3.BitBtn1Click(Sender: TObject);
Var i, cant ,cant1,cont,cont1,suma,suma1,resultado,sumav,sumac,p,sumatotal,dig:Integer;
nom, linea,linea1,linea2,linea3,linea4: string;
begin
Memo1.Visible:=true;
nom := EdNom.Text;
linea := '';
cant := 0;
for i:=1 to length(nom) do
if nom[i] in ['A','E','I','O','U','a','e','i','o','u'] then begin
linea := linea + nom[i] +' ';
cant := cant + 1;
end;


Memo1.clear;
Memo1.Lines.add('Su nombre contiene las vocales');
Memo1.Lines.Add(linea);
Memo1.Lines.Add('Total de vocales= '+ IntToStr(Cant));

linea := '';
cont1:= 0;
for i := 1 to length (nom) do
if nom [i] in ['B','C','D','F','G','H','J','K','L','M','Ñ','P','Q','R','S','T','V','W','X','Y','Z','b','c','d','f', 'g','h','j','k','l','m','n','ñ','p','q','r','s','t','v','w','x','y','z'] then
begin
linea1 := linea1 + nom[i] +' ';
cant1 := cant1 + 1;
end;

Memo1.Lines.add('-------------------------------- ');
Memo1.Lines.add('Cantidad de Consonantes');
Memo1.Lines.Add(linea1);
Memo1.Lines.Add('Total de Consonantes= '+ IntToStr(Cant1));

linea := '';
cant := 0;
for i:=1 to length(nom) do
begin
if nom[i] in ['A','E','I','O','U','a','e','i','o','u'] then
begin
linea := linea + nom[i] +' ';
cant := cant + 1;

if nom [i] in ['A'] then
sumav:=sumav+1;
if nom [i] in ['E'] then
sumav:=sumav+5;
if nom [i] in ['I'] then
sumav:=sumav+9;
if nom [i] in ['O'] then
sumav:=sumav+6;
if nom [i] in ['U'] then
sumav:=sumav+3;



end;
end;


Memo1.Lines.add('-------------------------------- ');
Memo1.Lines.Add('ESENCIA (lo que usted Quiere)');
Memo1.Lines.Add(linea);
Memo1.Lines.Add(inttostr(sumav));

linea := '';
cont1:= 0;
for i := 1 to length (nom) do
if nom [i] in ['B','C','D','F','G','H','J','K','L','M','Ñ','P','Q','R','S','T','V','W','X','Y','Z','b','c','d','f', 'g','h','j','k','l','m','n','ñ','p','q','r','s','t','v','w','x','y','z'] then
begin
linea1 := linea1 + nom[i] +' ';
cant1 := cant1 + 1;
if nom [i] in ['J','S'] then
sumac:=sumac+1;
if nom [i] in ['B','K','T'] then
sumac:=sumac+2;
if nom [i] in ['C','L'] then
sumac:=sumac+3;
if nom [i] in ['D','M','V'] then
sumac:=sumac+4;
if nom [i] in ['N','W'] then
sumac:=sumac+5;
if nom [i] in ['F','X'] then
sumac:=sumac+6;
if nom [i] in ['G','P','Y'] then
sumac:=sumac+7;
if nom [i] in ['H','Q','Z'] then
sumac:=sumac+8;
if nom [i] in ['R'] then
sumac:=sumac+9;
end;



Memo1.Lines.add('-------------------------------- ');
Memo1.Lines.Add('IMAGEN (como lo ven los demas)');
Memo1.Lines.Add(linea1);
Memo1.Lines.Add(inttostr(sumac));


end;


end.

Casimiro Notevi
04-06-2015, 21:33:31
Has batido el record de incumplir las normas de los foros ;)

Bienvenido a clubdelphi, como siempre aconsejamos a los nuevos, no olvides leer nuestra guía de estilo (http://www.clubdelphi.com/foros/guiaestilo.php), gracias por tu colaboración :)



Y recuerda poner los tags al código fuente, ejemplo:

http://www.clubdelphi.com/images/UtilizarTAGs.png

Gracias :)

ecfisa
04-06-2015, 22:04:58
Hola anonymous.

Combiné el nuevo hilo bajo el título del primero, de hace 6 días, ya que se trata del mismo tema. Al continuar con el tema previo, este pasa a encabezar la lista de nuevos mensajes, no es necesario crear otro con contenido similar.

Saludos :)

nlsgarcia
06-06-2015, 04:38:48
anonymous,


...Ingresando el usuario un Nombre y Apellido (DIEGO ARMANDO MARADONA)...Cada letra tiene su valor...Sumar los números asignados a una palabra...

:rolleyes:

Revisa este código:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

TAction = (Esencia = 1, Imagen = 2, Destino = 3, Sendero = 4);

var
Form1: TForm1;
ABC : Array['a'..'z'] of Byte = (1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8);

{
Tabla de Pitágoras
1 2 3 4 5 6 7 8 9
a b c d e f g h i
j k l m n o p q r
s t u v w x y z
}

implementation

{$R *.dfm}

function Numerology(Value : String; Action : TAction) : Byte;
var
SL : TStringList;
i, j, k : Integer;
AuxValue, AuxNum : String;
NumValue : Integer;
L : Char;

begin

SL := TStringList.Create;

ExtractStrings([' ','/','-'], [], PChar(Value), SL);

Result := 0;

for i := 0 to SL.Count - 1 do
begin

AuxValue := LowerCase(SL);
NumValue := 0;

for j := 1 to Length(AuxValue) do
begin

L := AuxValue[j];

if (Action = Esencia) and (L in ['a','e','i','o','u']) then
NumValue := NumValue + ABC[L];

if (Action = Imagen) and not (L in ['a','e','i','o','u']) then
NumValue := NumValue + ABC[L];

if (Action = Destino) then
NumValue := NumValue + ABC[L];

if (Action = Sendero) then
begin

if AuxValue[j] in ['0','1','2','3','4','5','6','7','8','9'] then
NumValue := NumValue + StrToInt(AuxValue[j]);

if NumValue > 9 then
repeat

AuxNum := IntToStr(NumValue);
NumValue := 0;

for k := 1 to Length(AuxNum) do
NumValue := NumValue + StrToInt(AuxNum[k]);

until NumValue < 10

end;

end;

Result := Result + NumValue;

end;

SL.Free;

if Result in [11,22] then
Exit;

if Result > 9 Then
repeat

AuxValue := IntToStr(Result);
Result := 0;

for j := 1 to Length(AuxValue) do
Result := Result + StrToInt(AuxValue[j]);

if Result in [11,22] then
Break;

until (Result < 10);

end;

procedure TForm1.Button1Click(Sender: TObject);
var
Name : String;
DateBirth : String;

begin

Name := 'Diego Armando Maradona';
DateBirth := '30/10/1960';

ListBox1.Clear;

ListBox1.Items.Add(Format('Nombre = %s',[Name]));

ListBox1.Items.Add(Format('Fecha Natal = %s',[DateBirth]));

ListBox1.Items.Add(Format('Esencia = %d',[Numerology(Name,Esencia)]));

ListBox1.Items.Add(Format('Imagen = %d',[Numerology(Name,Imagen)]));

ListBox1.Items.Add(Format('Destino = %d',[Numerology(Name,Destino)]));

ListBox1.Items.Add(Format('Sendero = %d',[Numerology(DateBirth,Sendero)]));

end;

end.

El código anterior en Delphi 7 sobre Windows 7 Profesional x32, Realiza cálculos numerológicos basados en la información obtenida de las imágenes de los Msg # 1 y #6, como se muestra en la siguiente imagen:

http://i.imgur.com/7luWaGp.jpg

Nota: El código propuesto tiene como único objetivo, [I]servir de guía a los requerimientos planteados en los Msg #1 y Msg #6.

Espero sea útil :)

Nelson.