Array


Array

An array is a variable that can store a group of values; an array is very similar to a list of values. An array is used whenever it is necessary to manipulate a group of values. For instance, the area of each country in the world can be stored and manipulated using an array. The figure below shown an array called x with four integer values inside it: 2, 4, -3 and 8.
Un arreglo es una variable que puede almacenar un grupo de valores; un arreglo es muy similar a una lista de valores. Un arreglo es usado cuando es necesario manipular un grupo de valores. Por ejemplo, la superficie de cada país en el mundo puede ser almacenada y manipulada usando un arreglo. La figura de abajo muestra un arreglo llamado x con cuatro valores enteros adentro de él: 2, 4, -3 y 8.

Array

Index

Each value in the array can be accessed using a number called index. For instance, suppose you have an array (a list) with the age of some students in a class. The age of the first student can be accessed using an index of 0; the age of the second student can be accessed using an index of 1, etc. Thus, the index describes the position of the value in the array. In programming, the index of the first element is always zero. The figure below shows the array x, note that the index goes from 0 to 3.
Se puede tener acceso a uno de los valores de un arreglo usando un número llamado índice. Por ejemplo, suponga que se tiene un arreglo (una lista) con la edad de algunos estudiantes en una clase. La edad del primer estudiante se puede accesar usando un índice de 0; la edad del segundo estudiante se puede accesar con un índice de 1, etc. Así, el índice describe la posición del valor en el arreglo. En programación, el índice el primer elemento es siempre cero. La figura de abajo muestra el arreglo x, observe que el índice va desde 0 hasta 3.

Index

Default Button

Any GUI can have a button that can be pressed using the enter key from the keyboard. Modifying the properties of the button using Wintempla, it is possible to set a button as the default button. One of the main advantages of having a default button is to avoid using the mouse while typing a lot of information using the keyboard. The figure below shows a default button and a normal button note that the default button looks a little different from the regular button.
Cualquier GUI puede tener un botón que se presiona usando la tecla de enter desde el teclado. Modificando las propiedades del botón desde Wintempla, es posible fijar un botón como el botón de defecto. Una de las principales ventajas de tener un botón de defecto es evitar el uso del ratón cuando se encuentra escribiendo mucha información desde el teclado. La figura de abajo muestra un botón de defecto y un botón normal note que el botón de defecto se ve un poco diferente al botón regular.

DefaultButton

The Focus

The focus allows sharing the keyboard among all programs that are running in one computer. The focus is displayed in each GUI element (GUI control). The focus can be moved from one GUI element o another one by pressing the tab key. One program is active in a computer, and inside this program one GUI element (GUI control) may have the focus. When the user types some text from the keyboard, the GUI element with the focus will receive the input from the keyboard. If the programmer wants to send the focus to a specific control, the program must call the method SetFocus() of the respective control. The figures below show the focus in a button, and in a textbox respectively.
El focus permite compartir el teclado entre todos los programas que se encuentran en ejecución en una computadora. El focus es mostrado en cada elemento GUI (control GUI). El focus puede moverse de un elemento GUI a otro presionado la tecla de tab. Un programa está activo en una computadora, y dentro de este programa un elemento GUI (control GUI) puede tener el focus. Cuando el usuario escriba un texto desde el teclado, el elemento GUI con el focus recibirá la entrada desde el teclado. Si el programador quiere enviar el focus a un control específico, el programa debe llar el método SetFocus() del control respectivo. Las figuras de abajo muestran el focus en un botón, y en una caja de texto respectivamente.

Focus

Tip
Always set and send the focus appropriately to reduce the number of clicks that the user has to make to use the program.
Siempre fije y envié el focus en forma apropiada para reducir el número de clics que el usuario tiene que hacer para usar el programa.

Problem 1
Create a Dialog Application called NumberList as shown. Insert a textbox called tbxList with the properties: read only and multiline. Insert a button called btInsert with the property: default button. The code shown below allows inserting elements in the list using the keyboard only. Every time the button is pressed, the integer value is extracted and converted to text with a new line. The resulting text is appended to another textbox. The input textbox is cleared, and the focus is sent to the input textbox.
Cree una Aplicación de Diálogo llamado NumberList como se muestra. Inserte una caja de texto llamada tbxList con las propiedades de: solo lectura y multi-línea. Inserte un botón llamado btInsert con la propiedad de botón de defecto. El código mostrado debajo permite insertar los elementos en la lista usando el teclado solamente. Cada vez que el botón es presionado, el valor entero es extraído y convertido a texto con una nueva línea. El texto resultado es agregado a otra caja de texto. La caja de texto de entrada es limpiada, y el focus es enviado a la caja de texto de entrada.

NumberList.cpp
void NumberList::btInsert_Click(Win::Event& e)
{
     wchar_t text[64];
     const double number = tbxNumber.DoubleValue;
     _snwprintf_s(text, 64, _TRUNCATE, L"%g\r\n", number);
     tbxList.Text += text;
     tbxNumber.Text = L""; // Clear the textbox
     tbxNumber.SetFocus(); // The user can keep typing without using the mouse
}

NumberList

Problem 2
Create a program called MaxMin to compute the maximum and minimum values in a list of numbers. Each time the Insert button is pressed, a new number is added to the list, and the maximum and minimum values are updated. Set the property of read only in the textboxes: tbxList, tbxMinimum and tbxMaximum.
Cree un programa llamada MaxMin para calcular el máximo y el mínimo de una lista de números. Cada vez que se presiona el botón de Insertar, se inserta un número en la lista y se actualizan los valores del mínimo y el máximo. Fije la propiedad de solo lectura en las cajas de texto de: tbxList, tbxMinimum y tbxMaximum.

MaxMin.h
#pragma once //______________________________________ MaxMin.h
#include "resource.h"

class MaxMin: public Win::Dialog
{
public:
     MaxMin()
     {
          minimum = 0;
          maximum = 0;
     }
     ~MaxMin()
     {
     }
     int minimum;
     int maximum;
protected:
     . . .
};

MaxMin

Problem 3
Create a program called SumProd to compute the summation and the product of the numbers in a list. Each time the Insert button is pressed, the number is inserted in the list and the values Addition and Product are updated. Set the property of read only to the appropriated textboxes.
Cree un programa llamada SumProd para calcular la suma y el producto de los números en una lista. Cada vez que se presiona el botón de Insertar, se inserta un número en la lista y se actualizan los valores de la suma y el producto. Fija la propiedad de solo lectura en forma apropiada a las cajas de texto.

SumProd

Tip
Arrays are used to store: lists of people, people information, scientist data, money movement, student grades, etc.
Los arreglos son usados para almacenar: listas de personas, información personal, datos científicos, movimientos de dinero, calificaciones de estudiantes, etc.

© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home