Aqui está um exemplo de um programa que está
programado para contar e separar consoantes
e vogais contidas numa frase inserida pelo
usuário pela entrada de dados feita com um
Objeto TEdit do C++ builder, na verdade o
O TEdit possui diversas propriedades interessantes,
e a mais adequada neste caso é a FilterChar,
simplesmente poderíamos bloquear os caracteres
que não  fosse de nosso interesse passar,
mas nós começamos no mundo da programação,
estudando linguagem C, e em C quase tudo
temos que fazer na mão, e isto muitas das vezes,
é muito gratificante, saber como as coisas funcionam.
No nosso exemplo tudo se baseia em comparações,
temos um Array de char do C predefinido e inicializado,
com os caracteres das vogais minúsculas, e maiúsculas
que será comparado com o array de char que recebeu
da entrada os seus valores.
Sem enrolação testem isto agora mesmo,
ou pelo menos aproveitem toda a lógica do programa
que foi criada em linguagem C, e que pode ser
traduzida em diversas outras linguagens.
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include <math.h>
#include "Unit1.h"
#include "stdlib.h"
#include "time.h"
#define tam 6
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1 ( TComponent* Owner )
	: TForm ( Owner )
{
}
//---------------------------------------------------------------------------
TText *Text1;
TText *Text2;
TText *Text3;
TText *Text4;
TText *Text5;
TText *Text6;
TText *Text7;
TButton *Button1;
int a, b, m, x, t;
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
	Rectangle1 -> Width = 600;
	Rectangle1 -> Height = 340;
	Rectangle1 -> Position -> X = 0;
	Rectangle1 -> Position -> Y = 0;
	Rectangle1 -> Fill -> Color = ( RGB ( 255, 0, 205 ) );
	Rectangle1 -> Size -> PlatformDefault = False;
	Rectangle1 -> Stroke -> Color = claRed;
	//Rectangle1 -> Stroke -> Kind = TBrushKind::Solid;
	//Rectangle1 -> Stroke -> Color = ( RGB ( 255, 255, 0 ) );
	Rectangle1 -> Stroke -> Thickness = 10;
	Rectangle1 -> XRadius = 15;
	Rectangle1 -> YRadius = 15;
	Label1 -> Position -> X = 170;
	Label1 -> Position -> Y = 250;
	Label1 -> Size -> Width = 200;
	Label1 -> Size -> Height = 30;
	Label1 -> TextSettings -> Font -> Size = 18;
	Label1 -> TextSettings -> FontColor = claBlack;
	Label1 -> TextSettings -> Font -> Family = "Consolas";
	Label1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
	Label1 -> Text = "Por: Samuel Lima";
	Label2 -> Position -> X = 170;
	Label2 -> Position -> Y = 265;
	Label2 -> Size -> Width = 200;
	Label2 -> Size -> Height = 30;
	Label2 -> TextSettings -> Font -> Size = 18;
	Label2 -> TextSettings -> FontColor = claBlack;
	Label2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
	Label2 -> Text = "sa_sp10@hotmail.com";
	Text1  = new TText ( this );
	Text1 -> Parent = Form1;
	//Text1 -> AutoSize = True;
	Text1 -> Position -> X = -55;
	Text1 -> Position -> Y = 17;
	Text1 -> Size -> Width = 700;
	Text1 -> Size -> Height = 20;
	Text1 -> TextSettings -> Font -> Size = 16;
	Text1 -> TextSettings -> FontColor = claRed;
	Text1 -> Size -> PlatformDefault = False;
	Text1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
	Text2  = new TText ( this );
	Text2 -> Parent = Form1;
	//Text2 -> AutoSize = True;
	Text2 -> Position -> X = -145;
	Text2 -> Position -> Y = 47;
	Text2 -> Size -> Width = 700;
	Text2 -> Size -> Height = 20;
	Text2 -> TextSettings -> Font -> Size = 14;
	Text2 -> TextSettings -> FontColor = claBlack;
	Text2 -> Size -> PlatformDefault = False;
	Text2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
	Text3  = new TText ( this );
	Text3 -> Parent = Form1;
	//Text3 -> AutoSize = True;
	Text3 -> Position -> X = -145;
	Text3 -> Position -> Y = 67;
	Text3 -> Size -> Width = 700;
	Text3 -> Size -> Height = 20;
	Text3 -> TextSettings -> Font -> Size = 14;
	Text3 -> TextSettings -> FontColor = claRed;
	Text3 -> Size -> PlatformDefault = False;
	Text3 -> Font -> Style = TFontStyles ( ) << fsItalic;
	Text4  = new TText ( this );
	Text4 -> Parent = Form1;
	//Text1 -> AutoSize = True;
	Text4 -> Position -> X = -70;
	Text4 -> Position -> Y = 87;
	Text4 -> Size -> Width = 700;
	Text4 -> Size -> Height = 20;
	Text4 -> TextSettings -> Font -> Size = 14;
	Text4 -> TextSettings -> FontColor = claBlack;
	Text4 -> Size -> PlatformDefault = False;
	Text4 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
	Text5  = new TText ( this );
	Text5 -> Parent = Form1;
	//Text5 -> AutoSize = True;
	Text5 -> Position -> X = -185;
	Text5 -> Position -> Y = 107;
	Text5 -> Size -> Width = 700;
	Text5 -> Size -> Height = 20;
	Text5 -> TextSettings -> Font -> Size = 14;
	Text5 -> TextSettings -> FontColor = claRed;
	Text5 -> Size -> PlatformDefault = False;
	Text5 -> Font -> Style = TFontStyles ( ) << fsItalic;
	Text6  = new TText ( this );
	Text6 -> Parent = Form1;
	//Text6 -> AutoSize = True;
	Text6 -> Position -> X = -80;
	Text6 -> Position -> Y = 127;
	Text6 -> Size -> Width = 700;
	Text6 -> Size -> Height = 20;
	Text6 -> TextSettings -> Font -> Size = 14;
	Text6 -> TextSettings -> FontColor = claBlack;
	Text6 -> Size -> PlatformDefault = False;
	Text6 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
	Text7  = new TText ( this );
	Text7 -> Parent = Form1;
	//Text7 -> AutoSize = True;
	Text7 -> Position -> X = -185;
	Text7 -> Position -> Y = 147;
	Text7 -> Size -> Width = 700;
	Text7 -> Size -> Height = 20;
	Text7 -> TextSettings -> Font -> Size = 14;
	Text7 -> TextSettings -> FontColor = claRed;
	Text7 -> Size -> PlatformDefault = False;
	Text7 -> Font -> Style = TFontStyles ( ) << fsItalic;
	Edit1 -> SetFocus ( );
	Edit1 -> Font -> Size = 12;
    Edit1 -> TextSettings -> FontColor = claRed;
	Edit1 -> Width = 130;
	Edit1 -> Height = 17;
	Edit1 -> Position -> X = 277;
	Edit1 -> Position -> Y = 47;
	Button1  = new TButton ( this );
	Button1 -> Parent = Form1;
	Button1 -> Width = 30;
	Button1 -> Height = 17;
	Button1 -> Position -> X = 415;
	Button1 -> Position -> Y = 47;
	Button1 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
	Button1 -> TextSettings -> Font -> Family = "Arial";
	Button1 -> TextSettings -> Font -> Size = 16;
	Button1 -> TextSettings -> FontColor = claRed;
	Button1 -> Text = "Ok";
	Button1 -> OnClick = Button1Click;
	Button2 -> Width = 50;
	Button2 -> Height = 17;
	Button2 -> Position -> X = 470;
	Button2 -> Position -> Y = 300;
	Button2 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
	Button2 -> TextSettings -> Font -> Family = "Arial";
	Button2 -> TextSettings -> Font -> Size = 16;
	Button2 -> TextSettings -> FontColor = claRed;
	Button2 -> Text = "Sair";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
	Label_Manual ( Sender );
	Text1 -> Text = "FMX - SEPARANDO VOGAIS E CONSOANTES EM FRASES";
	a = 0;
	if ( a == 0 )
	Text2 -> Text = "Digite uma frase : ";
	Button2 -> Visible = false;
	Label1 -> Visible = false;
	Label2 -> Visible = false;
	Edit1 -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click ( TObject *Sender ) {
	int i, j, k, h = 0, lenv, lenv_1;
	char Vogais [ ] = { 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' };
	lenv_1 = strlen ( Vogais );
	char str [ 50 ];
	char Vet [ 50 ];
	String st;
	st += Edit1 -> Text;
	AnsiString str_1 = Edit1 -> Text;
	if ( str_1 != "" ) {
		a++;
    }
	wcstombs (  str, st.c_str ( ), 50 );
	lenv = strlen ( str );
	if ( a == 1 ) {
		Edit1 -> Visible = false;
		Text2 -> Text = "Abaixo a frase digitada: ";
		Button1 -> Width = 100;
		Button1 -> Height = 17;
		Button1 -> Position -> X = 130;
		Button1 -> Position -> Y = 300;
		Button1 -> TextSettings -> Font -> Family = "Arial";
		Button1 -> TextSettings -> Font -> Size = 16;
		Button1 -> TextSettings -> FontColor = claRed;
		Button1 -> Text = "Pressione";
		for ( i = 0; i < lenv; i++ ) {
			Text3 -> Text += str [ i ];
		}
	}
	if ( a == 2 ) {
		Text4 -> Text = "Imprimindo abaixo só as ";
		for ( i = 0; i < lenv; i++ ) {
			for ( j = 0; j < lenv; j++ )
				if ( str [ i ] == Vogais [ j ] ) {
					break;
				}
			if ( j == lenv ) {   x++;
				Text5 -> Text += str [ i ];
			}
			if ( str [ i ] == ' ' )
					t++;
		  }
	x = x - t;
	Text4 -> Text = Text4 -> Text + x;
	Text4 -> Text = Text4 -> Text  + " consoantes da frase";
	}
	//==========================================================================
	if ( a == 3 ) {
		Text6 -> Text = "Imprimindo abaixo só as ";
		for ( i = 0; i < lenv; i++ ) {
			for ( j = 0; j < lenv_1; j++ ) {
				if ( Vogais [ j ] == str [ i ] ) {
					Vet [ h ] = str [ i ];
					h++;
					m++;
				}
			}
		}
		Text6 -> Text = Text6 -> Text + m;
		Text6 -> Text = Text6 -> Text + " vogais da frase";
		k = h;
		for ( h = 0; h < k; h++ ) {
			Text7 -> Text += Vet [ h ];
		}
		Button1 -> Text = "Nova frase";
		Button2 -> Visible = true;
		Label1 -> Visible = true;
		Label2 -> Visible = true;
	}
	if ( a == 4 ) {
		m = 0;
		x = 0;
		t = 0;
        Text2 -> Text = " ";
		Text3 -> Text = " ";
		Text4 -> Text = " ";
		Text5 -> Text = " ";
		Text6 -> Text = " ";
		Text7 -> Text = " ";
		Edit1 -> Text = "";
		Button1 -> Visible = false;
		FormShow ( Sender );
	}
	if ( str_1 == "" ) {
			Beep ( 500, 500 );
			Edit1 -> SetFocus ( );
			return;
	}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click ( TObject *Sender ) {
		   Close ( );
}
//---------------------------------------------------------------------------
 
Nenhum comentário:
Postar um comentário
Observação: somente um membro deste blog pode postar um comentário.