Vous êtes sur la page 1sur 8

Yeditepe University

ACM 321
Object oriented Programming

LAB 1:Structural Programming


Course Assistant:
Engin Kandran

February 5, 2016

LAB 1:Structural Programming

Engin Kandran

Contents
1 Introduction

2 Lab Materials

3 Assignment 1
3.1 Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Function List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4
4
4

4 Homework 1
4.1 Finding Maximum and Minimum Values . . . . . . . . . . . . . . . .

6
6

LAB 1:Structural Programming

Engin Kandran

Introduction

Structured programming is thought to be a programming without use of the GOTO


statement. To fully appreciate the definition, however, one must understand the full
extent of the problem addressed by structured programming.
In a word, this problem is complexity. Most programs that do anything significiant in
the real word are rather long. Of course, such software as word processors, compilers
or operating systems stagger the imagination. In fact, some computer scientists
claim that these very large software systems are the most logically complex things
humans have ever invented. However, even programming of only several hundred
lines can get unwieldy, and it is difficult to keep all the details of the program in the
mind at one time.With really large software systems, it is impossible.
Complexity is precisely the problem that structured programming addresses. Indeed,
one author has defined structured programming as follows: a method of designing
computer system componets and their relationships to minimize complexity.
How does structured programming minimize complexity? It does so in three ways,
which will serve as the full, working definition of the structural programming.
Structural programming a method of writing a computer program that uses (1) topdown analysis for problem solving, (2) modularization for program structure and
organization, and (3) structured codes for the individual modules.
FOR EMPHASIS
Structural Programming:
Top-down analysis of problem solving
Modularization for program structure and organization
Structured codes for each modules.
I hope that you find this explanations useful for understeanding the reaasoning behind structural programming.

LAB 1:Structural Programming

Engin Kandran

Lab Materials

You can download the all necessary materials which are covered during the lecture
and lab hours is going to be downloaded from:
ACM 321 Folder Link
You are going to open WEEK 1 folder in the given address. For the assignment given
for this lab hours, you are responsible for completing the solution of the assigned
problem to you at the end of the each lab lectures. The assignment done after the
given time will not be graded.In addition to exercises given in the lab, an extra
homework question is going to be assigned to you. For this second assignment, you
have a one week to complete it.(up to next lecture day.)
You are going to send your solutions to following e-mail address:
engin.kandiran@outlook.com or
engin.kandiran@gmail.com

LAB 1:Structural Programming

Engin Kandran

Table 1: Grade Policy


Total Weighted Score Grade
<60
FF
>=60 and 70<
DD
>=70 and 80<
CC
>=80 and 90<
BB
90<
AA

Assignment 1

3.1

Problem Statement

A program is needed to help a college to grade its students. A total weighted score
is determined for students from two midterm exam scores both weighted at 30%,
and a final exam score at 40%.
For each student, the program is to output the student number, the total weighted
score and the grade assigned. It is also required to count the number of students
receiving each of the five grades. The input will be in the form of a record, each
consisting of student number, midterm test 1, midterm test 2 and final test mark.
The iteration is to be terminated by a suitable dummy record. The summary will
then be printed showing the distribution of the grades.The grading policy is given
in Table 1.

3.2

Function List

Initialize all variables, counters


Get first record
Input record
Total Weighted score = 30% x Midterm Test 1+ 30% x Midterm Test 2 +
40% x Final Test
Assign grade
Increase Counter AA by 1
Increase Counter BB by 1
Increase Counter CC by 1

LAB 1:Structural Programming

Engin Kandran

Increase Counter DD by 1
Increase Counter FF by 1
Print Student Number, Weighted Score and Grade.
Get next record
Print Summary Record
End Program
Good Luck!

LAB 1:Structural Programming

Engin Kandran

Homework 1

4.1

Finding Maximum and Minimum Values

A common task that must be done in a loop is to find the maximum and minimum
of a sequence of values. The file Temps.java contains a program that reads in a
sequence of hourly temperature readings over a 24-hour period. You will be adding
code to this program to find the maximum and minimum temperatures. Do the
following:
1. Save the file to your directory, open it and see whats there. Note that a for
loop is used since we need a count-controlled loop. Your first task is to add code
to find the maximum temperature read in. In general to find the maximum of
a sequence of values processed in a loop you need to do two things:
You need a variable that will keep track of the maximum of the values processed so far. This variable must be initialized before the loop. There are
two standard techniques for initialization: one is to initialize the variable
to some value smaller than any possible value being processed; another is
to initialize the variable to the first value processed. In either case, after
the first value is processed the maximum variable should contain the first
value. For the temperature program declare a variable maxTemp to hold
the maximum temperature. Initialize it to -1000 (a value less than any
legitimate temperature).
The maximum variable must be updated each time through the loop. This
is done by comparing the maximum to the current value being processed.
If the current value is larger, then the current value is the new maximum.
So, in the temperature program, add an if statement inside the loop to
compare the current temperature read in to maxTemp. If the current
temperature is larger set maxTemp to that temperature. NOTE: If the
current temperature is NOT larger, DO NOTHING!
2. Add code to print out the maximum after the loop. Test your program to
make sure it is correct. Be sure to test it on at least three scenarios: the first
number read in is the maximum, the last number read in is the maximum, and
the maximum occurs somewhere in the middle of the list. For testing purposes
you may want to change the HOURS PER DAY variable to something smaller
than 24 so you dont have to type in so many numbers!
3. Often we want to keep track of more than just the maximum. For example,
if we are finding the maximum of a sequence of test grades we might want

LAB 1:Structural Programming

Engin Kandran

to know the name of the student with the maximum grade. Suppose for
the temperatures we want to keep track of the time (hour) the maximum
temperature occurred. To do this we need to save the current value of the hour
variable when we update the maxTemp variable. This of course requires a new
variable to store the time (hour) that the maximum occurs. Declare timeOfMax
(type int) to keep track of the time (hour) the maximum temperature occurred.
Modify your if statment so that in addition to updating maxTemp you also
save the value of hour in the timeOfMax variable. (WARNING: you are now
doing TWO things when the if condition is TRUE.)
4. Add code to print out the time the maximum temperature occurred along with
the maximum.
5. Finally, add code to find the minimum temperature and the time that temperature occurs. The idea is the same as for the maximum. NOTE: Use a
separate if when updating the minimum temperature variable (that is, dont
add an else clause to the if that is already there).
Figure 1:

Vous aimerez peut-être aussi