0% encontró este documento útil (0 votos)
5 vistas11 páginas

Menú Interactivo en C para Cálculo de Áreas

Este documento presenta un programa desarrollado por un estudiante para calcular el área de diferentes figuras geométricas utilizando un menú con opción de salir. El programa incluye las funciones necesarias como int, while y switch, y muestra el código y capturas de pantalla que demuestran su funcionamiento al calcular el área de triángulos, rectángulos, cuadrados, círculos, rombos y trapecios. El estudiante concluye que logró hacer un programa con menú y opción de salida según lo requerido.
Derechos de autor
© All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
5 vistas11 páginas

Menú Interactivo en C para Cálculo de Áreas

Este documento presenta un programa desarrollado por un estudiante para calcular el área de diferentes figuras geométricas utilizando un menú con opción de salir. El programa incluye las funciones necesarias como int, while y switch, y muestra el código y capturas de pantalla que demuestran su funcionamiento al calcular el área de triángulos, rectángulos, cuadrados, círculos, rombos y trapecios. El estudiante concluye que logró hacer un programa con menú y opción de salida según lo requerido.
Derechos de autor
© All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd

Instituto Politécnico Nacional

CECyT No 1. “Gonzalo Vázquez


Vela”
Lenguaje de Programación

PROGRAMA:52
[MENU CON
OPCION DE SALIR]
Contenido Temático
[Temas]

Nombre del Alumno


[GUTIERREZ AYON MARIA RAQUEL]

David Roque B.
david@[Link]
30 de abril de 2023
Desarrollo:
Escribe el problema a resolver:

Hacer un programa con un menú con opción de salir

Describe la posible solución:

Agregar función int, while, switch

Dibuja el diagrama de flujo:

Ing. David Roque B. SDTM 1


Escribe el código que empleaste:

//GUTIERREZ AYON MARIA RAQUEL

//Este programa hace un menu con opcion salir

#include <stdio.h>

Ing. David Roque B. SDTM 2


#include <conio.h>

void main (void)

int opcion = 0;

float base = 0, altura = 0, lado = 0, radio = 0, area = 0;

