0% found this document useful (0 votes)
72 views66 pages

Introduction To Computer Programming: Course 1 29-09-2011

This document provides an introduction and overview of a computer programming course in C language. It discusses the course content which includes logical schemes, data types, constants, variables, expressions, input/output functions, and control structures. It also describes the examination process, which involves multiple written tests and practical tests. The course content will cover topics like arrays, strings, functions, pointers, files handling, and graphics programming in C.

Uploaded by

Hellen Ellen
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views66 pages

Introduction To Computer Programming: Course 1 29-09-2011

This document provides an introduction and overview of a computer programming course in C language. It discusses the course content which includes logical schemes, data types, constants, variables, expressions, input/output functions, and control structures. It also describes the examination process, which involves multiple written tests and practical tests. The course content will cover topics like arrays, strings, functions, pointers, files handling, and graphics programming in C.

Uploaded by

Hellen Ellen
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 66

INTRODUCTION TO COMPUTER PROGRAMMING

Course 1 29-09-2011

Who am I?
Adriana ALBU Lecturer at Automation and Applied Informatics Department from Automation and Computers Faculty [email protected] www.aut.upt.ro/~adrianaa

Where you can find me?

Electro building, 6th floor


office B616
3

About the course


Every week:
3 hours of course Tuesday, 17-20 2 hours of laboratory lessons:
Tuesday 13-15 8-10 10-12 12-14 14-16 10-12 Monday Monday Monday Monday Monday Monday

Electrical engineering Civil engineering

A304 Dadiana CIMAN

B613 12-14 Lavinia DRAGOMIR


4

About the examination


Distributed evaluation several marks
2 written examinations (multiple choice written tests) in the 6th and the 11th weeks
you have the possibility to improve your marks at written tests the average of these 2 marks = 2/3 of the final mark

2 practical tests in the 7th and the 12th weeks


the marks from practical tests can be also improved the average of these 2 marks = 1/3 of the final mark

It is mandatory to get marks greater or equal to 5 in all these tests 5

Where you can find the courses?


My webpage:
http://www.aut.upt.ro/~adrianaa/teaching.html

Etc intranet:
https://intranet.etc.upt.ro/?page=english

The content of the course


Course 1
Introduction Logical schemes Data types (integer, real, char, logical) Constants, variables, expressions

Course 2
A first C program Input/Output functions Mathematical and other functions Possible errors

The content of the course


Course 3
Instructions (simple, alternative, repetitive)

Course 4
Arrays Strings

Course 5
User defined functions

First written test (the 6th week)


8

The content of the course


Course 6
User defined types Pointers

Course 7
Handling with files in C (first part)

Course 8
Handling with files in C (second part)

Course 9
Graphics programming in C

Second written test (the 11th week)

Content
Introduction
Logical schemes Constants, variables, expressions Data types (integer, real, char, logical)
10

Introduction
Why do you need this course? Some of you to learn basic knowledge about informatics and structured programming The others to consolidate and to order the knowledge that they already have

11

Introduction
What will you learn at this course? Fundamental notions about informatics Computer programming using C language

12

Introduction
Information concept with a diversity of meanings closely related to: control, data, communication, instruction, knowledge, meaning, perception, representation, pattern In the computer world, data and knowledge are not really meanings of information; they are connected to information

13

Introduction
1.Data the raw material
(body temperature of a patient is 40)

2.Information the processed data


(the standard temperature of the body is 37, so the patient has a temperature with 3 greater than the standard)

3 2 1
14

3.Knowledge an information with a special meaning (interpreted information)


(if the temperature of a patient is with 2 or more degrees greater than the standard, than the patient is in danger)

Introduction
Informatics - studies the structure, behavior, and interactions of natural and artificial systems that store, process and communicate information Since computers, individuals and organizations all process information, informatics has technological, cognitive and social aspects

15

Introduction
Communication a very important concept:
between people - language

people to computer programming language

16

Introduction
Programming language
used to tell to a computer how to do a special job like a human language, a programming language has words, sentences, and well defined syntactical rules the sentences are combined in order to make a program which will be responsible for the communication between a person and a computer

17

Introduction
One of the major programming paradigms is structured programming It states that three ways of combining elements of a program are sufficient to express any computable function:
sequencing, selection, and iteration

18

Introduction
There are three steps which have to be made in order to solve a problem:
analyzing the problem to establish exactly what are the requirements representing the problem in an adequate way for computer aid solving implementing writing the program that will solve the problem (in a specific language)
Analysis Representation Implementation
19

Introduction
Algorithm - a finite list of well-defined steps for accomplishing some tasks Example: Euclids algorithm

