Software Development 1 – Tutorial for Week 1
21 Pages
English

Software Development 1 – Tutorial for Week 1

-

Downloading requires you to have access to the YouScribe library
Learn all about the services we offer

Description

Software Development 1 – Week 1 Using the Labs and an Introduction to Programming 1. Introduction When you have read through this and completed all of the tasks, you should be able to:  Use the specialist computing lab computers  Use commands from a Windows command prompt  Edit, compile and run small computer programs  Understand what the term compile means and the steps needed to turn a file produced in a text editor into a program that you can run on the computer.  Start to gain an insight into the common parts of all C# programs I suggest reading through the entire tutorial before starting it to ensure you know what tasks you will be performing and their relevance to later tasks. It is important that you complete all parts of this tutorial before the lecture next week. Note. If you wish to do these exercises on your computer at home as well, you will need to install Microsoft Visual Studio 2008 on your home computer. See the Module Handbook for Software Development 1 for information on how to obtain a copy of Visual Studio 2008. Instead of Notepad++, you can use any text editor (for example, Notepad). Do not attempt to use a word processor such as Word since this puts extra formatting controls in the file which will give you unpredictable results. If you want to use Notepad++ at home, instructions on how to obtain it can be found in the Module Handbook. Week 1 - 1 - 4CC050 Software Development 1 2. Using the Command Prompt 2.1 ...

Subjects

Informations

Published by
Reads 16
Language English

Software Development 1 – Week 1
Using the Labs and an Introduction to Programming
1. Introduction
When you have read through this and completed all of the tasks, you should be able to:
 Use the specialist computing lab computers
 Use commands from a Windows command prompt
 Edit, compile and run small computer programs
 Understand what the term compile means and the steps needed to turn a file
produced in a text editor into a program that you can run on the computer.
 Start to gain an insight into the common parts of all C# programs
I suggest reading through the entire tutorial before starting it to ensure you know what
tasks you will be performing and their relevance to later tasks.
It is important that you complete all parts of this tutorial before the lecture next
week.
Note. If you wish to do these exercises on your computer at home as well, you will need
to install Microsoft Visual Studio 2008 on your home computer. See the Module
Handbook for Software Development 1 for information on how to obtain a copy of
Visual Studio 2008.
Instead of Notepad++, you can use any text editor (for example, Notepad). Do not
attempt to use a word processor such as Word since this puts extra formatting controls in
the file which will give you unpredictable results. If you want to use Notepad++ at
home, instructions on how to obtain it can be found in the Module Handbook.

Week 1 - 1 - 4CC050 Software Development 1 2. Using the Command Prompt
2.1 What is the Command Prompt?
Many of you will not have used a Windows command prompt before. If you have, then
you will be able to work through this section quickly. If not, this section will provide you
with the basic information you need and tell you how to obtain further information.
Note. Some people refer to the command prompt as the DOS box. This is because the
commands look like the old MS-DOS or PC-DOS commands and you can run some old
DOS programs. However, this is misleading. The command prompt simply provides you
with another way of running Windows applications and performing administrative tasks.
You can run any Windows application from a command prompt and do virtually
everything you can do in the graphical user interface using text-based commands. The
reason it is better to use a command prompt here is because you will be running
commands that require parameters and you will need to see the results of running the
commands. This is easier to do from a command prompt.
The normal command prompt can be accessed from the Windows Start menu by selecting
All Programs->Accessories->Command Prompt. You could do this, but you would
need to change some environment settings on the computer in order to run some of the
programs you will need, such as the C# compiler. Fortunately, a customized version of
the command prompt is provided with Visual Studio 2008 that you can use. This is the
version you will be using in the labs.
To run the Visual Studio command prompt, select the following from the Windows Start
menu:
All Programs->Languages->Microsoft Visual Studio 2008->Visual Studio Tools->Visual
Studio 2008 Command Prompt
as seen in figure 1.

