CST1620 C# / C++ Programming
Lab Week 6


Exercises

Exercise 7.1 Sentence Generation (10 points)

Write a program that uses random number generation to create sentences.  Use four arrays of Strings called article, noun, verb and preposition.  Create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article and noun.  As each word is picked, concatenate it to the previous words in the the sentence.  The words should be separated by spaces.  When the sentence is output, it should start with a capital letter and end with a period.  The program should generate 20 sentences and output them to a Listbox.

The arrays should be filled as follows:

article noun verb preposition
the boy drove to
a girl jumped from
one dog ran over
some town walked under
any car skipped on

Hint:
Example sentences would be:

One car jumped on the dog.
The girl ran under some car.

 

Exercise 7.5 Array List (10 points)

Use a single-subscripted array to solve the following problem:  Input 20 numbers, each of which is between 10 and 100, inclusive.  As each number is read, print a message stating if the number is a unique number or that it is a duplicate of a number already entered.  Provide for the "worst case" in which all 20 numbers are different.  Use the smallest possible array to solve this problem (the array size is 20 elements).

Notes:  I will be checking that you reject any numbers that are not 10 to 100 inclusive.  I will check that you stop accepting after reading 20 numbers.

  Result (Save to your local machine and run)

 

Exercise 15.4 Transpose EC (Extra Credit 10 points)

The transpose of an array is the technical term used to describe swapping the elements in an array across one of the diagonals. The numbers on the diagonal do not change. So if an array is: 

1

2

3

4

6

7

8

9

10

11

12

13

14

15

16

17

 

then its transpose is: 

1

6

10

14

2

7

11

15

3

8

12

16

4

9

13

17

Write a program to input the elements of an array in the same manner as the rainfall program. It transposes the array when a button is clicked, and displays it.