Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I NEED HELP WITH TASK 2, 3 AND 4 ALONG WITH EXERCISES INCLUDED I JUST NEED EXAMPLES OF HOW TO DO THE WORK Task 1:

I NEED HELP WITH TASK 2, 3 AND 4 ALONG WITH EXERCISES INCLUDED

I JUST NEED EXAMPLES OF HOW TO DO THE WORK

Task 1: Working with while loops (25 pts)

Exercise 1.The factorial of n, denoted n!, is defined as:

0! = 1

1! = 1

n! = 1*2*3*.*n for n > 1

So 4! = 1*2*3*4 = 24 and 6! = 1*2*3*4*5*6 = 720

Write an algorithm (pseudocode) to do the following:

prompt user to input an integer number n ( >= 0)

calculate the factorial of the number entered

output the result to standard output device

Exercise 2.Create a flowchart for your algorithm using Raptor and verify it for the example cases listed above.

Exercise 3.Modify your flowchart of Exercise 2 to valid the input using a loop that repeatedly prompts the user to enter a valid input (i.e. a number greater or equal to 0).

Exercise 4.Write a C++ program for the flowchart of Exercise 3.

Demo your program to your instructor. Copy and paste your flowchart below for submission to the EOL dropbox upon completion of your lab.

Task 2: Working with counter-controlled while loops (25 pts)

Exercise 1.Write an algorithm (pseudocode) to read a set of sales data items from standard input and calculate and output their total and their average. Prompt user to enter number of data items.

Exercise 2.Create a test data set to verify your algorithm. How many cases are needed? Explain.

Write your test data set below for submission to the EOL dropbox upon completion of your lab.

Number of items

List data items

Expected output

Case 1:

Exercise 3.Create a flowchart for your algorithm on Raptor and verify it using your test data. Copy and paste your flowchart below for submission to the EOL dropbox upon completion of your lab.

Exercise 4.Write a C++ program that implements your flowchart. Use a do-while loop for input validation and a for loop to calculate the total (You may skip this exercise until we cover for and do-while loops)

Demo your program to your instructor.

Task 3: Working with sentinel-controlled loops (25 pts)

Exercise 1.In the program of the previous task, we assumed the number of data items is known beforehand. Sometimes thats not the case. In those cases, instead of asking user for the number of data items, the program prompts the user to enter a sentinel as the last piece of data. Please refer to the textbook or class notes for the definition and use of sentinels.

Modify your program from the previous task so that the loop stops reading sales data when -1 is entered.Make sure to modify the prompt to inform the user to enter -1 when there are no more data items to enter.

Demo your modified program for credit.

Task 4: Working with files and end-of-file controlled loops (25 pts)

Note: You may skip this task until we cover the section about using files for input/output

Exercise 1.Modify your program from Task 3 so that sales data is read from a text file instead of being entered in the standard input device. Assume the data items are stored in the file separated by blank spaces and -1 is used as a sentinel.

Exercise 2.Modify your program from Exercise 1 above to read the sales data until the end of the file (i.e. no sentinel is used).

Demo your modified program for credit.

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

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions

Question

What were the issues and solutions proposed by each team?

Answered: 1 week ago