overview of programming language features
Download
Skip this Video
Download Presentation
Overview of Programming Language Features

Loading in 2 Seconds...

play fullscreen
1 / 32

Overview of Programming Language Features - PowerPoint PPT Presentation


  • 112 Views
  • Uploaded on

3. Overview of Programming Language Features. AIM To develop further an understanding of the transition from the design phase to the program development phase OBJECTIVES Study languages in general, and programming languages in particular

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Overview of Programming Language Features' - nile


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
overview of programming language features

3

Overview of ProgrammingLanguage Features

AIM

To develop further an understanding of the transition from the design phase to the program development phase

OBJECTIVES

  • Study languages in general, and programming languages in particular
  • Study the relationship between design notation and the facilities that mirror this in a modern programming language

V6.0

slide2

Languages: In General

Terms

3.1

  • All languages are subject to a set of rules governing
    • the set of valid characters that can be used
    • word construction
    • sentence construction
  • The rules of sentence construction are called syntax
  • To use a language correctly you need to know about these and
    • vocabulary - the set of valid words
    • semantics - ensuring that what is written makes sense
  • You need to be able to recognize language \'tokens\'
syntax rules
Syntax Rules
  • English language descriptions of language rules can be very cumbersome, and lead to ambiguity
  • Syntax diagrams are a neat way of expressing language rules
    • they should be completely unambiguous
    • they usually involve other syntactic elements (tokens)
  • What would a syntax diagram look like for
    • a word
    • a sentence
    • prose

Lesson:

The ability to read a syntax diagram is an important skill.

syntax vs semantics
Syntax vs. Semantics

Syntax - the grammatical arrangement of words to show their connection and relation; the set of rules governing this arrangement.

Semantics - relate to meaning in language

  • A sentence in English may be syntactically correct
    • it obeys the language rules
  • But not necessarily semantically correct
    • it has no valid meaning
  • Both syntax and semantics are important

Lesson:

You’ve got to put the syntactic elements together so that they are both syntactically and semantically correct.

slide5

Programming Language

Building Blocks

3.2

  • A computer program is like a set of instructions
  • Each instruction is termed a statement
  • Each program statement has a terminating character
  • Translate into syntax diagrams
types of statement
Types Of Statement
  • It’s useful to categorize statements
    • type definitions - introduce new types
    • variable declarations - introduce new objects
    • assignment statements - involve a change in the value of an object
    • I/O statements
    • compound statements - a (bracketed) collection of statements
    • control-flow statements - change the normal linear flow of control (selection, repetition, function)
    • other forms of statement
starting c programming

4

Starting C++Programming

AIM

To get started on programming in C++

OBJECTIVES

  • Understand the Systems Development Life Cycle (SDLC)
  • Simple C++ statements
  • Program layout and style
  • Simple input and output in C++
  • Comments in C++

V6.0

a first c program

Display a Greeting

#include <iostream.h>

int main()

{

cout << "Hello ";

cout << "Your name" << endl;

cout << "Welcome to MIS442" << endl;

return 0;

}

PROBLEM:

DESIGN:

Hello

Display “Hello”

Display your name

Display “Welcome to MIS442”

End

IMPLEMENTATION:

Chapter 4

Hello

4.0

A First C++ Program

Lesson:

Try things out in small test programs to determine what C++ features do.

slide9

4.1

Structure Of Simple C++

Programs

  • See syntax diagram simple C++ program
  • We’ll gradually introduce the different forms of statement that you can write in C++
    • The cout "..." ...; lines in the greeting program are statements that produce output
  • Special significance of main() and the braces { and }
  • Your programs must conform to the syntax rules of the language, as specified in the syntactic elements
  • The syntax rules allow the computer to distinguish between syntactically correct and syntactically incorrect programs
  • But what if a program doesn\'t conform?
c compile time errors

Object

Code

C++ Source

#include "..

int main()

{

...

...

} // end main()

C++

Compiler

Compiler Error Messages

Error: line 8

...

C++ Compile-Time Errors
  • What if you make a syntax mistake in your source program?

Lesson:

A single syntax error may give rise to multiple compiler error messages.

Lesson:

You’ll have to get used to the form of the compiler’s error messages.

Lesson:

It may be worth fixing the first source-code error and then recompiling.

program layout and style

4.2

Program Layout And Style
  • Are either of these C++ fragments syntactically legal?

int main(){cout<<"Hello"

;cout<<"Yourname"<<endl

;cout<<"Welcome to MIS442"

<<endl;return0;}

À

int main(){cout<<"Hello"

;cout<<"Yourname"<<endl

;cout<<"Welcome to MIS442"

<<endl; return 0;}

Á

Lesson:

The aesthetics of your program’s appearance to the human eye are very important.

Lesson:

Adopt sensible style rules and stick with them.

overall layout of c programs
Overall Layout Of C++ Programs
  • C++ is a free-format language
  • The compiler ignores white space (spaces, tabs, end of line, blank lines) in most situations

#include <iostream.h>

int main()

