LAB 1:structural Programming: Yeditepe University
LAB 1:structural Programming: Yeditepe University
LAB 1:structural Programming: Yeditepe University
ACM 321
Object oriented Programming
February 5, 2016
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
Engin Kandran
Introduction
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:
[email protected] or
[email protected]
Engin Kandran
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
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!
Engin Kandran
Homework 1
4.1
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
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: