Professional Documents
Culture Documents
Computing
Introduction
Basic info about the course
• Aim: To teach basic programming skills
• Course web site:
http://www.cmpe.boun.edu.tr/courses/cmpe150/fall2008
• There is no difference between the sections.
• There are some changes in the organization of
the course.
• 5 hours of class every week
– 1 hour lecture and 2 hours PS (lectured by the
instructor)
– 2 hours lab (taught by an assistant; student
assistants will also help the assistant)
Fall 2008 CMPE 150 – Introduction to Computing 2
VERY IMPORTANT NOTICE
• All announcements are made through the CMPE150 e-mail list. The
list has been constructed using your e-mail addresses in the
Registration system. Make sure that your address in the
Registration system is:
–your BOUN address,
–you check it every day,
–its quota is not exceeded and it is functional.
(We will re-construct the list after the add-drop period is over, so
change it now if your Registration e-mail address is not from BOUN.)
• Note that Yahoo, GMail, Hotmail, and similar addresses frequently
have problems or the messages may go to the spam folder.
• It is completely your responsibility to make sure that your account
receives the messages properly. We will send the announcements
via the mailing list and assume you read it the same day. There are
more than 350 students in this course and we do not have any
additional means to contact you if your e-mail address is not
working.
• NO EXCUSES WILL BE ACCEPTED FOR AN ANNOUNCEMENT
ALREADY MADE THROUGH THE MAILING LIST.
Fall 2008 CMPE 150 – Introduction to Computing 3
Basic info about the course
• You will have
– 2 midterms
– 1 final
– 3 projects
throughout the semester.
• The projects are NOT mandatory (except
for CMPE students). However, there will
be a question closely related with the
project in every exam.
Input /Output
Output
Output
Input
Input
APPLICATIONS
SOFTWARE
OPERATING SYSTEM
(Windows, Linux, MacOS, etc.)
HARDWARE
IR
...
Control Unit
Program Registers
R1
instr 1
R2
instr 2 .
. Arithmetic &
instr 3 .
Logic Unit
... Rm
instr n
IR
...
Control Unit
#include <stdio.h>
int main() 1110101011001001010
{ 0010101001010000100
printf("Hello world!"); Compile & Link 1010010101010100010
return 0; 1001000100101001
}
(machine code
(source code) (object code) or
executable code)
Fall 2008 CMPE 150 – Introduction to Computing 18
Statement vs. Instruction
• Our source code (in C) is composed of
statements.
– Eg: a=b+c/2;
• The corresponding machine code is composed of
instructions.
– Eg: 1101001010110010 (divide c by 2)
0110100100100101 (add it to b)
1010110110111011 (put the result in a)
– CPU is capable of executing instructions, not
statements. Statements may be too complex.
– Compiler implements each statement using several
instructions.
• Eg: The statement "a=b+c/2;" can be implemented as
temp1 = c/2
a = b + temp1
Fall 2008 CMPE 150 – Introduction to Computing 19
Why have input/output?
• A program should not always produce the
same output.
– O/w, you may keep the result and delete the
program after you run it for the first time.
• A program should be consistent; i.e., it
should not produce random results.
• Therefore, a program should take some
input, process it, and produce some
output as the result of that input.
Control Unit
#include <stdio.h>
int main() 111010101100100101000
{ 101010010100001001010
printf("Hello world!"); Compile & Link 010101010100010100100
return 0; 0100101001
}
(machine code
(source code) (object code) or
executable code)
Fall 2008 CMPE 150 – Introduction to Computing 22
Our first C program: Hello World
• Every C program has a #include <stdio.h>
main() function.
– It wraps all the statements to int main()
{
be executed. printf("Hello world");
• We make use of previously return 0;
a=10;
b=3;
c=a-b;
a=b+2;
}
• Invalid:
1a, sayı, int, $100
50 2 74 J 97 a 115 s
51 3 75 K 98 b 116 t
52 4 76 L 99 c 117 u
53 5 77 M 100 d 118 v
54 6 78 N 101 e 119 w
55 7 79 O 102 f 120 x
56 8 80 P 103 g 121 y
57 9 81 Q 104 h 122 z
... ... 82 R 105 i ... ...
65 A 83 S 106 j
a b a && b a || b
true true true true
true false false true
false true false true
false false false false
! ! exp NOT
Fall 2008 CMPE 150 – Introduction to Computing 63
Operators
• While using multiple operators in the
same expression, you should be careful
with the precedence and associativity of
the operands.
– Eg: The following does NOT check if a is
between 5 and 10.
bool = 5<a<10;
• bool will be true if a is 20. (Why?)
– Don’t hesitate to use parentheses when you
are not sure about the precedence (or to
make things explicit).