while (opcion != 7) {

clrscr(); // Limpia la pantalla

printf("Calculadora de areas\n");

printf("1. Triangulo\n");

printf("2. Rectangulo\n");

printf("3. Cuadrado\n");

printf("4. Circulo\n");

printf("5. Rombo\n");

printf("6. Trapecio\n");

printf("7. Salir\n");

printf("Selecciona una opcion: ");

scanf("%d", &opcion);

switch (opcion) {

case 1:

printf("Ingresa la base: ");

scanf("%f", &base);

Ing. David Roque B. SDTM 3


printf("Ingresa la altura: ");

scanf("%f", &altura);

area = (base * altura) / 2;

printf("El area del triangulo es: %.2f\n", area);

break;

case 2:

printf("Ingresa la base: ");

scanf("%f", &base);

printf("Ingresa la altura: ");

scanf("%f", &altura);

area = base * altura;

printf("El area del rectangulo es: %.2f\n", area);

break;

case 3:

printf("Ingresa el lado: ");

scanf("%f", &lado);

area = lado * lado;

printf("El area del cuadrado es: %.2f\n", area);

break;

case 4:

printf("Ingresa el radio: ");

scanf("%f", &radio);

area = 3.1416 * (radio * radio);

printf("El area del circulo es: %.2f\n", area);

Ing. David Roque B. SDTM 4


break;

case 5:

printf("Ingresa la diagonal mayor: ");

scanf("%f", &base);

printf("Ingresa la diagonal menor: ");

scanf("%f", &altura);

area = (base * altura) / 2;

printf("El area del rombo es: %.2f\n", area);

break;

case 6:

printf("Ingresa la base mayor: ");

scanf("%f", &base);

printf("Ingresa la base menor: ");

scanf("%f", &altura);

printf("Ingresa la altura: ");

scanf("%f", &lado);

area = ((base + altura) * lado) / 2;

printf("El area del trapecio es: %.2f\n", area);

break;

case 7:

printf("Hasta luego!\n");

break;

default:

printf("Opcion invalida\n");

Ing. David Roque B. SDTM 5


break;

if (opcion != 7) {

printf("Presiona cualquier tecla para continuar\n");

getch(); // Espera a que el usuario presione una tecla

Copia la o las pantallas del turbo C que demuestran el funcionamiento de tu programa:

Ing. David Roque B. SDTM 6


Ing. David Roque B. SDTM 7
Ing. David Roque B. SDTM 8
Escanea la hoja completa del código a mano y agrégala en el siguiente espacio:

Ing. David Roque B. SDTM 9


Conclusión:

Hicimos un programa con un menú y opción de salir con las funciones correspondientes.

Guarda este documento en formato .pdf y súbelo en el espacio correspondiente con el nombre del
programa.

Ing. David Roque B. SDTM 10

Common questions

Con tecnología de IA

The `getch()` function is used to pause the program execution and wait for the user to press any key before continuing. This ensures that the user has time to read the output of each operation before the screen is cleared for the next iteration of the menu. It enhances the user experience by preventing the information from disappearing too quickly and offers a moment to review the results .

Including hand-drawn flowcharts and detailed code documentation can be pedagogically effective as they facilitate a deeper understanding of the underlying logic and structure of the program. Flowcharts help learners visualize the control flow and logic of algorithms, making abstract concepts more tangible. Moreover, documentation encourages good programming practices by ensuring that learners can articulate their thought processes clearly. This combination reinforces both visual and written modes of learning, crucial for grasping programming concepts .

Procedural abstraction in this program involves separating the logic for calculating the area of each geometric shape into distinct cases within the switch statement. This modular approach makes the program easier to read, update, and debug. By encapsulating each calculation within its case, the program allows for focused development and testing of individual functionalities without affecting others. However, functions for repeated operations could improve abstraction further by reducing code repetition .

The program handles invalid inputs by utilizing the default case in the switch statement, which displays an error message 'Opcion invalida' to the user. This informs the user that the input did not match any of the expected menu options and does not terminate the program, allowing the user to try again .

Using a `switch` statement for menu selection is effective in this context as it allows for clear and organized handling of user input, where each menu option corresponds to a distinct case. Compared to if-else constructs, `switch` provides better readability and is generally more efficient for handling multiple discrete choices. However, it is less suitable if the conditions were to involve complex expressions or ranges, where an if-else ladder might be more flexible .

Converting the program to a GUI application would enhance user engagement and accessibility, making it more intuitive, especially for visual learners. A GUI could provide buttons, sliders, and input fields that visually represent choices and data entry, reducing user errors and improving interaction efficiency. It would allow for real-time visual feedback and interactive elements such as dynamic charts or diagrams representing the shapes calculated. Such enhancements can make the program more user-friendly and appealing, particularly in educational settings .

Improvements could include providing clearer instructions and prompts, such as examples of expected input formats, and restructuring the user interface to include input validation prompts that reinforce correct data entry. Additionally, implementing a consistent naming convention for the variables, such as 'largeBase', 'smallBase', and 'height' instead of 'base', 'altura', and 'lado', could prevent misunderstandings. Adding options to review calculations without clearing them immediately might also be beneficial .

The program calculates the area of a trapezoid using the formula `area = ((base + altura) * lado) / 2`, where 'base' and 'altura' are the lengths of the two parallel sides, and 'lado' is the height. However, the variable names 'base' and 'altura' could be misleading as 'base' typically refers to one side and 'altura' is height. Consistent terminology should be maintained to avoid confusion .

Command-line interfaces (CLI) are limited in providing visual feedback compared to graphical user interfaces (GUIs), which can be less engaging and harder for beginners to navigate. CLIs are text-based, requiring users to remember commands and inputs exactly, which may be challenging without proper instruction. Additionally, the monochrome output and reliance on textual input can make error detection and documentation harder, potentially hindering learning. The educational context may benefit from visual aids or GUI elements to keep students engaged and facilitate comprehension .

The main components required include defining a main control structure (such as a `while` loop) to continuously display the menu until the user chooses to exit. The program needs to handle user input, switch statements to determine actions based on the input, and functions to calculate different operations (in this case, areas of geometric shapes). An exit option should also be implemented to end the loop gracefully .

También podría gustarte