Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i am a noob please explain step by step Make sure to make a copy of the Google Doc for this lab into your Google

i am a noob please explain step by step Make sure to make a copy of the Google Doc for this lab into your Google Account. Answer all the highlighted questions in there. In the first part of this lab, we would like to introduce you to methods, parameter passing, and the helpfulness of the Debugger. Make a new Project in C# (Lab5_1. Delete the skeleton code, and rename Program.cs, to Lab5_1.cs. Then enter the following program into C# (ignore the line numbers). copy using System; public static class Lab5 { public static void Main() { // declare variables int inpMark; string lastName; char grade = ' '; // enter the student's last name Console.Write("Enter the last name of the student => "); lastName = Console.ReadLine(); // enter (and validate) the mark do { Console.Write("Enter a mark between 0 and 100 => "); inpMark = Convert.ToInt32(Console.ReadLine()); } while (inpMark < 0 || inpMark > 100); // Use the method to convert the mark into a letter grade grade = MarkToGrade(); // print out the results Console.WriteLine("{0}'s mark of {1} converts to a {2}", lastName, inpMark, grade); Console.ReadLine(); } // Method: MarkToGrade // Parameter // mark: call by value parameter to be converted to a letter grade // Returns: the corresponding letter grade public static char MarkToGrade(int mark) { char letterValue; // multi-alternative If statement to determine letter grade if(mark > 0 && mark < 50) letterValue = 'F'; else if(mark >= 50 && mark < 60) letterValue = 'D'; else if(mark >= 60 && mark < 75) letterValue = 'C'; else if(mark >= 75 && mark < 85) letterValue = 'B'; else if(mark >= 85 && mark <= 100) letterValue = 'A'; else { Console.WriteLine("***Error - invalid mark"); letterValue = 'X'; } //return the letter grade back to Main return letterValue; } } Run the program using input Smith and 98 What is the syntax error and how did you fix it? What is the output? Run the program using input Smith and 34 What is the output? Run the program using input Smith and 59 What is the output? Run the program using input Smith and 72 What is the output? Run the program using input Smith and 83 What is the output? Run the program using input Smith and then -1, 101 and 90 for the marks What is the output? Why do you think the input values for mark in Parts (b)-(g) were chosen? Now we are going to see how the Debugger can help us understand the functionality of methods. Put in a Breakpoint (F9 ) at the point where the method is invoked or called (Line 21). You will see that the line is highlighted in red with a red dot to the left of the line. Now run the program (F5 ) using a last name of Smith and a mark of 75. Notice that the program stops at the line with the Breakpoint (and the line is now highlighted in yellow). Also notice that in the bottom left part of Visual Studio there is a window labeled Locals that shows the current values for all the variables declared in Main(): inpMark, lastName, and grade. Press (F11) once and notice the program has jumped into the method MarkToGrade and the values in the Locals window now correspond to the variables and parameters of the method: mark and letterValue. Also notice that in the lower right hand side window (Call Stack), there are two entries: one for Main and one for MarkToGrade with the later one active (yellow arrow). Continue to single step your program until you reach the return statement in Line 55. Single step from Line 55 and describe what you are seeing in terms of where you are in the program (line number), what is in the Locals window (variables and values), and what is in the Call Stack window (will require two to three more single steps to see the program jump. Remove the BreakPoint from Line 21 (press: F9 while on the line) . At Line 53, add the following statement: copy Console.WriteLine("The value of the mark is {0}", inpMark); What error message did you receive and why? Remove the extra line you added in Part (i). Now lets change the method header to include a call by address (reference) parameter. Change Line 33 to be: copy public static void MarkToGrade(int mark, ref char letterValue) Remove Lines 35 (char letterValue;) and 55 (return letterValue;)) Change Line 21 to be: copy MarkToGrade(inpMark, ref grade);Run the program with the input of Smith and 98. What is the output? What do you notice about the output relative to what you saw in Part (b)? Why did we have to remove Line 35 (try putting it back in)? Why did we have to remove Line 55 (try putting it back in)? Why did the method call (invocation) in Line 21 have to change? One last set of changes to the program from Part (j). In the method call (Line 21), change it to: copy grade = MarkToGrade(inpMark); What error message did you receive and why? What if we change Line 21 to: copy grade = MarkToGrade(inpMark, ref grade); What error message did you receive and why? Finally, how about if we change Line 21 to: copy MarkToGrade(ref grade, inpMark); What error messages did you receive and why?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions