Você está na página 1de 2

Name:

Student Number: Trent University COIS 1020H Lab 1

1) Enter the following program into Microsoft Visual C# (ignore the line numbers).
1 public class Lab1 2 { 3 public static void Main() 4 { 5 int age; 6 long idNum; 7 double pay Rate, hours, grossPay; 8 string firstName, lastName; 9 10 // prompt the user to enter employee's first name 11 Console.Write("Enter employee's first name: "); 12 firstName = Console.ReadLine(); 13 14 // prompt the user to enter employee's last name 15 Console.Write("Enter employee's last name: "); 16 lastName = Console.ReadLine() 17 18 // prompt the user to enter a six digit employee's identification number 19 Console.Write("Enter a six digit employee's ID: "); 20 idNum = Convert.ToInt64(Console.ReadLine()); 21 // idNum = long.Parse(Console.ReadLine()); 22 23 // prompt the user to enter employee's age 24 Console.Write("Enter employee's age: "); 25 age = Convert.ToInt32(Console.ReadLine()); 26 // age = int.Parse(Console.ReadLine()); 27 28 // prompt the user to enter the number of hours employee worked this week 29 Console.Write("Enter the number of hours employee worked this week: "); 30 hours = Convert.ToDouble(Console.ReadLine()); 31 // hours = double.Parse(Console.ReadLine()); 32 33 // prompt the user to enter the employee's hourly pay rate 34 Console.Write("Enter employee's hourly pay rate: "); 35 pay Rate = Convert.ToDouble(Console.ReadLine()); 36 // payRate = double.Parse(Console.ReadLine()); 37 38 grossPay = hours * pay Rate; // calculate gross pay 39 40 // output results 41 Console.WriteLine("\nEmployee " + firstName + " " + lastName + " of age " 42 + age + " (ID: " + idNum + ") earned " + grossPay + " this week.\n"); 43 // Console.WriteLine("\nEmployee {0} {1} of age {2} (ID: {3}) earned {4:C}" 44 // + " this week.\n", firstName, lastName, age, idNum, grossPay); 45 46 Console.WriteLine("Press any key to end"); 47 Console.ReadKey(); 48 } 49 }

Use the following input for all questions: First name Last name ID Age Hours worked Pay rate John Doe 123456 35 22.5 8.75

2) Build the solution. Resolve any syntax mistakes until the program compiles. There are 3 intentional mistake already (think System, semicolon and identifier name), plus whichever ones you may make while copying. The same mistake may lead to cascading error messages. What are the 3 intentional mistakes?

3)

Run the program with the aforementioned input. What is the output?

4)

Uncomment lines 21, 26, 31, 36, 43, 44 to render them active and comment out lines 20, 25, 30, 35, 41, 42 to render them inactive. Build the solution. Resolve any syntax mistakes (if you make any) until the program compiles. Execute it with the provided input. What is the output?

5)

Replace the statement on lines 43-44 with the following statement:


Console.WriteLine("\nEmployee {0} {1} of age {2} (ID: {3}) earned {4:C}" + " this week.\n", 1stName.ToUpper(), lastName.ToLower(), age, idNum, (hours * pay Rate));

Build the solution. Resolve any syntax mistakes (if you make any) until the program compiles. Execute it with the provided input. What is the output?

What is the difference in the output between this and the previous run?

Você também pode gostar