Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please make sure that you are using C++ Coding Standards for naming of variables/ constants. Arrays and Pointers Write a program that declares three pointers
Please make sure that you are using C++ Coding Standards for naming of variables/ constants. Arrays and Pointers Write a program that declares three pointers for three one-dimensional arrays named price, quantity, and amount. Each array should be declared in main(). The size of the arrays should be asked from user. Try- catch blocks are to be used for handling exceptions such as "RUNTIME ERROR: The program failed to allocated negative memory" - if the size entered is negative. The three arrays should be created dynamically using "new" operator and their memory should be released by using "delete operator. The price and quantity values should be between 0.0 and 100.0 and the same should be validated by using functions contained in MyConsoleInput.h. The values should be stored in arrays using pointer notation. Have your program pass these three arrays and size of amount array to a function called Extend(), which calculates the elements in the amount array as the product of the equivalent elements in the price and quantity arrays: for example, amount[1] = price[1] * quantity[1]. The function declaration using pointers can be void Extend (double *, double *, double *, int); The extend function should be called only if the number of elements of price and quantity match otherwise it should throw an error saying "Please enter the same elements of price and quantity to calculate amount". After Extend() has put values in the amount array, display the values in the array from within main(). Expected Output: Sample Exception conditions: How many elements do you wish to process for Price? -1 RUNTIME ERROR: The program failed to allocated negative memory. How many elements do you wish to process for Price? 2 How many elements do you wish to process for Quantity? -1 RUNTIME ERROR: The program failed to allocated negative memory. How many elements do you wish to process for Price? 2 How many elements do you wish to process for Quantity? 2 How many elements do you wish to process for Amount? -1 RUNTIME ERROR: The program failed to allocated negative memory. How many elements do you wish to process for Price? 3 How many elements do you wish to process for Quantity? 2 How many elements do you wish to process for Amount? 3 Please enter the same elements of price and quantity to calculate amount Process exited after 5.73 seconds with return value e Press any key to continue How many elements do you wish to process for Price? 3 How many elements do you wish to process for Quantity? 3 How many elements do you wish to process for Amount? 3 Please enter 3 Prices: Price 1: 23.4 Price 2: -2 120 Invalid input. Please try again and enter a value between e and 10. Invalid input. Please try again and enter a value between 8 and 18. 24.5 Price 3: 45.6 Please enter 3 Quantities: Quantity 1: -3 Invalid input. Please try again and enter a value between 8 and 18. 120 Invalid input. Please try again and enter a value between 8 and 18. Sample Correct output How many elements do you wish to process For Price 3 How many elements do you wish to process for Quantity? 3 THow many elements do you wish to process for Amount? 3 Please enter 3 Prices: Price 1: 23.4 Price 2: 34.5 Price 3: 67.8 Please enter 3 Quantities: Quantity 1: 3 Quantity 2: 2 Quantity 3: 6 The elements of the amount array are: Amount 1: 70.28 Amount 2: 69.00 Amount 3: 406.80
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started