Solved by Expert Tutors
C++ Programming 1. Write programs with loops that compute a. The sum of all even numbers between 2 and 100 (inclusive). The sum of all squares...
Solved by Expert Tutors
Question

C++ Programming1. Write programs with loops that compute

a. The sum of all even numbers between 2 and 100 (inclusive).

b. The sum of all squares between 1 and 100 (inclusive).

c. All powers of 2 from 20 up to 220.

d. The sum of all odd numbers between a and b (inclusive), where a and b are inputs.

e. The sum of all odd digits of an input. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.)

2. Translate the following pseudocode for finding the minimum value from a set of inputs into a C++ program.

Set a Boolean variable "first" to true.

While another value has been read successfully

If first is true

Set the minimum to the value.

Set first to false.

Else if the value is less than the minimum

Set the minimum to the value.

Print the minimum.

3. Translate the following pseudocode for randomly permuting the characters in a string into a C++ program.

Read a word.

Repeat word.length() times

Pick a random position i in the word.

Pick a random position j > i in the word.

Swap the letters at positions j and i.

Print the word.

To swap the letters, construct substrings as follows:

 first i middle j last

Then replace the string with first + word.substr(j, 1) + middle + word.substr(i, 1) + last

4. A local art gallery has tasked you with writing a computer program that computes the ticket price based on the visitor’s age. Because of the high value of the art exhibits, only visitors 12 years and older are allowed in the art gallery. This means that only ages 12 and higher are valid for this program. The program should ask the visitor to re-enter his or her age if the age entered is less than 12. Use a loop structure to allow the visitor to re-enter his or her age if an invalid age was entered.

The program should use if-statements, that computes the ticket price according to this schedule, given the visitor’s age:

Ages 12-17 5.00 dollars

Ages 18-55 25.00

Ages 56 and older 10.00 dollars

The program should output a message that says “Thank you for vising our art gallery. Your ticket price is ” followed by the dollar amount of the ticket price. Example output for a visitor that is 55:

Thank you visiting our art gallery. Your ticket price is 25.00

First, describe your algorithm using pseudocode.

Translate the pseudocode into a C++ program. You must comment your program including comments at the top of the file that explains what the program does and comments for every line of code that explains what is happening for the line of code. Apply troubleshooting and testing strategies to ensure your code compiles, runs, and provides accurate results.

Submit 2 files:

Your Word document with your pseudocode.

Your .cpp file


Background image of page 1
Background image of page 1
Sign up to view the entire interaction

Step-by-step answer

consectetur adipiscing elit.

ng 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 l

code.zip - Preview not available

Subscribe to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Let our 24/7 Computer Science tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes