August 28, 2018
Deadlines: This lab needs to be completed before taking Lab 05.
Dependencies: This lab can be done in almost any order, but the recommended order is of course the one below.
The title of this part sums it all: re-downlad the files you saved for lab 03 and open the project with Visual Studio. Try to compile and execute it. Now, create a folder for this lab: upon completion of this lab, you will have created (at least) three new projects, that should each have one sub-folder. Make sure you save all of them correctly before exiting the lab.
From now on, read “Create a new project” as
Create a new project, using the “Console Application Visual C#” template, as you did in a. and b. of Part I of Lab 03. Pick simple and “valid” names for your project and solution, and make sure you save it in the right place. Compile and execute your program frequently, for instance upon completion of every item. Do not hesitate to change your program to answer questions: you’re in a lab, you’re supposed to conduct experiments! If you get an error when trying to compile your program, use Ctrl + Shift + F12 to “jump” to the line where VS thinks there is an error.
Main
method, so that when compiled and executed, you program will print the following: !
!!!
!!!!!!!
Press any key to continue . . .
*
* * *
* * * * * * *
Press any key to continue . . .
Can you think of a way to change your program using the “Find and Replace” feature of VS to do that?
Main
method, add three statements:string
variable named lastName
,string
variable named firstName
,int
variable named classOf
Assign your last name to the first variable, your first name to the second variable, and your anticipated graduation year (i.e., 2020, for instance) to the third one, using three statements.
Print the values of the three variables, using the following statement (that uses interpolation):
Answer the following: What would happen if the statement of d. was before the assignments of c., i.e., after the declarations of the variables, but before their assignments?
After the printing statement of d., add three statements that change the value of the three variables, and copy the statement of d. Notice that the very same statement will now print a different message!
Main
method, add the following:a
and b
…Use printing instructions to check your answer, and make sure you understand how variable assignment is done.
The following are two independent tasks, to widen your understanding of this class, and to prepare you for the next labs.
This is called composite formatting. Try to do the following:
{
character in a Console.Write
statement that does not use composite formatting.{
character in a Console.Write
statement that uses composite formatting.You should have a look at the documentation at https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting#escaping-braces if you can’t figure out how to do it.
using System;
statement. If you’re using Console.WriteLine
or Console.Write
instructions, you should not be able to compile your program anymore. Try replacing these instructions (using “Find and Replace”!) with System.Console.WriteLine
and System.Console.Write
. What do you observe? Can you explain this behavior?