1 lab session-i csit120 spring2001 using windows using an editor using visual c++ using compiler...

22
1 Lab Session-I Lab Session-I CSIT120 Spring2001 CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session I- B)

Post on 21-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

1

Lab Session-I Lab Session-I CSIT120 Spring2001CSIT120 Spring2001

• Using Windows

• Using An Editor

• Using Visual C++

• Using Compiler

• Writing and Running Programs

• Lab-1 continues (Session I-B)

Page 2: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

2

Lab TargetsLab Targets

• We wish to learn how to program

• We would like to edit a program, compile it and run it successfully

• Therefore we need to learn editing, compiling and running programs

• This can be done under MS-Windows operating system easily

Page 3: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

3

Using WindowsUsing Windows

• MS-Windows is a user friendly system

• Mouse clicks in GUI environment make it easy to use the system.

• Switching from one task to another is done through various ways

• Cutting and pasting from one application to another is convenient way to share data

Page 4: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

4

Using an EditorUsing an Editor

• First, we should learn basic editing under Windows operating system

• We need to know how to correct a mistake, cut and paste text and save a file

• Let us do some practice sessions as prescribed in the manual. Please do experiment 1.1 in lab session 1 Pages 3-4

Page 5: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

5

Suggested EditorsSuggested Editors

• Under Ms-Windows, Wordpad and Notepad are available as editors that can handle text files

• Wordpad is better than Notepad as it remembers previously edited files

• Please save the file as “Text file--MS-DOS format” if you wish to give it an extension of .cpp (C++ source code file) or save as “all files” under Notepad

Page 6: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

6

Using Visual C++Using Visual C++

• Visual C++ is part of MS Visual Studio package

• Visual C++ is easy to use because of its integrated development environment

• It implements the C++ programming language and offers many choices for structured or object-oriented programming

Page 7: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

7

Visual Studio IntroductionVisual Studio Introduction

• Visual Studio is a suite of programming tools from Microsoft. C++ is a part of this suite.

• Launch Visual C++from Start->Programs->Visual Studio x.x->Microsoft Visual C++

• The screen will be divided into three areas

• The large grey window to the right is the work area

Page 8: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

8

Visual Studio IntroductionVisual Studio Introduction

• The narrower window to the left is the workspace window and the bottom window is the output window

• You can control the appearance of your screen by right clicking and then selecting or de-selecting various windows

• We will be developing console projects in our work, starting with single C++ files

Page 9: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

9

Using A CompilerUsing A Compiler

• We will be using Visual C++ for this course as our programming environment

• Visual C++ can be started from the Start button• Go to “file==>new==>files==>C++Source

File” to start editing a new source code file. Visual C++ provides its own editor

• Perform Experiment 1.2 in session1 Pages 4-6 of lab manual

Page 10: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

10

Using A CompilerUsing A Compiler

• Please save your file once you are done editing it. The default name of your file would be Cpp1.cpp. Change it if you do not like this name.

• Now go to menu options “Build==>Build”

• It will ask you some funny question(s), say “Yes” to all

• Once built, the project can be executed from “Build==>Execute” or “!” icon

Page 11: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

11

The Anatomy of a C++ ProgramThe Anatomy of a C++ Program

• Let us explore the structure of the C++ program that we have compiled and executed.

• The program began with comments line. All comments start with “//” or “/*”. Comments do not contribute anything in the program. Comments are for readers to understand the program later.

Page 12: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

12

The Anatomy of a C++ ProgramThe Anatomy of a C++ Program

• You are expected to put comments at all important places so anyone else can read and understand your source code

• The line with– #include <iostream.h>

• is a directive to include a “header” file. Header files contain names of the functions to be used by the program.

Page 13: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

13

The Anatomy of a C++ ProgramThe Anatomy of a C++ Program

• C++ provides a lot of built-in functions so that programmers do not have to re-invent the wheel

• For example, displaying something on screen is a task. Everyone is not supposed to develop a program to do it

• C++ developers have already written a “program” to do it. All you need to do is to use it appropriately

Page 14: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

14

The Anatomy of a C++ ProgramThe Anatomy of a C++ Program

• cout<< is the way to display your data on the screen (Think of directing output to the screen)

• Next we see the line– void main(void)

• This line gives the name of the function that you are developing. main() is the default name used for the main function of any program

Page 15: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

15

The Anatomy of a C++ ProgramThe Anatomy of a C++ Program

• Function is a block of code that performs a given task. A function carries a name and opening and closing braces

• If there is only one function in your program, it must be named main().

Page 16: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

16

The Anatomy of a C++ ProgramThe Anatomy of a C++ Program

• The function main is started with an

opening brace { and terminated with a

closing one }• These braces identify the start and end of a

block of code. e.g. a function

• We will identify some more uses of these braces in future

Page 17: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

17

Lab Demo Due In-ClassLab Demo Due In-Class

• Please perform Experiment 1.4 and 1.5 and give the report to the Teaching Assistant

Page 18: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

18

Lab-1 Continues (Session I-B)Lab-1 Continues (Session I-B)

• We have learned– How to use a text editor in Windows– How to use Visual C++– How to compile, build and run programs in

Visual C++

• We should strengthen our knowledge by doing some more examples

Page 19: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

19

Q&AQ&A

• Why is <iostream.h> included in the program source code?

• Why do we name the only function in our program as main()?

• What is the use of opening braces and closing braces in the program?

• What is a header file?• What is cout<<?• Why do we put semicolons at the end of each statement?

Page 20: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

20

Lab ExperimentsLab Experiments

• We can introduce errors in our source code and then check the compiler error messages

• Perform Experiment 1.3 on page 8 of lab manual session-1

Page 21: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

21

Lab ExperimentsLab Experiments

• The little character “\n” inserts a newline in the display. We can use it whenever we want the next item to begin on a new line

• Text to be displayed is surrounded by double quotes in the cout statement. However double quotes are not shown when program is executed

• Perform Experiment 1.6 to learn the rules about placing quotation marks in the text.

Page 22: 1 Lab Session-I CSIT120 Spring2001 Using Windows Using An Editor Using Visual C++ Using Compiler Writing and Running Programs Lab-1 continues (Session

22

Practicing ASCII ArtPracticing ASCII Art

• Right now we have the expertise of using the output statement cout in displaying text

• We can use this expertise to display several different things.

• For example, let us show a triangle with this statement

• Can you write a program to show a triangle or a square, or an automobile with cout?