Figure 1 – Starting the Visual Studio 2008 Command Prompt
Be careful which Command Prompt you select since, as you can see, there are three
different command prompts that can be selected from that menu.
Week 1 - 2 - 4CC050 Software Development 1 A Visual Studio 2008 command prompt window will open that is similar to figure 2.

Figure 2 – The Visual Studio Command Prompt
A flashing cursor indicates where you can type commands. The prompt always tells you
which disk drive and folder you are currently on. In figure 1, you can see that it is
currently on drive C in the folder Program Files\Microsoft Visual Studio 9.0\VC
1.2 Using a Different Disk Drive
The first thing you need to do is change the drive you are using. In the labs, you are not
able to save any files to drive C. All of your files must be saved to drive T. This is the
disk space allocated to you on the server.
If you are at home, you could save your files to this folder on drive C, but it is not
recommended. It would be better to create a new folder on the C drive using the
commands described below.
To change to drive T, type the following at the prompt and press Enter:
t:
To change to a different drive, you always enter the drive letter, followed by a colon
(“:”). Note that it doesn‟t matter whether you use lower case or upper case in the
commands – they are not case-sensitive. The command prompt should now look like
figure 3.
Week 1 - 3 - 4CC050 Software Development 1
Figure 3 – Changing to a different disk drive
In the next steps you will use the following Windows commands:
MKDIR or MD Create a folder
CHDIR or CD Change folder
DIR List the contents of a folder
You can see that there are two versions of some commands. For many Windows
commands, there are long names (such as MKDIR) and short names (such as MD). For
the rest of this tutorial you will see the short names used, but you can use either.
1.3 Creating a Folder
You are currently in the root folder of drive T. In order to organise your files, you should
create folders for different modules. In this section, you will create a folder called
Year1. Inside that, you will create a folder called SoftwareDevelopment1.
To create the folder Year1, type the following and press Enter:
md Year1
Next, to move into the folder, type the following and press Enter:
cd Year1
Your console window should now look like figure 4.
Week 1 - 4 - 4CC050 Software Development 1
Figure 4 – Creating and moving into a new folder
You can see that the prompt indicates that you are in the Year1 folder. Now, to create the
SoftwareDevelopment1 folder and move into it, type the following (pressing Enter after
each command):
md SoftwareDevelopment1
cd SoftwareDevelopment1
The prompt should now indicate that you are in the folder you just created,
T:\Year1\SoftwareDevelopment1.
You will notice that neither of the folder names contained any spaces (i.e. you used
“SoftwareDevelopment1” rather than “Software Development 1”. This was because the
use of spaces in folder and file names can lead to problems with commands unless you
think carefully about what you are doing. The use of spaces in folder or file names
generally requires that you put quotes around the folder or file name. For example:
md “Software Development 1”
To avoid extensive use of quotes, I have avoided the use of spaces in folder and file
names in this tutorial and I recommend that you do the same until you are very
comfortable with the use of the command prompt.

1.4 Displaying the Contents of a Folder
To display the contents of a folder, use the dir command as follows:
dir
Your command window should look like figure 5.
Week 1 - 5 - 4CC050 Software Development 1
Figure 5 – Using the Dir command
You can see that the folder T:\Year1\SoftwareDevelopment1 is empty apart from two
special folders: “..” and “.”. If you are interested in what these refer to, you can look these
up yourself. However, it is not important for this module. You will come back to the dir
command later.
1.5 Moving to Other Folders
If you want to move back up to the folder Year1, you can do this by typing:
cd ..
(i.e. cd followed by a space and two dots). The use of “..” always indicates “the folder
above this one”.
To move to the root folder of the current drive, use:
cd \
(i.e. cd followed by a space and the backslash character). To go directly to a particular
folder, you can specify the full path name. For example:
cd \Year1\SoftwareDevelopment1
1.6 Other Commands
There are many other commands that can be used in the command prompt that you will
find useful. These include:
COPY Copy one or more files from one location to another
MOVE Move one or more files from one location to another
DEL Delete files (Note that you cannot retrieve the files from
the recycle bin if you use the DEL command so use it carefully)
RENAME Rename one or more files
XCOPY Copies complete folders and sub-folders
Week 1 - 6 - 4CC050 Software Development 1 Information on these commands and other command that are available can be found in
the Windows Help. From the Windows XP Start menu, select Help and Support. In the
Window displayed, enter “Command-Line Reference” into the Search field and press
Enter. From the suggested topics, select “Command-line reference A-Z”. You will then
have access to help for each of the commands. This can be seen in figure 6.

Figure 6 – The Windows Command-Line Reference

2. Creating a Small Program
When people learn how to program computers, the first program they write always seems
to be a program that displays “Hello World” on the screen. I don‟t see any reason to
break this tradition, so that‟s what you will do next - you will create a small computer
program that simply displays “Hello World” in the command prompt. Do not worry if a
lot of the things in this section do not make sense to you at this stage. Once you have
done this section, you will be asked to do some further reading and this will explain the
concepts covered in this section. They will also be covered in the lectures over the next
few weeks.
2.1 Make a Folder for Week 1 Exercises
Make sure you are in the folder T:\Year1\SoftwareDevelopment1. Now create a new sub-
folder called Week1 and move into it. Try to do this on your own. If you are stuck, refer
to solution 1 in the Exercise Solutions on the last page of this tutorial.
Week 1 - 7 - 4CC050 Software Development 1 2.2 Typing in a Program
To create the program, you need to use a text editor program. . You could use the
simplest editor – Notepad. However, a better editor called Notepad++ is installed in the
labs and you will be using this for your practical sessions for the first few weeks.
The file you will create will be called hello.cs.
To start up Notepad++ and create a file called hello.cs, type the following at the
command prompt:
notepad++ hello.cs

Note. If you are running Notepad++ at home, this may not work unless your computer
has been set up correctly. Refer to the notes on the last page of this tutorial for details
about how to make Notepad++ run from the command prompt on your computer.

Because this file does not yet exist, you will see the dialog box shown in figure 7
displayed.


Figure 7 – Creating a New File

Click Yes to create the file.
You will now see a window similar to figure 8.
Week 1 - 8 - 4CC050 Software Development 1
Figure 8 – Notepad++
Type the following text into the blank window in Notepad++. This text is source code
for your program written in a programming language called C# (C Sharp). Be very
careful with punctuation and getting the case of letters right. If you make mistakes, you
will have a chance to fix them later.
using System;

// A simple program that displays "Hello World"

class Hello
{
static void Main() {
Console.WriteLine("Hello World");
}
}

Your Notepad++ window should look like figure 9. Note that Notepad++ displays line
numbers for you. However, these are not saved in the file – they are simply there in the
display to help you locate specific lines.
Week 1 - 9 - 4CC050 Software Development 1
Figure 9 – The Notepad++ window containing the text you have entered
You can see that different words are in different colours. Notepad++ colourises the
source code for different programming languages, including C#, to enable you to more
easily distinguish different parts of the program. You will learn what the different
colours indicate later.
Once you have finished, select Save on the Notepad++ File menu to save the file. Next,
exit Notepad++.
You should be back at the command prompt you opened earlier. At the command
prompt, type dir to display the contents of the folder. You should see that your folder
contains one file – Hello.cs.
2.3 Compiling the Program
The file you have created contains the source code for your program. This is text that can
be read by human beings, but it is not in a form that the computer can run. Before you
can run your program and see the results, you need to compile it into an executable
program. This is done using a program called a compiler. All of these terms are covered
later in this document and in the lecture next week.
For the C# programming language, the compiler is a program called csc.
At the command prompt, type the following:
csc hello.cs
If you typed in the program correctly, your command window should look something like
figure 10.
Week 1 - 10 - 4CC050 Software Development 1