Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

Exercises

 

1: One-D Array

2. One D-Array

3. One-D Array

4. 2-D Array

5. Knight's Tour

6. Array of Objects

7. Two-D Array

 

 

 

Exercise 1

 

Create an array of 100 random integers in the range 1 to 100

Print the elements of the array, appropriately labeled, 10 elements per line

 

Exercise 2

 

      Formulas for the mean, median, mode, and standard deviation are given below.  The elements are denoted by x and the number of elements is given by n. i refers to the individual elements.

 

Requirements

Ø In the main method, create a one-dimensional array of 100 random integers in the range 20 to 40, including the end points.

Ø Call a method named printArray that will print the elements of the array, 5 per line

Ø Call a method named findMean that will find and return the mean

Ø Call a method named findMode that will find and return the mode. If the mode does not exist it will return an appropriate indication

Ø Call a method named findSD that will find and return the standard deviation

Ø Call a method named printResults that will print, appropriately labeled, the mean, mode (if does not exist than an appropriate statement), and standard deviation

 

Find and print, appropriately labeled, not in a message box the following: Mean, Mode, and Standard Deviation

 

Mean

 

 

In plain English: Add them and divide by the number of them.

 

Median

 

   

 

In plain English: Valid only if sorted. If number is odd, median is the one in the middle. If the number is even, median is the sum of the 2 in the middle divided by 2.

 

Mode

 

The value that occurs most often.

It may not exist, and if it exists, it may not be unique.

 

In plain English: The above is, I think, clear.

Standard Deviation

The standard deviation is given by the square root of the variance, defined as follows.

In plain English: First, find the mean as discussed above. Then, for each element, find the difference between it and the mean and square the difference. Then sum all of these differences. Finally, divide by the number - 1. The standared deviation is then the square root of this number.

Exercise 3

Use a console application for this lab

¢ In the main method

      Ø Create a one-dimensional array of 100 random integers, each of which is between 1 and 200, including the end points.

      Ø Call a method named printElements that will print the elements of the array, 10 per line

      Ø Call a method named findIt that will search for the integer.

            If it is found, it will print the cell in which the first instance occurs.

            If it is not found, it will announce that the integer is not in the array.

Exercise 4

Use a console application for this lab

¢ In the main method

      Ø Create a one-dimensional array of 100 random integers, each of which is between 1 and 200, including the end points.

      Ø Call a method named printElements that will print the elements of the array, 10 per line

      Ø Call a method named bubbleSort that will sort the elements, smallest to largest

      Ø Call a method named printElements that will print the sorted elements, 10 per line

      Ø Prompt the user to enter an integer

      Ø Call a method named findIt that will search for the integer.

            If it is found, it will print the cell in which the first instance occurs.

            If it is not found, it will announce that the integer is not in the array.

¢ Write the methods printElements, bubbleSort, and findIt as described above.


 

Exercise 5

 

Modeling a forest fire: Use a Console Application: Turn in when all parts completed.

 

Part a

¢ Create 2 classes with the following names

     Trees

     Shrubs

¢ Note: In an actual problem additional classes would be created and placed in the array (Break, for example) an

     additional classes created but not placed in the array (Environment class, for example)

 

Part b:

¢ Include data members for the Tree class as follows

     An integer variable named FireBurnRate. This variable takes values 4, 5, or 6

     A double variable named Height. This variable takes values from 1.0 to 100.0

¢ Include data members for the Shrub class as follows

    An integer variable named FireBurnRate. This variable takes values 1, 2, or 3

    A double variable named Height. This variable takes values from 1.0 to 3.0

 

Part c:

Provide code in the main method that will

¢ Create a two - dimensional array named forest with 60 rows and 60 columns.

¢ Prompt the user to enter the FireBurnRate and Height. Provide code to check verify that values entered are

      appropropriate and provide an error message until an acceptable value is entered.

¢ Populate the array so that objects of the Tree class are on rows with even element numbers (trees on rows 0, 2, 4, etc.)

      objects of the Shrub class are on rows with odd element numbers  9shrubs on rows 1, 3, 5 etc) except

 

Part d:

¢ Print the FIreBurnRate for the first 5 items on row 1

¢ Print the Height for the first 5 items on row 2