ITI 1220 Fall 2005 - Assignment 4

Available: Friday September 30
Due: Tuesday October 11, noon (NOTE:  Unusual day due to Thanksgiving holiday)

Instructions

This assignment is to be done in TEAMS OF TWO PEOPLE. The assignment should be submitted only once by a member of your team, but please ensure that the identification material contains the information for both team members. Follow the instructions in the lab manual for submitting assignments.

Your algorithms should be developed using the format used in class. Your algorithm traces should use the format shown in class; a separate table is to be used for each call to each algorithm. Programs should be based on the template file, and should follow good coding practices as described in the course lab manual.

Marking Scheme (total 100 marks)

Question 1 (10 marks)

In this question, you should use the algorithm format for Boolean expressions.  Keep in mind the difference between a Boolean expression, and a test used in a branch or loop.  You need only to write the expression (example:  A (B + 3) ), and not a branch structure.

 

The Boolean expressions that you write for this question should use only the comparison operators (<, >, =, etc.), Boolean operators (AND, OR, NOT), and math operators +, , ×, /, or MOD.  Use parentheses where necessary.


Question 1a)

 

Student participants in the 2005 ACM intercollegiate programming contest must satisfy the criteria listed below, based on the following variables for a student:  IsFullTimeStudent, PreviousContestParticipations, FirstUniversityYear, Age, and NumberOfSemesters.

 

The eligibility criteria are:

 

 

Write a Boolean expression that will be true if a student can participate in the contest, and false otherwise.

 

Question 1b)

 

Suppose that you have three numbers A, B, and C, which are greater than zero.  Write a Boolean expression that is true if any of the three numbers is evenly divisible by at least one of the other two numbers.

 

Question 2 (10 marks)

In this question, you should use the Java format for Boolean expressions.  Keep in mind the difference between a Boolean expression, and a test used in an if statement.  You need only to write the expression (example:  A <= (B + 3) ), and not the complete if statement..

 

The Java Boolean expressions that you write for this question should use only the comparison operators (<, >, ==, etc.), logical operators (&&, ||, !), and math operators +, , *, /, or %.  Use parentheses where necessary.

 

Question 2a)

 

Suppose that day is an integer variable with value 1 through 7, where 1 represents Sunday, 2 represents Monday, and so on through to 7 representing Saturday.  Another variable, hour, is an integer from 0 to 23.  Finally, there is a Boolean variable holiday, which is true on days that are holidays.

 

The ITI 1220 professor is usually on campus from 10 a.m. until 7 p.m. on Mondays through Fridays, except on holidays.  Write a Boolean expression that is true if the ITI 1220 professor would be on campus, and false otherwise.

 

Question 2b)

 

The rules for passing the course ITI 1220/1620 are as follows:

 

 

Suppose that you have the variables assignAverage, midterm, and exam representing the corresponding values for a student and all three values are numbers between 0.0 and 100.0.  Write a Boolean expression that will be true if the student passes the course, and false otherwise.


Question 3 (30 marks)

 

Implement the algorithm from Assignment 3, question 1a) – that is, the calculation of federal tax from income – in Java.  The algorithm diagram will be made available on Monday Oct. 3, after the assignment 3 deadline.

Question 4 (40 marks)

A company records historical data for the amount of sales (measured in millions of dollars) of their products for each month.  The sales amount for each month has already been stored in an array Sales, with length NumMonths.  Note that the monthly sales record could extend for several years, and you should not assume the array has size 12.

 

The company’s management is interested in finding out whether the sales trend is good or not, and you have been asked to find the answer to the following question:  What is the largest number of consecutive months for which sales have increased from one month to the next? 

 

For example, suppose that for a period of 12 months previously, the sales were:

 

{5, 4, 6, 8, 8, 9, 11, 13, 12, 14, 15, 14}

 

The answer to the question would be 4 for the above sales figures, for the set of months with sales {8, 9, 11, 13}

 

Question 4a)

 

Design an algorithm that will determine the largest number of consecutive months for which sales have increased from one month to the next, using an array containing sales in millions of dollars.

 

Question 4b)

 

Trace your algorithm on the following array of sales:

 

{12, 14, 13, 18, 19, 20, 19, 24}