Lecture 1 Log into Windows/ACENET Start Microsoft Visual Studio 2010

advertisement
Lecture 1

Log into Windows/ACENET

Start Microsoft Visual Studio 2010



Windows button -> All Programs ->
02-Programming -> Microsoft Visual Studio 2010
Choose C# as default environment, click Start
Visual Studio button
Wait for a long time... (next time should be faster)
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
1
Introduction

Introduction sheet

Course webpage


http://csserver.evansville.edu/~hwang/s11-courses/cs205.html

Handouts, assignments
Syllabus and schedule, textbooks
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
2
Outline

Software life cycle

Compilation process

MS Visual Studio C#

Console output
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
3
Software Life Cycle

Specification of the problem/task

Design of a solution

Implementation (coding) of the solution

Testing and debugging

Maintenance and evolution of the system

Obsolescence
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
4
Programming Languages

Syntax: What are the legal "sentences" in the
language?

Semantics: What do the "sentences" mean?

Compilers and interpreters enforce syntax.


Semantics determine whether the computation
is correct.
A program is not "working" if it gives the wrong
results!
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
5
Compiling vs. Interpreting

Some languages are compiled with a program
called a compiler. Source code file is
translated into a machine code file.


Examples: C/C++, Java, Pascal, COBOL, Fortran
Other languages are interpreted. An
interpreter is a program that receives
programming language statements and
executes them directly.

Examples: (original) BASIC, LISP, Prolog, LOGO
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
6
Source Code to Running Program

EDITOR -> programming language source file
-> COMPILER -> object file (+ libraries)
-> LINKER -> executable file
-> LOADER -> running program

Sometimes programs are run individually;
sometimes all work together in an Integrated
Development Environment (IDE)
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
7
C# Programming Language

Developed by Microsoft for .NET framework

Syntax similar to C++ and Java

Semantics similar to Java

Object-oriented

Built-in support to make GUIs (Graphical User
Interfaces)
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
8
Microsoft Visual Studio


Microsoft Visual Studio is an IDE for developing
applications for Windows in multiple
programming languages, including C#.
Free Express versions of each individual
compiler is available at
http://www.microsoft.com/express/Downloads/

EECS Labs have MS VS Professional.
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
9
Creating a Console Project



All C# code belongs to a project. Start with
New -> Project
Each project produces a particular kind of
application. We will be creating console
applications for the first half of semester.
After selecting the console application template,
set the Name box to "HelloWorldProgram".
Make sure the Location is on your network
drive, then click OK. A large text window and a
Solution Explorer panel will appear.
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
10
C# Programs

The C# IDE tries to be helpful by creating the
parts of code that all C# program have. This
includes:



using statements that cause (pre-defined) method
names in libraries like System to become known
namespace and class definition names based on
the project name given
a stub for the Main( ) method. The main program
code goes in this stub. It is the code that is
executed first when a program is run.
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
11
MS VS New Project Dialog
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
12
MS VS Changing Class Name
right click
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
13
MS VS Project Window
main program code
goes here!
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
14
First C# Program

Type the following code into the Main( ) stub:
Console.WriteLine("Hello World!");

Note that as you type, the C# editor suggests
items that match. Choices can be made by
using the up/down arrow keys, and selection
can be made by pressing the TAB key. (This is
called the "IntelliSense" feature of VS.)
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
15
MS VS IntelliSense
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
16
Console Output


Console.WriteLine( ) is a pre-defined method
that accepts one argument, a data item to be
displayed in the console window. It displays
this item followed by a newline character. Use
Console.Write( ), if you want to display an item
without the following newline character.
The argument in this example, "Hello World!", is
a string literal that is written using the double
quotes.
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
17
Building a Program


To build (i.e., compile) the program do Build ->
Build Solution
If there are no syntax errors, great! If there are
syntax errors, they will be listed at the bottom of
the screen. Correct and build again.
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
18
Running a Console Program


To run the program,
do Debug -> Start
Without Debugging.
This will start the
console window and
run the program, then
causes the program to
wait for the user to
press a key before the
program finishes.
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
19
Comments

Comments are lines in the source code that are
ignored by the compiler. There are two forms:



inline comments: // to the end of line
multi-line comments: /* everything between is a comment */
Every program should have at least a comment
at the beginning of the file stating who the
programmer is and what the program does:
// Programmer: Joe Codewriter
// This is the usual Hello World program
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
20
In-class Exercise


Add another line of
code that displays
"Programming is fun!"
as shown to the right.
Compile and run your
program.
Monday, January 10
CS 205 Programming for the Sciences - Lecture 1
21
Download