sexta-feira, 1 de fevereiro de 2019

C++ Builder - Vetor invocando vetor

Na função de eventos OnPaint criei e inicializei 
dois vetores de números inteiros, à saber:
int vetor [ tam ] = { ...}; que recebe seu tamanho
pré-definido pela Macro tam,
e int vet [ dim ] = { ...}; que recebe seu tamanho
pré-definido pela Macro dim.
int vetor [ ] foi passado como parâmetros para a função
emb_lhar ( int vetor [ tam ] ) para que seus
nove elementos sequenciais sejam embaralhados,
mas a quantidade de números embaralhados que serão
imprimidos no vídeo é definida por cada um dos
quatro elementos de int vet [ ] = {...};
Porém não é de qualquer maneira a chamada destes
números que serão à quantidade dos números apresentados
é totalmente aleatória, por isto msmo dei este título
estranho ao programa:
C++ BUILDER - VETOR INVOCANDO VETOR,
Se quiser saber mais click na imagem e veja os códigos
do programa, copie e cole no seu Embarcadero,
Se não conseguir compilar me peça o link do projeto
completo para download, que estou pronto
a disponibilizá-lo para estudos.


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

void __fastcall TForm1::Informe ( TObject *Sender ) {
Canvas->Font->Color = clBlack;
Canvas->TextOut ( 200, 190, "Por: " );
Canvas->Font->Color = clRed;
Canvas->TextOut ( 240, 190, "Samuel Lima" );
Canvas->Font->Color = clBlack;
Canvas->TextOut ( 200, 210, "sa_sp10@hotmail.com" );
Canvas->Font->Name = "Garamond";
Canvas->Font->Size = 20;
Canvas->Font->Color = clSkyBlue;
Canvas->TextOut ( 200, 256, "MUITO OBRIGADO" );
SetBkMode ( Canvas->Handle, TRANSPARENT );
Canvas->Font->Color = clBlue;
Canvas->TextOut ( 200, 250, "MUITO OBRIGADO" );
}
void emb_lhar ( int vetor [ tam ] ) {
int i, temp;
int y = y;
srand (time ( NULL ) );
for ( i = 0; i < tam; i++ ) {
y = rand ( ) % tam;
temp = vetor [ i ];
vetor [ i ] = vetor [ y ];
vetor [ y ] = temp;
}
}

//---------------------------------------------------------------------------

void __fastcall TForm1::OnPaint ( TObject *Sender ) {
Canvas->Font->Size = 18;
Canvas->Font->Name = "Garamond";
Canvas->Font->Color = clRed;
Canvas->Font->Name = "Garamond";
Canvas->Pen->Width = 10;
Canvas->Rectangle ( 05, 05, 595, 295 );
SetTextColor ( Canvas->Handle, RGB ( 255, 25, 2 ) );
Canvas->TextOut ( 40, 20, "C++ BUILDER - VETOR INVOCANDO VETOR" );
String str_1 = " ";
String str_2 = " ";
String str_3 = " ";
Canvas->Font->Color = clRed;
int vetor [ tam ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int vet [ dim ] = { 2, 3, 4, 5 };
int b;
int a = 1;
int i, x = 0;
emb_lhar ( vet );
for ( i = 0; i < tam; i++ ) {
for ( i = 0; i < dim; i++ ) {
do {
str_2 = " ";
a = vet [ i ];
str_1 = a;
Canvas->Font->Color = clBlack;
Canvas->TextOut ( 140, 70, "Imprimindo " );
Canvas->Font->Color = clRed;
Canvas->TextOut ( 270, 70, str_1 );
Canvas->Font->Color = clBlack;
Canvas->TextOut ( 300, 70, "elementos " );
emb_lhar ( vetor );
for ( b = 0; b < a; b++ ) {
str_2 += vetor [ b ];
}
i++;
x++;
str_3 = ( x + 0 );
Canvas->Font->Color = clRed;
Canvas->TextOut ( 140, 130, str_3 + "ª");
Canvas->Font->Color = clBlack;
Canvas->TextOut ( 170, 130, "Impressão" );
Canvas->Font->Color = clRed;
Canvas->TextOut ( 400, 70, "                      " );
Canvas->TextOut ( 400, 70, str_2 );
Sleep ( 2000 );
if ( ( x + 0 ) == 9 ) {
Informe ( Sender );
Sleep ( 4000 );
exit ( 0 );
}
break;
str_2 = " ";
} while ( 1 );
i = i - 1;
}
}
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
//Unit1.h
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall OnPaint(TObject *Sender);
    void __fastcall Informe ( TObject *Sender );
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------

#endif


object Form1: TForm1
  Left = 342
  Top = 165
  Caption = 'C++ BUILDER - VETOR INVOCANDO VETOR'
  ClientHeight = 300
  ClientWidth = 600
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesigned
  OnPaint = OnPaint
  PixelsPerInch = 600
  TextHeight = 13

end

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.