0% found this document useful (0 votes)
25 views15 pages

Computer Programming Work Overview

1. The document is a computer programming work presented by engineering students from FEAMIG in 2015. 2. The work contains solved exercises in computer programming. 3. The questions cover topics such as compilers, interpreters, algorithms, and variables.
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)
25 views15 pages

Computer Programming Work Overview

1. The document is a computer programming work presented by engineering students from FEAMIG in 2015. 2. The work contains solved exercises in computer programming. 3. The questions cover topics such as compilers, interpreters, algorithms, and variables.
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

MINAS GERAIS SCHOOL OF ENGINEERING - FEAMIG

Cândida de Souza Educational Institute

Bianca Gonçalves
Cristiane Assis
Deisiane Rodrigues
Nikolas Gonçalves
Nikokas Seixas

COMPUTER PROGRAMMING WORK

BELO HORIZONTE

2015
MINAS GERAIS SCHOOL OF ENGINEERING - FEAMIG

CÂNDIDA DE SOUZA EDUCATIONAL INSTITUTE

Computer Programming Work

Work presented to the Discipline,


COMPUTER PROGRAMMING, from
2nd Period of the Engineering Course
Production of the Faculty of Engineering
from Minas Gerais - FEAMIG to
consolidation of knowledge and
acquisition of credits Professor: Paulo
Isnard.

Belo Horizonte

2015

2
SUMMARY

1. Introduction...................................................................................................4
2. Resolution of the Exercises....................................................5
2.1 Exercises
3. Conclusion...................................................................................................14
15

3
1. Introduction

Programming is the process of defining, using a programming language,


the commands and the instructions that the computer must execute to perform
certain task.

An algorithm is, in a certain sense, an abstract program stating otherwise,


a program is a concretized algorithm. However, programs are, to
exceptions of minors, more easily viewed as a collection of
combined smaller algorithms in a unique way like a house
is built from components.

In this way, an algorithm is a description of how a computer can be


led to perform a simple and specific operation, such as, for example, a
ordering. A program, on the other hand, is an entity that actually
implement one or more operations in a way that is useful for people.

4
2. Resolution of Exercises
(1, 2, 3, 4, 5, 11, 12, 13, 14, 15, 26, 27, 28, 29,30)
2.1 What is a Compiler, what is it for? Give an example.

The compiler is a translator of programs written in a language of


programming for machine language programs. It serves to
translate programs written in high-level languages to languages of
machine. An example of a compiler is Pascalzim.

2.2 What is an Interpreter? Are there advantages over the


Compiler? Which ones?

An interpreter is a program that executes other programs written in some.


programming language. Yes, there are advantages over the Compiler. The
the interpreter does not have to worry about optimization issues and generally
processes programming languages that are structurally less rich than the
Compiler. Easy to implement, the interpreter ensures greater speed in
edit/compile/run cycle, and allows for testing/modifying programs as needed
that are executed.

2.3 What is the difference between High-Level and Low-Level Language?

Provide an example.

High-level language is a language better understood by


programmer and low-level language is the language read by the computer.
Example of high-level language: Java; Visual Basic; Delphi.
Example of low-level language: C; Assembly.

2.4 Define, in your own words, what a logarithm is. Without doing
algorithm, can you program yourself?

An algorithm is similar to a cake recipe, it operates on a set of


ingredients (flour, eggs, yeast, etc.) in order to generate a pleasant output
for the user (the cake is ready). It is not possible to program without an algorithm, because the

the algorithm is present in our daily lives without us realizing it.


5
2.5 Cite, explain and exemplify 03 characteristics of
algorithms.

Definition - Each step of an algorithm must be precisely defined. The


actions must be defined rigorously. Example: Define that you will do the
speak.
Inputs: An algorithm must have zero or more inputs, that is, quantities
that are provided to you before the algorithm starts. Example: flour, eggs,
ferment, etc.
Outputs: An algorithm must have one or more outputs, that is, quantities that
there is a specific relation with the inputs. For example: the cake is ready.

2.11. Describe what Algorithm Refinement is. Give 02


examples.

Refinement of algorithms is the act of unfolding commands of an algorithm that


they do not have a clear interpretation, in new commands until it can be good
interpreted.
Algorithm - Change a light bulb
Start
Take a ladder;
Go up the stairs;
Change the light bulb;

Film.
Algorithm - Change a light bulb (After refinement)
Start
Take a ladder;
Go up the stairs;
Remove the burnt-out bulb;
Put in the new bulb;
Get down from the stairs;

Discard the burnt-out bulb;


End.
Algorithm - Take a shower
6
Start
Go into the bathroom;
Cover the body;
Here is the body;
The end.
Algorithm - Taking a shower (After refinement)
Start
Go into the bathroom;
Take off the clothes;

Turn on the shower;


Take the soap;
Get the body ready;
Save the soap;
Rinse the body;
Turn off the shower;
Dry the body;
Film.

2.12. What is the format of the Basic Structure of an Algorithm?

When we work on constructing an algorithm, we must follow a


predetermined order. The construction of an algorithm follows the following order:

1. Program name;

2. Inclusion of the libraries used;

3. Declaration of global variables;

4. Creation of procedures;

5. Program start indicator (Begin);

6. Main code;

7. Program end indicator (End).

