CISC 1115
Introduction to Modern Programming Techniques
Lab #1
Review

How to Develop and Submit your Labs

Lab 1.1 (Lab 6.6 in the 1115 labs) — Fun with Numbers (InfoOf3) (Approval)

Write a program that reads three numbers from the keyboard, and then prints out some information about the relationships between the numbers-- whether they are all equal, in ascending order, in descending order, and so on. To determine these relationships, write the following boolean-valued functions: Try to "talk boolean" — i.e., use boolean variables and conditional operators rather than if statements where possible

Sample Test Run

first number? 1
second number? 2
third number? 3
allAreEqual: false
twoAreEqual: false
noneAreEqual: true
areAscending: true
areDescending: false
strictlyAscending: true
strictlyDescending: false

Lab 1.2 (Lab 9.5 in the 1115 labs) — Calculating Averages (Averages)

The file numbers.text conisits of sequences of numbers, each sequence preceded by a header value nd then followed by that many integers. Read in the sequences and print their averages. When all sequences have been read in, print out the number of sequences processed.

Sample Test Run

For example if the file numbers.text contains:

3 1 2 3
5 12 14 6 4 0
10 1 2 3 4 5 6 7 8 9 10
1 17
2 90 80
the program should produce the following output:
The average of the 3 integers 1 2 3 is 2.0
The average of the 5 integers 12 14 6 4 0 is 7.2
The average of the 10 integers 1 2 3 4 5 6 7 8 9 10 is 5.5
The average of the 1 integers 17 is 17.0
The average of the 2 integers 90 80 is 85.0
5 sets of numbers processed

Lab (1.3) (Lab 10.4 in the 1115 labs) — Finding the Last Occurrence of a Value in a File (FindLast)

Write a program that prompts the user (at the keyboard)for a value and searches the file numbers.text for that value, printing out the last position where the number appears in the file (the first number in the file is at position 1). If the number does not appear in the file, print out an appropriate message. Continue asking the user for values until they signal end-of-file (i.e., in Windows one enters end-of-file at the keyboard by entering Ctl-Z, in Unix end-of-file is indicated by entering Ctl-D). The logic is the same as end-of-file for a disk file-- i.e., if your Scanner variable is named 'keyboard', you would have the loop condition 'while (keyboard.hasNextInt())'.

Sample Test Run

For example if the file numbers.text contains:

10
23
43
5
12
23
9
8
10
1
16
9
execution of the program should look like:

Enter a number: 10
10 last appears in the file at position 9
Enter a number: 29
29 does not appear in the file
Enter a number: 9
9 last appears in the file at position 12
Enter a number:

Some Guidance and Notes

Lab 1.4 (Lab 12.1 in the 1115 labs) — Array Information (ArrayInfo) (Approval)

The file numbers.text contains a header value, followed by that many double values. Create an array of the appropriate size, populate the array with the doubles, and print out various information about the array (see below).

Sample Test Run

For example if the file numbers.text contains:

8
12.3
2.5
9.4
3.14
22.15
17
54.3
7.6
the program should produce the following output:
The array: {12.3, 2.5, 9.4, 3.14, 22.15, 17.0, 54.3, 7.6} contains 8 elements
The first element of the array is 12.3
The last element of the array is 7.6 and is at position 7
The middle element of the array is 3.14 and is at position 3
The largest element of the array is 54.3 and is at position 6
The smallest element of the array is 2.5 and is at position 1
Notes:
  • Reading in data using a header value
  • More practice with arrays
  • 'Muscle-memory practice for comma logic
  • A variation on the max method; this also emphasizes the distinction between the value of the element and its index (position/location within the array).
  • This exercise is marked for 'Approval' because:
    • Again, there are several methods I want to make sure you're using
    • I just want to see your programming style