Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task B: 1. New Project and give your project the name Lab4B. 2. Add a source file to your project, called FindMax.cpp. 3. C++ program

image text in transcribed

Task B: 1. New Project and give your project the name Lab4B.

2. Add a source file to your project, called FindMax.cpp.

3. C++ program with a function named FindMax that has two parameters, one in type constant pointer to constant double array (i.e. const double* const arr), another one is in int type that represents the size of the array.

Your task in this part is to find the position of array element with the maximum value. Instead of returning the array index, a pointer to the maximum element should be returned (note: the returned pointer should be made in a way that the value of the maximum value is unchangeable.)

Assumption: All the floating point values in the array are distinct. Your main function should start by asking the user how many numbers he/she would like to input, then followed by asking all the values. At the end of the program, print the maximum value obtained from the FindMax function. A sample screen display when the method is called is given below: How many numbers do you like to enter?

5 Enter values: 10.5 2.1 5.21 1.23 23.8 The maximum value: 23.8 The input which is underlined is the user's input to a question.

Task A: 2. 1. Create a New Project and give your project the name Lab4A. Add a source file to your project, called FindPrimeNumbers.cpp. 3. Write a C++ program that uses an array of n elements (where n is a user input) to determine and display the prime numbers between 2 and n, including n using the method described below. Ignore array elements 0 and 1. A prime number is any integer greater than one that is divisible only by itself and 1. A list of prime numbers can be found by the following method. a Create a primitive type bool atray with all elements initialized to true. Array elements with prime indices will remain true. All other array elements will eventually be set to false. b. Starting with array index 2, determine whether a given element is true. If so, loop through the remaining of the array and set to false every element whose index is a multiple of the index for the element with value true. c. Then continue the process with the next element with value true. For array index 2, all elements beyond element 2 in the array that have indices which are multiples of 2 (indices 4, 6, 8, 10, etc.) will be set to false, for array index 3, all elements beyond element 3 in the array that have indices which are multiples of 3 (indices 6, 9, 12, 15, etc.) will be set to false, and so on. d. When this process completes, the array elements that are still true indicate that their indices are prime numbers. These indices can be displayed. Multiple sessions of sample screen display when the method is called are given below: Enter the value of n: 10 Prime numbers: 2, 3, 5, 7 4 primes found. Enter the value of n: 60 Prime numbers: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59 17 primes found. Enter the value of n: 100 Prime numbers: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 25 primes found. The input which is underlined is the user's input to a question. (Note: you don't have to repeatedly execute your program code using loop for this assignment.) 4. Compile your program and test it by executing your program

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 Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions