Lab 0 Manual: COS 495 - Autonomous Robot Navigation
Lab 0 Manual: COS 495 - Autonomous Robot Navigation
Fall 2011
Lab 0 Manual
1.1 Goals
The programming interface goals of this lab are as follows:
• Introduce students to the Microsoft Visual Studio .NET programming environment
• Introduce students to C# programming language
• Enable students to compile and run their first C# program
• Introduce students to online documentation and help
Your project has several files which you can view/edit by double clicking them from the “Solution
Explorer”, (see Fig. 2). The main file to edit is “Program.cs”, which has several components. Notice the
first 4 lines of the files start with the command using. This command allows your program to access
various packages of code, each called a namespace, already written. The next line “namespace
COS495Lab0” says that we are creating our own namespace that we want to call COS495Lab0.
Everything contained within the brackets {} that follow, will be part of this new namespace.
Figure 1: Creating a new console application.
Class
declaration
.
Figure 2: The template for a console application
The next line “class Program” says to create a new class called Program. A class is an object that has
various variables and methods associated with it. For example, a class called “Rectangle” might have
variables called “length” and “width”, as well as a method called “calculateArea”. Everything contained
within the brackets {} that follow, will be part of this new class.
In the class Program, there is only one method called “Main”. The Main method of a program is what the
program calls when it starts running. Within the {}’s that follow, the programmer should add a list of
commands that should be executed when the program starts. The next step of this lab will guide you in
adding some commands.
Step 3: Add some commands
Within your Main() method of the class Program, add the following commands:
Console.WriteLine("Hello World!");
Console.ReadLine();
Your file Program.cs should look like the one shown in Figure 3. Note that Console is a class from the
namespace System that the program says we want to use. Two methods that are part of the Console class
are WriteLine() and ReadLine().
To compile your program, i.e. creating an executable program from the code you have written, select
Build => Build Solution from the MVS drop-down menu. If you did everything correctly, the Output
fields at the bottom of your MVS window should read “========= Build: 1 succeeded” (see
Figure 3). Otherwise, errors will be reported.
Step 5: Run your program
To run your program, click the green triangle OR select Debug => Start Debugging from the MVS drop-
down menu. A console window should pop up with your “Hello World!” message. Hit the <Enter> key to
close the program.
Congratulations! You have created, compiled, and run your first C# program!
Notice the fourth line in the method, it creates a new variable called “usersName”. This variable is
declared to be of type string. There are many types of variables one can make while programming
including integers, floats, etc. One can think of string types as text consisting of a string of letters. The
line that follows sets the value of usersName to be whatever text is entered by the user. The value of
usersName is printed back on the next line.
Compile and run this code to make sure you understand how the sequence of commands work.
Working with your partner, use your C# Console application to create an ASCII image of a robot. The
image could be inspired by an image, photo, sketch or your imagination. The image must be dynamic in
that it responds to at least 3 different user inputs, (e.g. how wide should the image be? Should the robot be
happy or sad?...). The program should also include at least 1 for loop.
1.6 Deliverables
None for this lab.