Problem 1 - no methods required
When the user runs this block of code, the values in the array will be displayed, along with a sum value, the lowest value, and the number of occurrences of the lowest value. Appropriate data types are required, and use the Length property of the array to control all looping
constructs except the ‘foreach'. Here are the steps to follow:
a. Declare an integer constant for the SIZE of the array, the size will be 25.
b. Declare and instantiate an integer array with the name testScores using the constant SIZE. Make sure to use the "new" operator.
c. Use a ‘for' loop to populate the array with random numbers from 10 to 100 inclusive. Use constants.
d. Use a ‘while' loop structure to accumulate the values that are in the array. Store that value in a variable named sum.
e. Do not sort the array, and use a ‘do' loop to determine the lowest value in the array. Keep it simple, you do not have to create a sorting routine. (Hint: store the first value in the array into a variable called low. Inside the loop compare low to the next element in the array. If it is less, then store the array value into low. Repeat until you reach the end of the loop.)
f. Use a foreach loop to display the values in the array on one line with spaces between each number. (See below) Within this loop, count the number of times the highest value occurs in the array.
g. Using one CW, display the sum (including comma), the lowest value and the number of occurrences of the lowest value. (See below)
Required output [values listed will vary]:
Problem 1
82 87 90 91 87 88 96 92 97 100 92 92 86 94 81 88 82 92 98 92 99 85 86 81 86
Sum of values: 2,244
Lowest value: 81 occurs 2 time(s).
Problem 2
Description: Use two single dimension arrays, where one will be a Lookup Table to determine the cost of an individual item in an outlet retail store. The user will input the item (string) and the quantity (integer) purchased; then the program will determine the price (fractional number) for the item and display the total cost (fractional number) for that purchase. This will use methods, and you do not need to validate the data. Define the methods for this question directly under Main; there are comments to guide you, and above the Pause() method, and in the same Class. Reminder to not use class level variables, and accept user mixed case input for the item purchased. A fractional number is data that allows decimal points. Use the following pseudocode to guide you.
a. Declare and initialize two arrays, arrItem (Item) and arrPrice (Price) and use the “new” operator when declaring the arrays. Use the following data to initialize the arrays and do not change the order as shown.
Item Price
laptop 925.25
keyboard 52.00
mouse 15.75
monitor 95.50
Use 1 C# statement for each array to declare and initialize the values in them. Declare the arrays within Main()
b. In Main, call the methods to get the item and the quantity. (see steps f and g)
c. In Main(), use the item array to determine the subscript/index value to use for the price.
Use a ‘for’ repetition structure and not the binary search to determine the index value to use as a Lookup in the price array.
d. If the user inputs an invalid item, display an error message that repeats the value the user entered. See example after this question. Do not add a loop to ensure valid data.
e. If the data is valid, call the CalcItemCost method (see step h) and display the total cost formatted with a dollar sign and two decimal places.
f. Method GetItem – Parameters: none; return: item Prompt for the item, and convert the input value all to lower case.
g. Method GetQuantity – Parameters: none; return: quantity of items purchased as a whole number.
Prompt for the quantity of items purchased.
h. Method CalcItemCost – Parameters: the number of items, the cost for the item; returns: the calculated total cost. A tax of 9.5% is included in the total cost, and this method will not get nor display any data to the console. Create and use a constant for the tax rate.
See examples of the prompts, and text below. Use Write instead of WriteLine for the prompts.
Required display :
Problem 2
Enter the item to purchase: Keyboard
Enter the number of items purchased: 10
Total cost for the purchase is: $569.40
Required display [Error]:
Problem 2
Enter the item to purchase: diskette
Enter the number of items purchased: 20
Invalid entry, diskette does not exist.
Problem 3
Description: Within Main(), Problem 3 curly braces, this section will call 3 methods which will be created directly below CalcTicketCost() method and right above the Pause() method. Do not declare any class level variables; use only local variables in each code block and method. Data types must match as arguments and parameters, an implicit conversion will be marked as incorrect.
a. In this code block, prompt the user for three integer values and store into appropriate data type variables. You do not need to validate the data, but you must use TryParse, and numbers can be positive or negative. Use Write instead of WriteLine for the prompts.
Within the class, create the 3 methods as describe: Product(), Division(), Average()
b. Product() with three parameters. The parameter names must be different than the variables stored in the Problem 3 code block.
Calculate the product and return the value
c. Division() with two parameters – the first parameter is the dividend, the second parameter is the divisor. The parameter names must be different than the variables stored in the Problem 3 code block.
In this example (571/13), 571 is the dividend, and 13 is the divisor
Calculate the result (no truncated values) and return the value.
Check for zero division. To keep this simple, if this error occurs, return a negative 999.99.
d. Average() with three parameters. The parameter names must be different than the variables stored in the Problem 3 code block.
e. In this Problem 3 code block, call each of the methods, with the following arguments:
a. Product: use all three input numbers as arguments
b. Division: use the “first two” input numbers as arguments
c. Average: use all three input numbers as arguments
f. Use one WriteLine to display the resulting values with appropriate labels. Show the product with commas, and no decimal places, except show the division and average results with 2 decimal places.
Required display [example1]:
Problem 3
Enter number 1: 543
Enter number 2: 000
Enter number 3: 21
The results of the three method calls are:
Product: 0
Division: -999.99
Average: 144.00
Required display [example2]:
Problem 3
Enter number 1: 25
Enter number 2: 52
Enter number 3: 33
The results of the three method calls are:
Product: 42,900
Division: 0.48
Average: 36.67
Challenge
Write a program that allows the user to enter any amount of numbers (double data type) continuously until the user enters 999; use a ‘do’ construct. Display the number of values entered and the sum of the values entered, not including 999, with commas and 2 decimal places. Use a constant for the value that ends the repetition.
Required display:
Enter a number: 1010
Enter a number: 100.10
Enter a number: 10.01
Enter a number: 999
You entered 3 numbers and the sum is 1,120.11