---
title: CSCI 1301 -- Lab 04
author: Clément Aubert
lang: en
fontsize: 10pt
documentclass: scrartcl
numbersections: true
links-as-notes: true
papersize: letter
geometry: margin=1in
keywords:
- Computer Science
- Problem solving methods
- Syllabus
- Augusta University
- Bachelor of Science
---

# Reading the Instructions

This is the fourth lab already, and you should have some habits.
You should know how to

#. Manipulate projects (creating them, opening them, editing them, saving them, making backups).
#. Compile and execute your program frequently.

You already started to read "compile and execute" as 

> In the menu, click on`Build` → `Build solution` (or use <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>B</kbd>), then on `Debug` → `Start without Debugging` (or use <kbd>Ctrl</kbd> + <kbd>F5</kbd>).

From now on, read "Create a new project" as 

> Create a new project, using the "Console Application Visual C#" template, as you did in [lab 03](../03/#starting-from-a-template).
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 <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>F12</kbd> to "jump" to the line where VS thinks there is an error.

And, _even if it is not explicitly asked_, you should save your work once you are done, and re-open it at the beginning of the next session to make sure you saved it properly.

If you want a tutor or your instructor to check your answer to a previous lab, just ask!

# Exploring the Documentation

The documentation for Visual Studio and C# is packed with useful information, and efforts are made to make it accessible to beginners.
The goal of this exercise is to help you realizing that it contains answers to questions you may have asked yourself, like "what is a solution?", or "what does the `namespace` keyword do?".

All the documentation for Visual Studio is at <https://docs.microsoft.com/en-us/visualstudio/>.
The documentation for C# is at <https://docs.microsoft.com/en-us/dotnet/csharp/>.
To get started, have a look at the first three paragraphs of <https://docs.microsoft.com/en-us/visualstudio/ide/creating-solutions-and-projects> (or at <https://docs.microsoft.com/en-us/visualstudio/mac/projects-and-solutions?view=vsmac-2019> for Mac), and answer the following:

#. What is a solution?
#. What is a project?
#. Which one contain the other: the solution, or the project?

Note that since we will only manipulate one project at a time, the distinction between solution and project will not be critical in this lab.
That's the reason why I wrote previously "create a new project" with the sense of "create a new solution and a new project in it": we will never manipulate more than one project in a solution at a time.

Finally, read the page at <https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/namespaces/>: do you know an example of namespace that we used?

# Variables Assignments

Think with a pen and a sheet of paper for some time before opening Visual Studio.
Consider the following code:

~~~~~~~{.cs .numberLines .lineAnchors}
int a = 0;
a = 12 - 3;
a = 10 % 3;
a = 12 * 2;
a = 9 / 3;
a = -3;
a -= 3;
a += 5;
a *=12;
a /= 2;
a = a + a;
~~~~~~~~

#. In the previous code, what is the value of `a` after each line is executed?
#. Check your answers: create a new project, copy the previous statements in the `Main` method, use `Console.WriteLine(a);` to display the value of `a` after each statement.

# More About Displaying Characters at the Screen

#. Create a new project.
#. Edit the `Main` method, so that when compiled and executed, you program will display the following at the screen:

~~~~~~~{.cs .numberLines .lineAnchors}
   !
  !!!
!!!!!!!

Press any key to continue . . .
~~~~~~~~

#. We will now use the ["Find and Replace" feature of VS](https://msdn.microsoft.com/en-us/library/139eef4h.aspx#Anchor_1).
    #. Hit "Edit" → "Find and Replace" → "Find in Files", or press <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>f</kbd>.
    #. In the panel that appears, click on the "Replace in Files" tab, enter "!" (without the quotes) under "Find what:", and "*" (without the quotes) under "Replace with:".
    #. Hit "Replace All", and note the modification in your program.
#. As you can see this is a really useful feature of VS, but also a really dangerous one.
If you were to replace all the "*" characters with "!" in all the program we wrote so far, what could possibly go wrong?