Logical diagrams
the simplest way to represent an algorithm are made of graphical elements

20

Logical diagrams elements


START block shows the start of the algorithm (program)
STOP block marks the end of the program
START

STOP

21

Example
A program that does nothing

START

STOP

22

Logical diagrams elements


Input block used to read users data
read a

Output block used to write the results


write a
23

Example
A program that prints the message Hello world!
START

Hello world!

STOP

24

Example
A program that reads and writes a number
START

read a

write a

STOP
25

Logical diagrams elements


Calculation operations block executes some

x=7*5

26

Example
START
read a, b

First degree equation ax+b=0

x=(-b)/a

write x

STOP

Is it totally correct? We have to verify if a0


27

Logical diagrams elements


Decisional block evaluates conditions

NO

YES

NO

a0

YES

28

Example first degree equation


START

ax+b=0

read a, b
b=0
YES

a=0

NO

NO

b0 No solutions

b=0

YES

x=(-b)/a write x

0=0 Infinite number of solutions

STOP

29

Example surface of a square 1


START
read L

A=L2

write A

STOP
30

Example surface of a square 2


START read L

NO

L>0

YES

The square doesnt exist

A=L2

write A

STOP

31

Example surface of a square 3


START The dimension has to be positive!
NO

read L

L>0
YES

A=L2 write A STOP


32

Data types
Integer, Real, Char, Logical

Data types
Data = variables or constants Each data has a type Type = a multitude of values which has a name Types could be:
Standard
int for integer values float or double - for real values char for characters

Defined by user

Modifiers
Defines the length of the memory space allocated for a variable:
Short Long Signed Unsigned

Types and Modifiers


Type unsigned char char unsigned int Dimension Values (range) 8 bits 8 bits 16 bits
0 255 -128 127 0 65. 535 -32.768 32.767 0 4.294.967.295 -2.147.483.648 2.147.483.647

int 16 bits unsigned long int 32 bits long int 32 bits

float double long double

32 bits 64 bits 80 bits

3.4*(10^-38) 3.4*(10^38)
1.7*(10^-308) 1.7*(10^308) 3.4*(10^-4932) 1.1*(10^4932)

What is a bit?
Bit
is a binary digit, taking a value of either 0 or 1 a basic unit of information storage and communication in digital computing and digital information theory 8 bits = 1 byte

Integer type
Each integer type is a subset of integer numbers multitude (Z)
Type
int, short int unsigned int long int

Representation
16 bits with sign

Values (range)
-32.768 32.767

16 bits without sign 0 65.535 32 bits with sign 2.147.438.648 2.147.438.647

unsigned long int 32 bits without sign 0 4.294.967.295

Integer type
Standard constants connected with integer type:
INT_MAX (maximum value of int type): 32767 INT_MIN (minimum value of int type): -32768 LONG_MAX (maximum value of long int type): 2.147.483.647 LONG_MIN (minimum value of long int type): 2.147.483.648 UINT_MAX (maximum value of unsigned int type): 65.535 ULONG_MAX (maximum value of unsigned long int type): 4.294.967.295

Example for unsigned int and int


Example 1 Example 2

{ unsigned int age; age=20; }

{ int temperature; temperature= -10; }

Integer type operations


Relational operations:
>, >=, <, <=, ==, != (0 is false, anything else is true)

Arithmetical operations:
+, -, *, /, %

Logical operations
for variables: and &&, or ||

Integer type operations


Increment x++; ++x
x x+1 (after or before using)

Decrement x--; --x


x x-1 (after or before using)

Example
x=7; a=x++; result: a=7, x=8 x=7; a=++x; result: a=8, x=8

Real type
Real numbers are written in floating point format
Type float double long double Represen- Values (range) tation 32 bits 3.4E-38 3.4E38 64 bits 80 bits 1.7E-308 1.7E308 3.4E-4932 1.1E4932

Real type operations


Relational
Classical operators ( >, >=, <, <=, ==, !=) The result is a value that can be interpreted as true or false e.g. 17.4 < 21.3 true

Arithmetical
Operators: + , - , * , / Real operands and real result e.g. 7/2 = 3, but 7.0/2.0 = 3.5.

Char type
It is the multitude of all possible chars
Type Representation Values (range) 0 255 -128 127 unsigned char 8 bits char 8 bits

All characters are converted in integer numbers American Standard Code for Information Interchange (ASCII)

