top of page

Resolution of the exercises proposed in the 1st edition of UERJ Geophysical Society MAGAZINE

Exercise 1

Develop a narrative description algorithm that tells you how to take a test. Do the algorithm thinking that the student should not leave questions blank, so keep testing as long as there are blank questions and the test time is not over. In addition, the student should only solve a question if he knows how to solve it, or skip to the next.

 

Resolution:

1. Take the test;

2. Take the pen;

3. Sit in the chair;

4. Read the whole proof;

5. While there are blank questions, do:

    6. Read the question;

    7. If you know the answer, then:

        8. Do ask the question;

    9. If not, skip to the next question;

10. Until there are no more blank questions on the test or the test time is not over;

11. Deliver the proof.

 

Note that bold words are standard keywords of an algorithm, which will change the syntax in each programming language, but the meaning of the algorithm is the same.

Exercise 2

Suppose you have a box full of balls. In this box there are blue balls and red balls. In addition, you also have two empty boxes. Let's call the box containing the balls "box 1" and the two empty boxes "box 2" and "box 3". In this context, write a conventional flowchart algorithm that defines how to remove all balls from “box 1” by placing the blue balls in “box 2” and the red balls in “box 3”.

 

Resolution:

gfh.jpg

Remember that there are more than one possible flowchart type to perform the same action. This is just one of several.  

 

Exercise 3

 Joseph works in the human resources department of a company. Joseps's company has defined that employees' salaries will be increased by following the following rule: if the salary is less than $ 1000.00 the increase will be 10% and otherwise it will be 8%. Joseph received a list containing the names and salaries of all employees of the company and was asked to calculate the new salary of these employees. So write an algorithm in Pseudocode so that Joseph correctly calculates the new salaries.

 

Resolution:

Program Increase Salary     

      Variables: EMPLOYEE; CURRENTSALARY; NEWSALARY; ANSWER.

Start        

    Write “Type employee name”;         

    Read EMPLOYEE;         

    Write “What is this employee's current salary?”;         

    Read CURRENTSALARY;        

     If CURRENTSALARY <= 1000, then                

         NEWSALARY = CURRENTSALARY * 1.1;         

    If no,                 

         NEWSALARY = CURRENTSALARY * 1.08;        

    Write “The new salary for” EMPLOYEE ”is:” NEWSALARY;         

    Write “Enter new employee? Yes or no"         

    Read ANSWER;         

    If ANSWER = ”Yes” or ANSWER = ”Y” then                 

          Back to start;         

    If no,         

    End

End       

 

Remember that there are more than one possible pseudocode to perform the same action. This is just one of several.  We have two "End", one for the If algorithm, and one for the program itself. Several times during a program, you will need to Quit so that the computer understands that it should stop reading that command or program. The more detailed rules and most used structures of structured Portuguese will be covered during the next edition.

bottom of page