Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this lab, you will demonstrate your understanding of basic C++. There are 2 programs to be completed. All files require Javadoc documentation comments at

In this lab, you will demonstrate your understanding of basic C++. There are 2 programs to be completed. All files require Javadoc documentation comments at the top to include a description of the program and an @author tag with your name. Note: Your output does not need to match the samples shown.

1. Write a program that reads a word at a time and determines whether the word begins with a vowel, a consonant or something else such as a number. Words are repeatedly accepted until the word quit is entered. The program should then output a count of the number of words read that begin with a vowel, the number of words read that begin with consonants and the number of words read that fit neither of those categories (numbers).

Hints: One or more spaces, tabs or enter keys will terminate input using cin. Therefore, each cin will read one word. Parsing the input stream is not needed. Instead, include the cin statement in the loop that processes a word and continues until the word read is "quit".

String objects can be used as character arrays; the first character of a string is the element at index location 0 while the second character is the element at index location 1.

The function isalpha accepts a single character as a parameter and returns a Boolean indicator as to whether or not the character is a letter. The functions toupper and tolower accept a single character as a parameter and return the character converted to upper or lower case.

image text in transcribed

2. Create an application for generating lottery tickets of random numbers. Each lottery ticket has a fixed count of numbers to be played with each number selected being within a given range. For example, when the range of numbers is 1 through 100, and 5 numbers are to be played, the lottery ticket will be composed of 5 unique values between 1 and 100. The values are selected at random.

The main function is responsible for obtaining the upper range of the numbers and the count of numbers to be played from the end user. The count of numbers must be less than the upper range. The main function will call the generateLotto function to generate the lottery ticket and then call the displayTicket function to display the resulting lottery ticket. Any number of lottery tickets may be generated.

The generateLotto function should accept two parameters. The first should be the upper range for the numbers while the second parameter represents a count of the numbers to be played. For example, lotto(51, 6) will select 6 numbers at random between 1 and 51 (inclusive.) The function should return a vector of unique integer values in sorted order.

The displayTicket function accepts a vector of integers and displays the vector.

Hints: Although the standard library defines a rand() function for generating random numbers, the function may produce duplicate numbers and hence, is not suitable for this application. To ensure that unique values are generated, create a vector that contains all possible values (1 through the given upper range) and then shuffle these values using the random_shuffle() function. This will result in a vector of numbers between 1 and the upper range in random order. From this vector, select the required number of values from the beginning of the vector, adding these values to the result vector. Lastly, use the sort() function to sort the result vector.

The random_shuffle() and sort() functions require two parameters that specify the beginning and ending elements on which to operate. To specify the beginning and ending of the vector, the begin() and end() methods of the vector class can be used. For example, when the vector allNumbers contains all the values between 1 and 51, the values within the vector can be rearranged (shuffled) using:

random_shuffle(allNumbers.begin(),allNumbers.end());

image text in transcribed

Enter words (quit to end): A cat jumped over the dog! quit 2 words begin with a vowel 4 words begin with a consonant 0 other words' were found Enter the highest number: 51 How many numbers should be generated? 6 Your randomly generated ticket: 1 2 10 13 28 50 Do you want to generate another ticket? (Y or N): y Enter the highest number: 51 How many numbers should be generated? 6 Your randomly generated ticket: 2 24 30 35 37 39 Do you want to generate another ticket? (Y or N): Y Enter the highest number: 21 How many numbers should be generated? 4 Your randomly generated ticket: 6 10 11 14 Do you want to generate another ticket? (Y or N): n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

=+Which options are in-the-money and which are out-of-the-money?

Answered: 1 week ago

Question

5. How do instructional objectives help learning to occur?

Answered: 1 week ago