Programming on Algorithmic Languages

Содержание

Слайд 2

1.1 General Notes About C++ and This Course

Course geared toward novice programmers
Stress

1.1 General Notes About C++ and This Course Course geared toward novice
programming clarity
C and C++ are portable languages
Portability
C and C++ programs can run on many different computers
Compatibility
Many features of current versions of C++ not compatible with older implementations

Слайд 3

1.1 General Notes About C++ and This Course

What do you need?
Books:
C++ How

1.1 General Notes About C++ and This Course What do you need?
to Program, Fifth (fourth) Edition By H. M. Deitel -  Deitel & Associates
C++A Beginner’s Guide By Herbert Schildt
Absolute C++ By Walter Savitch
IDE:
Microsoft Visual C++ 2008 (Express or Professional editions)
Sites:
http://cplusplus.com/
http://e-practice.org
http://www.iitu.kz/
Your Mind (Brain)

Слайд 4

1.2 Introduction to C++ Programming

C++ language
Facilitates structured and disciplined approach to computer

1.2 Introduction to C++ Programming C++ language Facilitates structured and disciplined approach
program design
Following several examples
Illustrate many important features of C++
Each analyzed one statement at a time
Structured programming
Object-oriented programming

Слайд 5

1.3 Basics of a Typical C++ Environment

C++ systems
Program-development environment
Language
C++ Standard Library

1.3 Basics of a Typical C++ Environment C++ systems Program-development environment Language C++ Standard Library

Слайд 6

1.3 Basics of a Typical C++ Environment

Phases of C++ Programs:
Edit
Preprocess
Compile
Link
Load
Execute

1.3 Basics of a Typical C++ Environment Phases of C++ Programs: Edit

Слайд 7

1.3 Basics of a Typical C++ Environment

Input/output
cin
Standard input stream
Normally keyboard
cout
Standard output stream
Normally

1.3 Basics of a Typical C++ Environment Input/output cin Standard input stream
computer screen
cerr
Standard error stream
Display error messages

Слайд 8

1.3 A Simple Program: Printing a Line of Text

Comments
Document programs
Improve program readability
Ignored by

1.3 A Simple Program: Printing a Line of Text Comments Document programs
compiler
Single-line comment
Begin with //
Preprocessor directives
Processed by preprocessor before compiling
Begin with #

Слайд 9

1 // Fig. 1.2: fig01_02.cpp
2 // A first program in C++.
3 #include

1 // Fig. 1.2: fig01_02.cpp 2 // A first program in C++.

4
5 // function main begins program execution
6 int main()
7 {
8 std::cout << "Welcome to C++!\n";
9
10 return 0; // indicate that program ended successfully
11
12 } // end function main

Welcome to C++!

Слайд 10

1.31 A Simple Program: Printing a Line of Text

Standard output stream object
std::cout
“Connected” to

1.31 A Simple Program: Printing a Line of Text Standard output stream
screen
<<
Stream insertion operator
Value to right (right operand) inserted into output stream
Namespace
std:: specifies using name that belongs to “namespace” std
std:: removed through use of using statements
Escape characters
\
Indicates “special” character output

Слайд 11

1.31 A Simple Program: Printing a Line of Text

1.31 A Simple Program: Printing a Line of Text

Слайд 12

1 // Fig. 1.4: fig01_04.cpp
2 // Printing a line with multiple statements.
3

1 // Fig. 1.4: fig01_04.cpp 2 // Printing a line with multiple
#include
4
5 // function main begins program execution
6 int main()
7 {
8 std::cout << "Welcome ";
9 std::cout << "to C++!\n";
10
11 return 0; // indicate that program ended successfully
12
13 } // end function main

Welcome to C++!

Слайд 13

1 // Fig. 1.5: fig01_05.cpp
2 // Printing multiple lines with a single

1 // Fig. 1.5: fig01_05.cpp 2 // Printing multiple lines with a
statement
3 #include
4
5 // function main begins program execution
6 int main()
7 {
8 std::cout << "Welcome\nto\n\nC++!\n";
9
10 return 0; // indicate that program ended successfully
11
12 } // end function main

Welcome
to
C++!

Слайд 14

1.4 Variables

Variables
Location in memory where value can be stored
Common data types
int

1.4 Variables Variables Location in memory where value can be stored Common
- integer numbers
char - characters
double - floating point numbers
Declare variables with name and data type before use
int integer1;
int integer2;
int sum;
Can declare several variables of same type in one declaration
Comma-separated list
int integer1, integer2, sum;

Слайд 15

Variables
Variable names
Valid identifier
Series of characters (letters, digits, underscores)
Cannot begin with digit
Case sensitive

1.4

Variables Variable names Valid identifier Series of characters (letters, digits, underscores) Cannot
Variables

Слайд 16

1.5 Memory Concepts

Variable names
Correspond to actual locations in computer's memory
Every variable has

1.5 Memory Concepts Variable names Correspond to actual locations in computer's memory
name, type, size and value
When new value placed into variable, overwrites previous value
Reading variables from memory nondestructive

Слайд 17

1.5 Memory Concepts

std::cin >> integer1;
Assume user entered 45
std::cin >> integer2;
Assume user entered

