Lab SessionI CSIT120 Spring2001 - PowerPoint PPT Presentation

About This Presentation
Title:

Lab SessionI CSIT120 Spring2001

Description:

It will ask you some funny question(s), say 'Yes' to all ... Text to be displayed is surrounded by double quotes in the cout statement. ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 23
Provided by: sunyfr
Category:

less

Transcript and Presenter's Notes

Title: Lab SessionI CSIT120 Spring2001


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

2
Lab 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

3
Using 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

4
Using 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

5
Suggested 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

6
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

7
Visual Studio Introduction
  • Visual Studio is a suite of programming tools
    from Microsoft. C is a part of this suite.
  • Launch Visual Cfrom 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

8
Visual 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

9
Using 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 filenewfilesCSource 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

10
Using 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 BuildBuild
  • It will ask you some funny question(s), say Yes
    to all
  • Once built, the project can be executed from
    BuildExecute or ! icon

11
The 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.

12
The 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
  • is a directive to include a header file. Header
    files contain names of the functions to be used
    by the program.

13
The 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

14
The Anatomy of a C Program
  • coutscreen (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

15
The 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().

16
The 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

17
Lab Demo Due In-Class
  • Please perform Experiment 1.4 and 1.5 and give
    the report to the Teaching Assistant

18
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

19
QA
  • Why is 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?

20
Lab 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

21
Lab 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.

22
Practicing 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?
Write a Comment
User Comments (0)
About PowerShow.com