ASCII
SP 32 0 48 @ 64 P ! 33 1 49 A 65 Q 34 2 50 B 66 R # 35 3 51 C 67 S $ 36 4 52 D 68 T % 37 5 53 E 69 U & 38 6 54 F 70 V 39 7 55 G 71 W ( 40 8 56 H 72 X ) 41 9 57 I 73 Y * 42 : 58 J 74 Z + 43 ; 59 K 75 [ , 44 < 60 L 76 \ 45 = 61 M 77 ] . 46 > 62 N 78 ^ / 47 ? 63 O 79 _

80
` 96 p 112

81
a 97 q 113

82
b 98 r 114

83
c 99 s 115

84
d 100 t 116

85
e 101 u 117

86
f 102 v 118

87
g 103 w 119

88
h 104 x 120

89
I 105 y 121

90
j 106 z 122

91
k 107 { 123

92
l 108 124

93
m 109 } 125

94
n 110 ~ 126

95
o 111

127

Char type
c1 = A; c2 = 7; c3 = \n; /* newline */ c4 = \t; /* tab */
Standard operators and functions
c1+c2 x

Relations between operands of char type


C<D is true, 8<6 is false, A>1 is true

Logical type
This is not a standard type in C There are used integer values in order to represent logical aspects
False is 0 True anything else

Logical type operations


Relational: == ,< ,>,<=,>= ,!=
The result is a logical value

Logical operations:
not ! or || and &&

Logical type operations


a false false true true b false true false true not a (!a) true true false false a or b (a || b) false true true true a and b (a && b) false false false true

Type conversion cast


We can require an explicit type conversion, using the construction (type)expression Example: double a=10.25; int i; i=(int)a;

Constants, Variables, Expressions

Constants, variables, expressions


Instructions from a program works with data:
variables quantities that can change their value during the execution of the program constants quantities that cannot change their value during the execution of the program

Constants, variables, expressions


Declarations presents the variables that will be used in the program (eventually their initial values) Operators specifies the action that has to be done with the variables and the constants Expressions put together variables and constants in order to produce new values

Constants
Constants can be: Defined by the user
Numerical Alphanumerical Example of constants defined by the user const m=-3; const n=fabs(m)-1;

Symbolic constants (M_PI=3.14, INT_MAX)

Variables
In a C program it has to be declared any variable that appear in that program Declaration connection between the symbolic name of the variable and its type int m,n; float v,w; char ch1,ch2;

Variables
A variable is in fact the symbolic name of a memory location Using a declaration, that memory location will have:
a name and a type

This memory location will store a value of the declared type

Variables declaration
type_var name_var;
type_var is a the type of the variable which I declare name_var is the name of a variable or a list with the names of more variables The variable can receive an initial value when it is declared

Variables declaration
Integers variables are used to store integer numbers
int number; int no_students = 165;

Real variables, used as float variables, store floating point numbers


float variable = 0.0; float real_number = 1234567.89;

Char variables can memorise the values of a char


char first_letter = A; char a_letter= X;

How to name variables and constants


A name of a variable or of a constant is made by letters, numbers or special signs, according with few rules:
the first character must be a letter or the underscore sign (name or _name) dont use characters like #, $ or space in the name C language is case sensitive (so var1 and Var1 are two different names) there are some key words that cannot be used as name of variables or of constants (is not allowed to declare a variable with the name float or if) 60

Expressions
It is represented by some operations that are made with operands (constants, variables, functions) The result is a value The type of the result depends of the type of the operands

Expressions
E = simple expression [relational operators simple expression] relational operators: <, <=, >, >=, ==,!= A simple expression has:
terms additive operators (+, -, OR, XOR)

A term has
factors multiplicative operators (*,/,%, AND)

Expressions
A factor can be:
a constant a variable (represented by its value) & followed by a variable NOT other factor + or - other factor call of a function type conversion other expression written between ()

Operators
Multiplicative operators: *, /, % Additive operators: +, - (binary and unary) Composed operators: +=, -=, *=, /=, %=
(e.g. x+=3 x=x+3)

Increment/Decrement operators ++, - (e.g. x++, ++x, x--, --x)

& operator
placed in front of a variable (&x) represents the memory address of a variable

Next time
The first steps in programming
C environment A first program The structure of a program Input/output functions Mathematical and other functions

65

Problems logical diagrams


1. Second degree equation
ax2+bx+c=0

2. The surface of a triangle whose sides have lengths a, b, and c using Herons formula: A s( s a )( s b )( s c )
s the semiperimeter of the triangle

3. Euclids algorithm
Greatest common divisor (GCD) of two natural numbers

4. The first 20 Fibonacci numbers


f1=1, f2=1, , fi=fi-1+fi-2
66

You might also like