7
2.13. Fill in the appropriate Data Type and complete with a
observation. See Example.

Data Type Observation

Long (Uses 4 Bytes for storage) See slide


2147438602 Integer 3.

0.03 Real Uses 4 bytes for storage. See slide 4

F Literal Use 1 byte for each character. See slide 6

-36 Integer Uses 2 bytes for storage. See slide 2

V Name It starts with a letter. See slide 8

45329876430 Integer Long (Uses 4 bytes for storage. See slide 3)

- 32769 Whole Uses 2 bytes for storage. See slide 2

FALSE Name It starts with a letter. See slide 8

65.2365 Real Uses 4 bytes for storage. See slide 4

.V. Logical Uses 1 byte for storage. See slide 7

..F.. Logical Uses 1 byte for storage. See slide 7

Feamig Literal Use 1 byte for each character. See slide 6

10/12/204 Literal Use 1 byte for each character. See slide 6

8
2.14. Create the appropriate variables for the values below:
2.14.1. 12345 -Integer
2.14.2. 123.45 -Real
2.14.3. 1.23456 - Real
2.14.4 1549122 - Integer
2.14.5. X10 - Name
2.14.6. . TRUTH. -Logical
2.14.7. . V. -Logical
2.14.8. 812345605 - Integer

2.15. Fill in V (True) or F (False) for the Names of


Variables and the justification of your answer. See example.

Name Yes
Variable T or F Justification

Base Salary F The use of hyphen "–" is not allowed. See slide 9.

August V Starts with the letter e and is not a reserved word. See slide 9

1 dollar
day V It must start with a letter, it cannot start with a number. See slide 9

result 2 F It must start with a letter, it cannot start with an underscore. See slide 9

_2 result F It must start with a letter, it cannot start with an underscore. See slide 9.

auxiliary F It must start with a letter, it cannot start with an underscore. See slide 9.

Procedure F Reserved Word. See slide 9

Base salary V Starts with a letter, underscore is allowed. See slide 9

9
2.26. Create an algorithm that calculates the factorial of n (n!). Explain it.
reasons that led him to choose the structure used.

Algorithm 'Factorial'
Var
n
Start
Type a number
Read n;
For i from 1 to n do
Start
factorial := factorial * i;

The factorial of, n, is: factorial


Film;
End.
We chose to use 'for' because in our opinion it was easier, and the algorithm became
but more reduced.

2.27. What are logical expressions? When should we use them?

Logical expressions are operations between logical values, the result of which is
logical. The expressions are:
No - It is used when there is a need to invert the logical result of a
a certain condition. Example: If 2 plus two equals 4, true, otherwise false.
Or - It is used when at least one of the relationships in the condition is required.
to be true. Example: If condition 1 is true or condition 2 is true,
your result will be true.
E - It is used when two or more expressions in the condition need to be
true. Example: If condition 1, condition 2, and condition 3 are
true, your result will be true, otherwise it will be false.
Logical expressions are used in the decision-making of the program.

10
2.28. Create an algorithm that calculates and writes the value of the sum

where?

Sum = 1/1 + 3/2 + 5/3 + 7/4 + ... 99/50


Program EX28
Var
Cont1, Cont2, result: integer;
Start
Write 'Program EX28';
Displays the value of the sum
Cont1:=1;
Cont2:=1
To count from 1 to 99 do
Cont1/Cont2:= result;
Cont1 := Cont1 + 1;
Write "result", result;
Film;
Film.

2.29. Construct the table for each of the logical expressions


mentioned above.

Table of no

Condition 1 Result

True True

False False

Table of or:

Condition 1 Condition 2 Result

False False False

11
True False True

False True True

True True True

Table of the e:

Condition 1 Condition 2 Result

False False False

True False False

False True False

True True True

2.30. Create a structured algorithm that reads a list of letters


finished by the letter z. In the end, the algorithm should show the
amount read of each vowel.

Program EX30
Var
int
Literal
Start
Write "Enter a letter"
While letter <> Z do
Read lyrics;
If letter = A then cont1 := cont1 + 1 or
If letter = E then cont2 := cont2 + 1 or
If letter = I then cont3 := cont3 + 1 or
If letter = O then cont4 := cont4 + 1 or
If letter = U then cont5 := cont5 + 1 else
12
Cont:= cont +1;
Film;
Write 'A', cont1;
Write "And" cont2;
Write 'I', cont3;
Write "O", cont4;
Write 'U', count 5;
End.

13
3. Conclusion
In this work, it was possible to gain a little more knowledge about algorithms and
Programming and its applications in our daily lives. We realize the importance of
algorithm and we understand that it is fundamental in planning,
development of any program.

14
4. Bibliography

BRAZILIAN ASSOCIATION OF TECHNICAL STANDARDS. NBR 14724: information and


documentation: academic works and presentation. 2nd ed. Rio de Janeiro: 2006.

FARRER HARRY FARIA C. E, MATOS F. HELTON, SANTOS A. MARCOS, MAIA


L. MIRIAM. Algorithms and Data Structure.

LAGES NEWTON and GUIMARÃES ÂNGELO. Algorithms and Data Structures. Rio
Rio de Janeiro: Scientists Ed. LTDA, 1992, single volume.

PAULO ISNARD. Algorithms and Data Structures Introduction (Handout).

15

You might also like