1.5 Memory Concepts std::cin >> integer1; Assume user entered 45 std::cin >>
72
sum = integer1 + integer2;

Слайд 18

1.6 Data types

C and C++ have four basic built-in data types, described

1.6 Data types C and C++ have four basic built-in data types,
here for binary-based machines.
char is for character storage and uses a minimum of 8 bits (one byte) of storage, although it may be larger.
int stores an integral number and uses a minimum of two bytes of storage.
The float and double types store floating-point numbers, usually in IEEE floating-point format. float is for single precision floating point and double is for double-precision floating point.

Слайд 19

1.6 Data types

1.6 Data types

Слайд 20

1.6 Data types

Specifiers
Specifiers modify the meanings of the basic built-in types and

1.6 Data types Specifiers Specifiers modify the meanings of the basic built-in
expand them to a much larger set. There are four specifiers:
Long
Short
Signed
Unsigned

Слайд 21

1.6 Data types

The exact sizes and ranges of values for the fundamental

1.6 Data types The exact sizes and ranges of values for the
types are implementation dependent.
The range of values a type supports depends on the number of bytes that are used to represent that type.
Consider a system with 4 byte (32 bits) ints.
signed int type, the nonnegative values are in the range 0 to 2,147,483,647 (231 1).
signed int type, the negative values are in the range 1 to 2,147,483,648 (231).
unsigned int on the same system would use the same number of bits to represent data, but would not represent any negative values.

Слайд 22

1.6 C++ Data Types

The guaranteed
minimum range for
each type as
specified

1.6 C++ Data Types The guaranteed minimum range for each type as
by the
ANSI/ISO C++
standard

Слайд 23

1. C++ Data Types

1. C++ Data Types

Слайд 24

1.7 Arithmetic

Arithmetic calculations
*
Multiplication
/
Division
Integer division truncates remainder
7 / 5 evaluates

1.7 Arithmetic Arithmetic calculations * Multiplication / Division Integer division truncates remainder
to 1
%
Modulus operator returns remainder
7 % 5 evaluates to 2

Слайд 25

1.7 Arithmetic

Rules of operator precedence
Operators in parentheses evaluated first
Nested/embedded parentheses
Operators in innermost

1.7 Arithmetic Rules of operator precedence Operators in parentheses evaluated first Nested/embedded
pair first
Multiplication, division, modulus applied next
Operators applied from left to right
Addition, subtraction applied last
Operators applied from left to right

Слайд 26

1.7 Arithmetic

1.7 Arithmetic

Слайд 27

1.8 Decision Making: Equality and Relational Operators

if structure
Make decision based on truth

1.8 Decision Making: Equality and Relational Operators if structure Make decision based
or falsity of condition
If condition met, body executed
Else, body not executed
Equality and relational operators
Equality operators
Same level of precedence
Relational operators
Same level of precedence
Associate left to right

Слайд 28

1.8 Decision Making: Equality and Relational Operators

1.8 Decision Making: Equality and Relational Operators

Слайд 29

1 //
2 // Using if statements, relational
3 // operators, and equality operators.
4

1 // 2 // Using if statements, relational 3 // operators, and
#include
5
6 using std::cout; // program uses cout
7 using std::cin; // program uses cin
8 using std::endl; // program uses endl
9
10 // function main begins program execution
11 int main()
12 {
13 int num1; // first number to be read from user
14 int num2; // second number to be read from user
15
16 cout << "Enter two integers, and I will tell you\n"
17 << "the relationships they satisfy: ";
18 cin >> num1 >> num2; // read two integers
19
20 if ( num1 == num2 )
21 cout << num1 << " is equal to " << num2 << endl;
22
23 if ( num1 != num2 )
24 cout << num1 << " is not equal to " << num2 << endl;
25

Слайд 30

26 if ( num1 < num2 )
27 cout << num1 << "

26 if ( num1 27 cout 28 29 if ( num1 >
is less than " << num2 << endl;
28
29 if ( num1 > num2 )
30 cout << num1 << " is greater than " << num2 << endl;
31
32 if ( num1 <= num2 )
33 cout << num1 << " is less than or equal to "
34 << num2 << endl;
35
36 if ( num1 >= num2 )
37 cout << num1 << " is greater than or equal to "
38 << num2 << endl;
39
40 return 0; // indicate that program ended successfully
41
42 } // end function main

Слайд 31

Enter two integers, and I will tell you
the relationships they satisfy:

Enter two integers, and I will tell you the relationships they satisfy:
7 7
7 is equal to 7
7 is less than or equal to 7
7 is greater than or equal to 7

Enter two integers, and I will tell you
the relationships they satisfy: 22 12
22 is not equal to 12
22 is greater than 12
22 is greater than or equal to 12

Слайд 32

Readings:

C++ How to Program, By H. M. Deitel
Chapter 1. Introduction to Computers, the Internet

Readings: C++ How to Program, By H. M. Deitel Chapter 1. Introduction
and World Wide Web
Chapter 2. Introduction to C++ Programming
Имя файла: Programming-on-Algorithmic-Languages-.pptx
Количество просмотров: 354
Количество скачиваний: 0