Рабочие листы
к вашим урокам
Скачать
1 слайд
Programming on Algorithmic Languages
Week 1
2 слайд
1.1 General Notes About C++ and This Course
Course geared toward novice programmers
Stress 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
2
3 слайд
1.1 General Notes About C++ and This Course
What do you need?
Books:
C++ How 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 program design
Following several examples
Illustrate many important features of C++
Each analyzed one statement at a time
Structured programming
Object-oriented programming
4
5 слайд
1.3 Basics of a Typical C++ Environment
C++ systems
Program-development environment
Language
C++ Standard Library
5
6 слайд
1.3 Basics of a Typical C++ Environment
6
Phases of C++ Programs:
Edit
Preprocess
Compile
Link
Load
Execute
Primary
Memory
CPU takes each
instruction and
executes it, possibly
storing new data
values as the program
executes.
CPU
.
.
.
.
.
.
Program is created in
the editor and stored
on disk.
Editor
Disk
Preprocessor program
processes the code.
Preprocessor
Disk
Compiler
Compiler creates
object code and stores
it on disk.
Disk
Linker links the object
code with the libraries,
creates a.out and
stores it on disk
Linker
Disk
Loader
Primary
Memory
Loader puts program
in memory.
.
.
.
.
.
.
Disk
7 слайд
1.3 Basics of a Typical C++ Environment
Input/output
cin
Standard input stream
Normally keyboard
cout
Standard output stream
Normally computer screen
cerr
Standard error stream
Display error messages
7
8 слайд
1.3 A Simple Program:
Printing a Line of Text
Comments
Document programs
Improve program readability
Ignored by compiler
Single-line comment
Begin with //
Preprocessor directives
Processed by preprocessor before compiling
Begin with #
8
9 слайд
9
1 // Fig. 1.2: fig01_02.cpp
2 // A first program in C++.
3 #include <iostream>
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++!
Single-line comments.
Preprocessor directive to include input/output stream header file <iostream>.
Function main appears exactly once in every C++ program..
Function main returns an integer value.
Left brace { begins function body.
Corresponding right brace } ends function body.
Statements end with a semicolon ;.
Name cout belongs to namespace std.
Stream insertion operator.
Keyword return is one of several means to exit function; value 0 indicates program terminated successfully.
10 слайд
1.31 A Simple Program:
Printing a Line of Text
Standard output stream object
std::cout
“Connected” to 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
10
11 слайд
1.31 A Simple Program:
Printing a Line of Text
11
12 слайд
12
1 // Fig. 1.4: fig01_04.cpp
2 // Printing a line with multiple statements.
3 #include <iostream>
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++!
Multiple stream insertion statements produce one line of output.
13 слайд
13
1 // Fig. 1.5: fig01_05.cpp
2 // Printing multiple lines with a single statement
3 #include <iostream>
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++!
Using newline characters to print on multiple lines.
14 слайд
1.4 Variables
Variables
Location in memory where value can be stored
Common data types
int - 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;
14
15 слайд
Variables
Variable names
Valid identifier
Series of characters (letters, digits, underscores)
Cannot begin with digit
Case sensitive
15
1.4 Variables
16 слайд
1.5 Memory Concepts
Variable names
Correspond to actual locations in computer's memory
Every variable has name, type, size and value
When new value placed into variable, overwrites previous value
Reading variables from memory nondestructive
16
17 слайд
1.5 Memory Concepts
std::cin >> integer1;
Assume user entered 45
std::cin >> integer2;
Assume user entered 72
sum = integer1 + integer2;
17
integer1
45
integer1
45
integer2
72
integer1
45
integer2
72
sum
117
18 слайд
1.6 Data types
C and C++ have four basic built-in data types, described 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.
18
19 слайд
1.6 Data types
19
20 слайд
1.6 Data types
Specifiers
Specifiers modify the meanings of the basic built-in types and expand them to a much larger set. There are four specifiers:
Long
Short
Signed
Unsigned
20
modify the maximum and minimum values that a data type will hold.
tell the compiler how to use the sign bit with integral types and characters (floating-point numbers always contain a sign).
21 слайд
1.6 Data types
The exact sizes and ranges of values for the fundamental 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.
21
This is a total of 232 possible values
values in the range 0 to 4,294,967,295 (232 1)
22 слайд
1.6 C++ Data Types
The guaranteed
minimum range for
each type as
specified by the
ANSI/ISO C++
standard
22
23 слайд
1. C++ Data Types
23
60,000 is within the range of an unsigned short int, but is typically outside the range of a signed short int . Thus, it will be interpreted as a negative value when assigned to i.
24 слайд
1.7 Arithmetic
Arithmetic calculations
*
Multiplication
/
Division
Integer division truncates remainder
7 / 5 evaluates to 1
%
Modulus operator returns remainder
7 % 5 evaluates to 2
24
25 слайд
1.7 Arithmetic
Rules of operator precedence
Operators in parentheses evaluated first
Nested/embedded parentheses
Operators in innermost pair first
Multiplication, division, modulus applied next
Operators applied from left to right
Addition, subtraction applied last
Operators applied from left to right
25
26 слайд
1.7 Arithmetic
26
27 слайд
1.8 Decision Making: Equality and Relational Operators
if structure
Make decision based on truth 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
27
28 слайд
1.8 Decision Making: Equality and Relational Operators
28
29 слайд
1 //
2 // Using if statements, relational
3 // operators, and equality operators.
4 #include <iostream>
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
using statements eliminate need for std:: prefix.
Can write cout and cin without std:: prefix.
Declare variables.
if structure compares values of num1 and num2 to test for equality.
If condition is true (i.e., values are equal), execute this statement.
if structure compares values of num1 and num2 to test for inequality.
If condition is true (i.e., values are not equal), execute this statement.
29
30 слайд
30
26 if ( num1 < num2 )
27 cout << 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
Statements may be split over several lines.
31 слайд
31
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 and World Wide Web
Chapter 2. Introduction to C++ Programming
33 слайд
33
Thanks for your attention!
Рабочие листы
к вашим урокам
Скачать
6 671 666 материалов в базе
Настоящий материал опубликован пользователем Дроздова Ирина Михайловна. Инфоурок является информационным посредником и предоставляет пользователям возможность размещать на сайте методические материалы. Всю ответственность за опубликованные материалы, содержащиеся в них сведения, а также за соблюдение авторских прав несут пользователи, загрузившие материал на сайт
Если Вы считаете, что материал нарушает авторские права либо по каким-то другим причинам должен быть удален с сайта, Вы можете оставить жалобу на материал.
Удалить материалВаша скидка на курсы
40%Курс профессиональной переподготовки
600 ч.
Курс профессиональной переподготовки
300/600 ч.
Курс повышения квалификации
72/180 ч.
Оставьте свой комментарий
Авторизуйтесь, чтобы задавать вопросы.