0% found this document useful (0 votes)
154 views27 pages

Structured Programming Using C++ (1) : University of Kufa Collage of Mathematics and Computer Science

The document provides an overview of structured programming using C++. It discusses key concepts like analysis, design, algorithms, flowcharts, testing, the C++ language environment, compiling and executing programs, debugging, operators, variables, constants, and escape sequences. The document is a lecture on structured programming and C++ from the University of Kufa Collage of Mathematics and Computer Science.

Uploaded by

Hasanen Murtadha
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
Download as ppt, pdf, or txt
0% found this document useful (0 votes)
154 views27 pages

Structured Programming Using C++ (1) : University of Kufa Collage of Mathematics and Computer Science

The document provides an overview of structured programming using C++. It discusses key concepts like analysis, design, algorithms, flowcharts, testing, the C++ language environment, compiling and executing programs, debugging, operators, variables, constants, and escape sequences. The document is a lecture on structured programming and C++ from the University of Kufa Collage of Mathematics and Computer Science.

Uploaded by

Hasanen Murtadha
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1/ 27

University of Kufa Collage of Mathematics and Computer Science

Structured Programming using C++(1)

9/27/2012

Introduction
C++ programming language was developed by Bjarne Stroustrup in 1983 as a better version of C. It was originally named C with Classes. It was designed to be multi-paradigm language support many different programming styles and constructs: procedural programming, data abstraction, object oriented programming, generic programming.
9/27/2012 2

Analysis
The analysis of an problem begin with determine the inputs and the outputs of the problem and then choose the right process to get the require output according to the problem

9/27/2012

Design

9/27/2012

Algorithm
Is a sequence of precise instructions that leads to a solution .the instructions of an algorithm are expressed in English, a set of instruction must completely and unambiguous.

9/27/2012

Flowchart
A flowchart is a diagram that uses graphic symbols to depict the nature and flow of the steps in a process.

Benefits of using flowcharts Basic Flowchart Symbols


9/27/2012 6

Flowchart (continue)
. Start/ Stop . Processing operation

. Input/ Output

. Decision

. connection

. Data flowing 9/27/2012 7

Testing and Maintenance


Testing the program it means debugging to check whether there is an error in it, which include test all types of errors, maintenance make the program able to add an improvement or correction thats why it should be design easy to read and easy to change(modify).

9/27/2012

C++ Language Environment


The general form of simple C++ program #include<iostream.h> The first line include<iostream.h> void main() is called an include directive it tell { the computer where to find Variable declaration; information about certain items Statement1; that are used in program, Statement1;

Statement last; }
9/27/2012

directive always begin with symbol #.The main() is main function, the braces { and } mark the beginning and end of the main part of the program
9

Compile and Execute a C++ program

Compiler is a program that translating a high-level language program into a machine language . The way of compile and run C++ depends on the particular system using, it need to give command to compile, link and run a C++ program on your system. When you give the command to compile the program this will produce a machine language of C++ program object code, it must be linked after that you can execute the program.
9/27/2012 10

Debug
Programming is a complex process, it often leads to errors. A mistake in a program is usually called bugs and the process of eliminating and correcting them is called debugging. There are a few different kinds of errors that can occur in a program, and it is useful to distinguish between them in order to correct more quickly. 1. Compile errors(syntax) 2. Logic errors(semantic) 3. Run-time errors
9/27/2012 11

Assignment statement
Variable=expression int x=10; char x=a; float x=1.3; int x(10); x=y+z; average=(m1+m2+m3)/3;

9/27/2012

12

Assignment statement (continue)


Operator += Required expression total = total + 10; C++ expression total += 10;

-=
*= /=

expense = expense 100;


salary = salary * 0.05; x= x/1.9;

expense = 100;
salary*= 0.05 x/=1.9;

9/27/2012

13

Increment and decrement


x++ sign increment the variable x by 1 x++; x=x+1; x+=1; y-- sign decrement the variable y by 1 x--; x=x-1; x-=1;

9/27/2012

14

Assignment operations
1-Arithmetic operators 2-Comparison operators 3-Logical operators 4-Unary operators
9/27/2012 15

Arithmetic operators
Operator Algebraic C++ expression Example Result

+ * / %

a+b a-b a * b (or) a x b a / b (or) a b a mod b

a+b a-b a*b a/b a%b

1+2 1-2 1*2 3/2 2%3

3 1 2 1 1

9/27/2012

16

Comparison operators
Operator C++ expression

> >= < <=

a>b a >= b a<b a <= b

= =

a == b a!=b

9/27/2012

17

Logical operators
Operator and or not C++ expression && || !

9/27/2012

18

Unary operators
Operator C++ expression

++ --

++ --

9/27/2012

19

Precedence rules
operators ++,--,() ! *,/,% +,<,<=,>,>=,==,!= && || =,+=,=,*=,/=,%=
9/27/2012

description increment, decrement, parentheses not Multiplication, division, remainder(mod) Addition , subtraction Less than, less than or equal , greater than, greater than or equal ,equal , not equal and or Assign, add and assign, sub and assign, multiple and assign, division and assign ,mod and assign

Highest precedence

Lowest precedence
20

Comment

Comments are ignored by the compiler and thus are not an executable part of the program. Comments are very important in programming languages because they make programs understandable to any one reading the code. One line comment Average = (x+ y)/ 2; // Calculate the average of two numbers The other style is useful for multiline comments. That is you enclose your comments between two characters pairs, namely /* and */. /* Putting an asterisk at the beginning of each line of a multiline comment allow people looking at the code to determine with a quick look what a comment and what is a code. */
9/27/2012 21

Case sensitive

C++ is a case-sensitive language Example: rate RATE

Rate

9/27/2012

22

Identifier

Are used as names for variable and other items in a C++ program. Variable start must start with either a letter or the underscore( _ ) symbol, and remaining characters must all be letter and digit. You can use uppercase or lowercase letters. Example: x1, Y_1, Average, area_2 Do not use special characters such as +, -, *. etc. or reserve words such as int float, main, long, char, etc.

9/27/2012

23

Variables
Every variable must be declare before using it. Variables have unique names and types and hold values that you assign them. You can initailize the variable when it declare. The type of the variable determines the size of variable that stored in computer memory. Syntax: variable_type variable_name; Example : - integer int x; - float float y=3.5; - char char x;

9/27/2012 24

Variable Types
Variable type Single Character Integer Keyword Char int Range -128 to 127 -32,786 to 32,767 Memory Requirement 1 byte 2 bytes Digits of precision __ __

Floating point
Longer integer More accurate Even more accurate floating Larger character set Positive integer Longer positive integers

float
long double long double unsigned char unsigned int unsigned long

3.4e-38 to 3.4e+38
-2,147,483,648 to 2,147,483,647 1.7e-308 to 1.7e+308 3.4e- 4932 to 1.1e+4932 0 to 255 0 0 to to 65,535

4 bytes
4 bytes 8 bytes 10 bytes 1 byte 2 bytes 4 bytes

7
__ 15 19 __ __ __

4,294,967,295

9/27/2012

25

Constant variable
When initialize a variable inside a declaration, you can make the variable is not change inside the program. This variable called constant variable. Syntax: const variable_type variable_name= constant; Example : const double pi=3.14;

9/27/2012

26

Escape sequences
Sign Meaning

9/27/2012

\n \t \v \a \b \\ \? \ \

new line tab vertical tab alert (beep) back space back slash question mark(?) single quote() double quote()

27

You might also like