a versão do programa:
Pesquisando múltiplos em matriz de inteiros
que foi criado no C++ Builder.
Mas para não ficar só nos pensamentos,
abri o Qt e criei uma versão do programa original,
quem sabe eu me anime um pouco com o Qt depois disto.
//Pesquisando múltiplos numa matriz de inteiro
//MÚLTIPLOS - MARCANDO OCORRÊNCIAS COM UM CÍRCULO
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>
#include <QTimer>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
/*============================================================*/
void MainWindow :: Informe ( QPaintEvent *event ) {
QPainter painter ( this );
painter.setFont ( QFont ( "Times", 12, QFont :: Bold ) );
painter.setPen ( Qt::red );
painter.drawText ( QPoint ( 140, 310 ), "Por: ");
painter.setPen ( Qt::blue );
painter.drawText ( QPoint ( 180, 310 ), "Samuel Lima");
painter.setPen ( Qt::black );
painter.drawText ( QPoint ( 140, 325 ), "sa_sp10@hotmail.com");
}
/*============================================================*/
void MainWindow :: load_Array ( QPaintEvent *event ) {
QPainter painter ( this );
painter.setFont ( QFont ( "Times", 14, QFont :: Normal ) );
QString str_1;
for( i = 0; i < 100; i++ ) {
A [ b ] [ a ] = i;
a++;
}
int y = 1;
for ( a = 0; a < 10; a++ ) {
for ( b = 0; b < 10; b++ ) {
str_1.append ( " " );
if ( A [ a ] [ b ] % 10 == 0 ) {
str_1.append ( "\n" );
y = y - 2;
}
if ( A [ a ] [ b ] >= 0 && A [ a ] [ b ] < 10 )
str_1.append ( "0" );
if ( x >= 1 && x < 10 ) {
if ( A [ a ] [ b ] % n == 0 && A [ a ] [ b ] != 0 ) {
painter.setPen ( Qt::red );
painter.setBrush ( Qt::green );
QRect rec1 ( 139 + ( b * 33 ), 48 + ( a * 24 + y ), 20, 20 );
painter.drawEllipse ( rec1 );
}
}
str_1 += QString::number ( A [ a ] [ b ] );
QRect rec ( 140, 26, 400, 290 );
painter.setPen ( Qt::black );
painter.drawText ( rec, str_1 );
}
}
Informe ( event );
}
/*============================================================*/
void MainWindow::on_pushButton_clicked()
{
x++;
n = ui -> lineEdit -> text( ).toInt();
repaint ( );
_beep ( 500, 500 );
ui -> lineEdit -> setText (" ");
ui -> lineEdit -> setFocus ( );
}
/*============================================================*/
void MainWindow::paintEvent ( QPaintEvent *event )
{
QPainter painter ( this );
//Criando um retângulo sem preenchimento
QRectF rectangle ( 5.0, 5.0, 590.0, 340.0 );
//Colocando uma borda vermelha no retângulo
painter.setPen ( QPen ( Qt::red, 10, Qt::SolidLine ) );
//Adicionando a retângulo ao painter
painter.drawRect ( rectangle );
painter.setFont ( QFont ( "Times", 16, QFont :: Bold ) );
painter.setPen ( Qt::red );
painter.drawText ( QPoint ( 110, 30 ), "MÚLTIPLOS - MARCANDO OCORRÊNCIAS");
load_Array ( event );
}
/*============================================================*/
void MainWindow::on_pushButton_2_clicked()
{
close ( );
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
void paintEvent ( QPaintEvent *event );
void load_Array ( QPaintEvent *event );
void Informe ( QPaintEvent *event );
private slots:
void on_pushButton_clicked ( );
void on_pushButton_2_clicked();
private:
Ui::MainWindow *ui;
int x = 0;
int n = 0;
int a = 0, b = 0;
int A [ 10 ] [ 10 ], i;
};
#endif // MAINWINDOW_H
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}