0% found this document useful (0 votes)
35 views3 pages

Algorithms and Data Structures - Case Selection Structure

The document explains the CHOOSE...CASE decision structure used for testing conditions in programming, providing syntax and flow of execution. It includes exercises for creating a simple integer calculator and a main menu program, as well as a task for classifying athletes based on age. The document emphasizes the importance of faith in life, suggesting that losing it leads to ruin.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views3 pages

Algorithms and Data Structures - Case Selection Structure

The document explains the CHOOSE...CASE decision structure used for testing conditions in programming, providing syntax and flow of execution. It includes exercises for creating a simple integer calculator and a main menu program, as well as a task for classifying athletes based on age. The document emphasizes the importance of faith in life, suggesting that losing it leads to ruin.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Algorithm and data structure 06

A human being can lose everything in life, but if they lose faith, certainly
will be ruined.

Script

1.Case structure
2.Exercises

STRUCTURE CHOICE...CASE

The decision structure CHOOSE...CASE is used to test a condition,


in a single expression that generates a result or the value of a variable that is found
saved in a certain content.

In this structure, there can be one or more conditions to be tested and a


a different command associated with each of these.

Syntax:

CHOOSE <Expression of choice>


CASE condition1
Command1
CASE condition2
Command2
CASE condition3
Command3
OUTROCASE
Command A
FIND YOUR CHOICE

This structure occurs as follows:

When entering this type of CHOICE structure, condition1 is tested with the
variable: if it is TRUE, execute command1 and, after its completion, the flow of
execution continues with the first instruction after the end of the construction (ENDCHOICE);
If condition1 is FALSE, condition2 is tested, and if this is TRUE, the
command2 is executed and, upon completion, the execution continues with the next instruction
at the end of the construction (FIMESCOLHA). This same reasoning is applied to all of the
construction conditions. If by chance all conditions are evaluated as
FALSE, the Command A, which corresponds to the ELSE of the construction, is executed.

SOLUTION EXERCISE:

1) Through the multiple-choice structure, create an algorithm to simulate a


simple integer calculator.

Resolution:
Calculator algorithm
Var
X,Y: Integer;

Page 1 of 3
Algorithm and data structure 06

Operator: Character;
BEGINNING
Write("Enter X:"); Read(X);
Write("Type Y:"); Read(Y);
Write('Enter the Operation:'); Read(Operator);
CHOOSE Operator
CASE '+'
Write(X + Y)
CASE ‘-’
Write(X - Y)
CASE '*'
Write(X * Y)
CASE '/'
Write(X / Y)
OUTROCASE
Write("Invalid operation");
ENDCHOICE
FIMALGORITHM

FIXATION EXERCISE

1) Main menu - Create a menu program that


show on the screen, under the title "Main Menu", three
opções: "1 - Fim", "2 - Cadastro" e "3 - Consulta", lê
selects the desired option by the user from the keyboard and shows it
a message confirming the chosen option or
an error message, if the option is invalid.
2) Multiple choice 1 - Develop a multiple choice question, of a
subject you are taking or a topic of interest, with a statement and
five alternatives, with one correct or incorrect. Write a program that
display the question on the screen, asks for the correct answer and informs the user if this
Got it or got it wrong.

3) Multiple choice 2 - Enrich the program above the multiple choice question
choose, including another question on a different topic. At the beginning of the program,
offer the user the choice of which question they want to answer.

A certain football club intends to classify its athletes into categories.


and for this he hired a programmer to create a program that would execute
this task. To do this, the club created a table that contained the age range of
athlete and their category. The table is shown below:

AGE CATEGORY
From 05 to 10 Children
From 11 to 15 Youth
From 16 to 20 Junior

Page 2 of 3
Algorithm and data structure 06

From 21 to 25 Professional

Build a program that requests the name and age of an athlete and prints it.
your category.

Page 3 of 3

You might also like