Part 1

1. Which built-in data type is the most precise type for storing monetary values?

2. What is the value of the cityState string after these statements are executed?

cityState = "Milwaukee";
cityState = "," + "Wisconsin";

3. If quantity has a value of 2, what is the value of discount after these statements are executed?

switch(quantity)
{
case 1:
discount = 0;
break;

case 2:
case 3:
discount = .1;
break;

default:
discount = .2;
break;
}

4. To refer to the second column in the fourth row of a rectangular array named vendors, you code _____________.

5. What is the value of kilos[1] after the code that follows is executed?

decimal[] kilos = {200, 100, 48, 59, 72};
for (int i = 0; i < kilos.length; i++)
{
kilos[i] *= 2.2;
}

6. The keyword _____ is used to declare a named constant.

7. The _____ operator is used to create objects.

8. In C#, an array subscript must be a(n) _____.

9. What is stored in ans as a result of the arithmetic expression, given the following declarations?

int ans = 5, v1 = 2, v2 = 10, v3 = 18;
ans += v1 + 10 * (v2-- / 5) + v3 / v2;

10. Which of the following is a valid compile-time initialization for amountDue, a variable of the decimal type, that will initially be set to zero?

A. amountDue = 0;
B. amountDue = '0';
C. amountDue = 0d;
D. amountDue = 0m;

11. Which of the following is not a parameter type?

A. out
B. in
C. ref
D. params

12. How can the compound conditional expression ((average > 79 && average <= 89)) be written to eliminate the logical operator without changing the logic?

13. How can you produce the following results in one line of code?

Welcome
to
C#
Programming!

14. By default, everything in a class is _____, unless you specify otherwise by providing access modifiers.

15. Overloaded methods always have the same _____.

16. Which of the following statements is false?

A. An exception indicates a problem that occurs while a program executes.
B. Exception handling helps you create fault-tolerant programs.
C. When an exception is handled, the program continues executing as if no problem was encountered.
D. The compiler does not detect exceptions.

17. Which of the following properly declares an auto-implemented Name property of type string?

A. public string Name { get, set }
B. public string Name { get, set, }
C. public string Name { get: set: }
D. public string Name { get; set; }

18. A return type of _____ is specified for a method that does not return a value.

19. The order of simplicity to a human of the three basic types of languages is: (easiest to hardes)

A. high-level, assembly, machine
B. assembly, machine, high-level
C. machine, high-level, assembly
D. machine, assembly, high-level

20. Using the following code segment:

if (aValue < largest)
result = aValue;
else
result = largest;

what happens when aValue is equal to largest in the program segment above?

Part 2

Short Answer. All provided code segment/images are intented to be syntactically correct, unless otherwise stated (e.g., error is an answer).

21. Write a C# program to test a method that will return the day within the year for a given date. For example, May 19, 1981 was the 31 + 28 + 31 + 30 + 19 = 139th day of that year. Refer to the sample output below.

Sample Run:

Enter a month: 5
Enter a day: 19
Enter a year: 1981

This is the 139 day of the year.

Fill in the missing parts of the program below to solve the problem as stated above. Do not add any additional lines of code.

//DayInYear.cs

using System;
class DayInYear {
static void Main() {
int day, month, year, inYear;
Console.Write("Enter a day: ");
____________________________
Console.Write("Enter a month: ");
month = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter a year: ");
year = Convert.ToInt32(Console.ReadLine());
________________________________
Console.WriteLine();
Console.WriteLine("This is the {0} day of the year.", inYear);
}

static int dayInYear(int day, int month, int year) {
int dayNumber;
_________________________
if(month > 2) {
dayNumber = dayNumber - ((4 * month + 23 / 10);
if(isLeapYear(year))
________________
}

return dayNumber;
}
}


static bool isLeapYear(int year) {
_____________________________
}
}

1. Create a C# program that contains an array of 15 strings. Use the words below in the string. Prompt the user to enter a maximum string length and use LINQ statements to display all the strings that are shorter than the value entered by the user. If no strings meet the criterion, display an appropriate message. Must use LINQ statements. Output should be user friendly.

antelope bear cat dolphin elephant frog giraffe hippopotamus iguana jaguar koala llama moose newt okapi

Name the program: LINQShortWordsXX.cs

2. A barcode scanner for a Universal Product Code (UPC) verified the 12-digit code scanned by comparing the code's last digit (called check digit) to its own computation of the check digit from the first 11 digits as follows:

1. Calculate the sum of the digits of the digits in the odd numbered positions (the first, third... eleventh digits) and multiply this sum by 3.

2. Calculate the sum of the digits in the even numbered positions (the second, fourth... tenth digits) and add this to the previous result.

3. If the last digit of the result from step 2 is 0, then 0 is the check digit. Otherwise, subtract the last digit from 10 to calculate the check digit.

4. If the check digit matches the final digit of the 12-digit UPC, the UPC is assumed correct.

Write a C# program that prompts the user to enter the 12 digits of a barcode separated by spaces. The program should calculate the check digit and compare it to the final barcode digit. If the digits match, output the check digit and barcode with the message "Validated" if not, output the check digit and barcode with the message "Error in barcode". No letters or special characters are found in a UPC code. Finally, ask the user if he/she wishes to run the program again. Refer to the sample output below.

Sample Run:

Enter 12 digits of a barcode: 7 8 0 3 9 3 9 7 9 5 0 9
Check digit is 2

780393979509: Error in barcode
Run again (Y/N): n

Name the program: UPCCodesXX.cs

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.