{

cout << "Hello ";

cout << "Your name"

<< endl;

cout << "Welcome to MIS442"

<< endl;

return 0;

}

  • Use indentation and white space to make your programs more readable. The compiler doesn’t care about white space.
simple i o in c

4.3

Simple I/O In C++

Design and write a program that asks a user to input their first name followed by their age in years, and then calculates and prints their age in hours.

PROBLEM:

DESIGN:

i o in c conti
I/O In C++ (Conti.)

#include <iostream.h>

#include <cstring.h>

cin >>

cout <<

getline(cin, variable, ‘\n’);

#include <iomanip.h>

cout.setf(ios::showpoint);

cout.setf(ios::fixed);

cout.setf(ios::right);

cout.precision(2)

cout << ... << setw(9) << ... ;

comments

4.4

Comments
  • Program statements alone are often not very readable
  • Often you wish to add some commentary to a program
  • Such comments give the reader additional information
  • There has to be a syntactic element in the language to permit this – see comment
comments1

+

// Source file name: hello.c

// A C++ program to print out a greeting message

// Edit the lines indicated below

// Include the information which defines the IO types

#include <iostream.h>

int main()

{

cout << "Hello ";

cout << "Your name" // Edit to your name

<< endl;

cout << "Welcome to MIS442" // Edit to your course

<< endl;

return 0;

} // end main()

+

+

+

4.4

Comments
comments style rules

Chapter 4

Program

Template

Comments: Style Rules
  • A program without any comments is a bad program.
  • A comment should add something to the program.
  • And not just expand on the obvious.
  • Add comments while you are implementing your program.
  • Capture design abstractions as comments in the source code.
  • Use white space to improve their readability.
  • A source file should identify the name and purpose of the program, and its author and date.
  • Use a template for new programs.
slide18

4.5

Systems /Software Development Life Cycle (SLC/ SDLC)

  • A method that provides information systems professionals with step-by-step procedures to develop their projects/systems.
  • SOFTWARE ENGINEERING ...
1 problem conceptualization
1. (Problem) Conceptualization
  • Prepare a complete and unambiguous problem statement.
  • Users and analysts sign the requirements document.
2 analysis
2. Analysis
  • Understand the problem: develop a system behavior model and determine problem input, output, and other relevant data elements.
  • Name each identified data element and develop a model of the essential characteristics (attributes and operations) for each element.
3 design
3. Design
  • Using the system and data models developed during requirements analysis, perform a top-down design of the system.
  • For each system component, identify key data elements and subordinate functions using structure charts.
4 implementation
4. Implementation
  • Write algorithms and pseudocode descriptions of individual functions.
  • Code the solution.
  • Debug the code.
5 testing and verification
5. Testing and Verification
  • Test the code, verifying that it is correct. Each data modeling component should be tested separately, before all components are tested as an integrated whole.
  • Involve users and special testing teams in all system tests.
6 operation follow up and maintenance
6. Operation, Follow-up, and Maintenance
  • Run the completed system.
  • Evaluate its performance.
  • Remove new bugs as they are detected.
  • Make required changes to keep the system up to date.
  • Verify that changes are correct and that they do not adversely affect the system’s operation.
slide25

Summary

Your first steps as a C++ programmer:

  • Use of syntax diagrams
  • Compile-time errors
  • Basic structure of simple C++ programs
  • Simple I/O in C++
  • C++ comments

Your first steps as a software engineer:

  • Program layout and white space
  • Style rules
  • Use of comments to capture the design
  • Constructing test programs to see what C++ features do
more c examples
More C++ Examples
  • miles.cpp (p. 40)
  • Hello.cpp (p.55)
  • A Case Study: Finding The Value of A Coin Collection: Coins.cpp (p.82)
sieve program
Sieve Program

IMPLEMENTATION:

Chapter 3

Sieve

OUTPUT:

summary
Summary
  • You now know about the importance of syntax and semantics
  • You know how to read syntax diagrams
  • You know about the basic features of programming languages
  • You should be able to recognize these features in many popular languages (especially C++)
  • But you don\'t know enough yet to be able to write programs ...
age in hours program

variable names

#include <iostream.h>

#include "Text.h"

int main()

{

const double HOURS_YEAR = 365.0 * 24.0;

int age;

Text name;

cout << "What is your first name? ";

cin >> name;

cout << "and what is your age in years? ";

cin >> age;

cout << "Welcome to " << name

<< " who claims to be " << (age * HOURS_YEAR)

<< " hours young" << endl;

return 0;

}

constant

declaration

variable

declarations

expression

input

statements

Age-In-Hours Program

IMPLEMENTATION:

drawing a square
Drawing A Square

Design and implement a program to draw a square.

int main()

{

// Create window and sideLength

// Input a value for sideLength

// Move to starting position

// Put the pen down

// Draw line forward

// Draw line up

// Draw line back

// Draw line down

return 0; //exit the program

} //end main()

PROBLEM:

DESIGN:

IMPLEMENTATION:

Lesson:

A useful starting point is a set of comments expressing the design.

ad