Question

Answered step-by-step

Asked by jrom239 on coursehero.com

1. C++ For loop program to find the sum, average, range of N non-zero positive integers.

• This program asks user to enter the value of N. Here, N indicates the number of values or terms from which user wants to sum, average, and range. This program then ask user to enter each term or values.

• For example, suppose, a user entered N (number of value or term) as 4. Then the user entered the following four (4) values as: 20, 40, 60, and 80. So, the sum will be 20+40+60+80=200. You need to enter each term/value using for loop. Now calculate the sum.

• For calculating range, you need to subtract smallest number from the largest number.

• Once you get the sum, you can simply divide sum by N; you will get the average value.

__Sample output 1: __

Enter the Value of N: 5

Enter the values: 10 20 30 40 50

Sum:150 Average:30 Range:40

__Sample output 2: __

Enter the Value of N:4

Enter the values: 20 40 60 80

Sum:200 Average:50 Range:60

2. C++ program to read a string from the keyboard, and count number of digits, letters, and whitespaces on the entered string.

• This program asks user to enter string which contains following characters: letters or digits, or whitespaces. The length of the string should be more than 8. You should use getLine() function to read string from keyboard.

• You need to extract each character, and check whether the character is a letter or digit or whitespace.

• You can access character at a specific index using .at() function. Once you have extracted the character, you can test the extracted character using character test methods.

• You can look at google/web search to check the functions (isdigit, isalpha, and isspace) available to test a character. Use the syntax properly in your code.

• Once you found a match, simply increase the value of the counter by 1. You need 3 separate counters to count number of letters, digits, and spaces.

• In this program, you do not need to worry about uppercase or lowercase letter.

__Sample Output 1__

Enter the string: Name of your University

Number of spaces: 3

Number of letters: 20

Number of digits: 0

__Sample Output 2 __

Enter the string: CS 101 Computer science

Number of spaces: 3

Number of letters: 17

Number of digits: 3

__Sample Output 3 __

Enter the string: cbs 123 def

Number of spaces: 2

Number of letters: 6

Number of digits: 3

Solved by verified expert

Answered by vb1395574 on coursehero.com

sectetur adipiscing elit. Nam lacinia pulvi

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, conUnlock access to this and **over 10,000 step-by-step explanations**

Have an account? Log In

<p>sectetur adipiscing elit. Nam lacinia pulvi</p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, con

**sect**

**sectetur**

`sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Done`

**sectetu**

**sect**

**sectetur**

`sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque`

**sectetu**

**sectetur adipisc**

6 attachments

PNG

PNG

PNG

PNG

PNG

PNG

Unlock every step-by-step explanation, download literature note PDFs, plus more.Get Access