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.   References: Please see http://www.cplusplus.com/reference/cctype/ (Links to an external site.) to learn more about using the isalpha, tolower, and toupper functions.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter8: Advanced Method Concepts
Section: Chapter Questions
Problem 8RQ
icon
Related questions
Question

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.  

References: Please see http://www.cplusplus.com/reference/cctype/ (Links to an external site.) to learn more about using the isalpha, tolower, and toupper functions.

Example runs (two separate runs shown):

 

 

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());

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,