PROG 110 Quiz 2 (Final)

Winter 2015
Points Possible: 100
You will have 3 hours to complete this exam.
From Question 1 download and save the questions (pdf) and the zip file.
Extract (unzip) the zip file and open up the solution, and run it. On your monitor you will
see Problem 1, Problem 2, etc. This is just a skeleton template that I have provided.
Verify that the program works since you only have one attempt.
Answer Question 1 by copying and pasting in your "Started" time as shown when you
started the quiz.
Save your answer and submit the quiz.
When you have finished answering the questions, or have run out of time, submit your
source file (yourLastNameQuiz2.cs) using the Assignment Quiz 2 Submission.
The time stamp of when you started the quiz and the time stamp of when you submitted your
assignment will determine the amount of time you used.
For each minute late, I will deduct one point from the quiz, so please manage your time, and
give yourself an extra 15 - 30 minutes to submit your quiz to me within the 3 hour time limit.
For this assessment, you will be modifying an existing project. This project is an open book
assessment. That is to say you may use your book and notes for this course. You may NOT,
however, correspond/talk to anyone about anything during the course of development and
during the open time period. You may not receive answers or help from anyone. You must do
your own work. You may email me for any specific question, but unfortunately, I may not
respond in time for you to complete the assessment.
You will have 3 hours to work on the project. Make sure to set aside that amount of time to
complete your work and manage your time. After retrieving the directions, the zip file, and
"answering" it with the Started time, click the "Submit" button to "finish" your quiz.
Hint: Plan/design your sequential (or branching) statements before typing the code. Remember
that the Software Development Standards still apply in regards to naming conventions,
indentation, and use of decision structures. The only exception is that internal comments are
optional.
Submit the source file only as a submission to the Assignment Quiz 2 Submission.

Winter 2015
Points Possible: 100
Objective: programming terminology, variable declaration, data type, decision structures,
looping structures, arrays and methods.
Add comments at the beginning of the code to include todays date and your name. Internal
comments within the code are optional. For this assessment, you are required to use the Write()
method for displaying prompts, and the TryParse method to convert numeric input. For all data
displayed on the screen, use placeholders. For numeric data, format using the appropriate
character format specifier inside the placeholder. Use the exact prompts as shown for each
problem. You are not allowed to use class level variables, use only local variables within the
curly braces.
Change the name of the source file to yourLastNameQuiz2.cs (e.g. SmtihQuiz2.cs)
Leave the class name as Quiz2
Problem 1 (30 points) 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 92 87 98 90 92 91 99 87 85 88 86 96 81 92 86 97

100 92 92 86 94 81 88 82


Sum of values: 2,244
Lowest value: 81 occurs 2 time(s).

Problem 2 (40 points)
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
laptop
keyboard
mouse
monitor

Price
925.25
52.00
15.75
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 (30 points)
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
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 (5 points)
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

Submission
Submit your source file only, do not zip it. Use the Assignment tool to submit your answers.
Go to the Assignment called Quiz 2 Submission in Canvas, and submit the source file only
[yourLastNameQuiz2.cs] as an attachment.


It is your responsibility to ensure that the correct file is submitted. There is no time for me to
check, validate and request a new file from you. If I dont have the correct file, I cannot grade
your project and therefore, you will receive a zero for this quiz. There is a penalty of one point
deducted for each minute late.

  • 9 years ago
assignment
NOT RATED

Purchase the answer to view it

blurred-text
  • attachment
    consoleapplication1.zip