You are on page 1of 31

Course Goals Logistics Student Input Computers Algorithms Recap

CMP1401: Introduction to Programming with C


0 1
Ece Gelal Soyak
14
P
Bahçeşehir Üniversitesi

C M Week 1: Introduction
Oct. 13, 2020

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 1 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Target Audience

Everyone.
0 1
14
Programming is an asset that every engineer and every scientist
should have for a successful career

P
In this room: students enrolled in EEE, MCH, any others?

C M
CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 2 / 31
Course Goals Logistics Student Input Computers Algorithms Recap

Course Coverage

Fundamentals of programming in C

0 1
Understand computer programming fundamentals

14
Upon successful completion of this course, you’ll be able to:

Analyze a problem and develop basic algorithms to solve it

P
Implement the algorithm using the C programming language
Practice and improve programming on your own

C M
Have the foundation that is essential for you to build on in your future
courses/internships/projects

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 3 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Tentative Outline

Week
1)
2)
Date
Oct. 13/14/15
Oct. 20/21/22
Subject

0 1
Course outline, introduction to computer systems
Basics of C programming; data types, assignments

4
Oct. 27/Nov.
3) Operators and conditional statements
4/Nov. 5

1
4) Nov. 3/11/12 do-while/while/for loops; switch statement
5) Nov. 10/18/19 Nested loops
6) Nov. 17/25/26 Functions
7)
8)
Nov. 24/Dec.
2/Dec. 3
Dec. 1/9/10
Midterm exam
Functions (cont’d)
P
9)
10)
11)
12)
13)
Dec. 8/16/17
Dec. 15/23/24
Dec. 22/30/31
Dec. 29/Jan.
6/Jan. 7
Jan. 5/13/14 C M Arrays
Pointers
Passing pointers to a function
Searching in arrays
Strings, string operations
14) Jan. 11/18/19 Semester recap

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 4 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Resources

(optional) Books:
0 1
14
C How to Program, Deitel & Deitel, Prentice Hall
The C Programming Language, Kernighan & Ritchie, Prentice Hall

P
References
http://www.cprogramming.com/

M
www.stackoverflow.com/

C
Additional online resources announced via itslearning

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 5 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Lectures

Delivered online through MS Teams


0 1
Lectures on:
Section IV: Tuesdays 13:30-15:20
Section VI: Wednesdays 16:30-18:20
14
Section V: Thursdays 16:30-18:20

P
C M
Office Hours: Fridays 9:30-10:30, Online on MS Teams

Typical lecture: Recap&questions, new topic, exercises

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 6 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Attendance

0 1
14
Attendance is mandatory (will take attendance through MS Teams)

Students must attend at least 9 out of 14 lectures


P
C M
CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 7 / 31
Course Goals Logistics Student Input Computers Algorithms Recap

Grading

A. Midterm [30%]
Covering all topics until Week 7.

0 1
B. Final [40%]

14
Cumulative final exam covering all topics. Date and time will be announced at the

P
end of the semester.

C. Quizzes [10%]

in total.

D. Lab work [20%]


C M
A few short-answer questions covering topics from the previous lectures. 2 quizzes

This assessment will be handled by the teaching assistant.

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 8 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Please Do’s

Attend the lectures

0 1
4
Check class website for updates/announcements/syllabus

1
Spend at least 1 hour every week on this class (excluding lecture time!)
Suggested readings, course notes review

P
More hours will be necessary before quizzes/midterm/final

Ask questions when unclear. We’ll discuss in class, you’ll help your
classmates too!

C
Attend the exams at all cost
M
Make-up for Midterm or Final will be available only if you supply a formal
paperwork

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 9 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Cheating & Plagiarism

Collaboration is strongly encouraged; however, the work you hand in


must be solely your own.

0 1
14
Cheating and plagiarism are very serious offenses and will be
penalized accordingly by the university disciplinary committee.
Copying answers on exams, homeworks, lab works
Using prohibited material on exams

P
Lying to gain any type of advantage in class

exam, lab, etc.

C M
Modifying graded material to be re-graded
Causing harm to colleagues by distributing false information about an

Turning in someone else’s work as your own


(www.plagiarism.org)

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 10 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Student Input

0 1
Any questions?
Anything you would change?
14
Any topics you would particularly like covered?
P
C M
CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 11 / 31
Course Goals Logistics Student Input Computers Algorithms Recap

What is a Computer?

Computer: A device capable of performing computations and making


logical decisions

0 1
Hardware (physical components)
Processor

14
P
Memory
I/O devices (keyboard, monitor, mouse)

How does it work?

C M
Executes very simple instructions
Executes them incredibly fast
Must be programmed – the software determines what a computer
actually does

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 12 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Hardware Components of a Computer

0 1
14
P
C M
CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 13 / 31
Course Goals Logistics Student Input Computers Algorithms Recap

Software Applications

Create games; create apps

0 1
Most engineering activities
involve software
e.g. aircraft communication,
14
P
telecommunications, energy
monitoring, Mars rovers,
chip manufacturing

Other sectors

C
banking, automobiles,M
defense, bioinformatics

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 14 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

How to Program?

Problem -- understand the problem precisely


(usually defined by the user to the programmer)

0 1
Solution -- find a solution to the problem

14
Algorithms -- express the solution as (a set of) algorithm(s)

P
Programming -- implement these algorithms as a set of instructions that
a computer can follow (source code)

C M
Program using a programming language, e.g. C

Executable -- run the C compiler to translate the source code into an


executable program
The user can then run the executable program on a computer and
obtain the solution to the problem

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 15 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Algorithms

A procedure defined to solve a problem


sequence of instructions that obtains the solution

0 1
Must satisfy:

14
non ambiguity -- the instructions must be interpretable in a unique
way by whomever is executing them

P
executability -- it must be possible to execute each instruction (in a
finite amount of time) given the available resources

M
finiteness -- the execution of the algorithm must terminate in a finite
amount of time for each possible set of input data

C
First we design an algorithm, next we code it in the selected
programming language

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 16 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Example

0 1
4
Problem: We want to know the age difference between two persons

General outline of solution:


1. Get the ages from users
a. Ask user for first age
b. Ask user for second age
P 1
3. Print the result

C M
2. Subtract second age from first age

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 17 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Important: Consider All Inputs!

Previous solution looks OK except if the first person is younger

0 1
Algorithm revised for inputs:
1. Get the ages from user.
14
P
a. Ask user for first age.
b. Ask user for second age

M
2. Subtract the smaller age from the greater one
a. If first age is greater than second, subtract second age from first age

C
b. Otherwise, subtract first age from second age
3. Print the result.

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 18 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Important Points When Designing Algorithms

Machines do not have judgement or intuition


0 1
We need to be aware of the assumptions we make

14
P
Need to consider the initial conditions (initial state)

Be careful not to overlook a step in the procedure just because it


seems obvious

C M
Consider rare conditions (Edge Cases)

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 19 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Presenting Algorithms

0 1
14
P
Flowchart
C M Pseudocode

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 20 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Flowcharts

A visual representation of the sequence of


steps and decisions needed to perform a
process
0 1
Each step in the sequence is noted within
a diagram shape
14
Steps are linked by connecting lines and
directional arrows
P
Flowchart rules:

C M
All flowcharts begin with Terminal or
Process symbols
All boxes must be connected with arrows
Decision symbols have 2 exit arrows
(TRUE/YES and FALSE/NO)

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 21 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Example: Decision on a Flowchart

0 1
14
P
C M
CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 22 / 31
Course Goals Logistics Student Input Computers Algorithms Recap

Loops on a Flowchart

Two examples:

0 1
14
P
C M
CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 23 / 31
Course Goals Logistics Student Input Computers Algorithms Recap

Pseudocodes

Compact and informal high definition description of a program

0 1
mathematical notation

14
The algorithm is outlined using English statements and compact

P
intended for human reading rather than machine reading

Simple guidelines for writing pseudocode


Use simple English

C M
Put one command on a line
Place any important words in bold
Start from the top and work toward the bottom
Separate processes with spaces to form modules

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 24 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Example Pseudocode - 1

0 1
14
P
C M
CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 25 / 31
Course Goals Logistics Student Input Computers Algorithms Recap

Example Pseudocode - 2

0 1
14
P
C M
CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 26 / 31
Course Goals Logistics Student Input Computers Algorithms Recap

Exercise: Add User’s Two Numbers

Algorithm: (in simple English)

0 1
Initialize sum=0 (PROCESS)
Ask the user for two numbers
14
P
(I/O)

Add the numbers and store

M
the result in sum (PROCESS)
Print sum (I/O)

C
CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 27 / 31
Course Goals Logistics Student Input Computers Algorithms Recap

Exercise: Add User’s Five Numbers (1/3)

Algorithm: (in simple English)

Initialize sum=0 and count=0 (PROCESS)


0 1
Take a number from user (I/O)

Find sum+number and assign it to sum (PROCESS)


14
Increment count (PROCESS)
P
M
If count is less than 5, take another number from user (DECISION)
If count is equal to 5, exit loop and display sum (I/O)

C
How can you change this algorithm and get the same solution?

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 28 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Add User’s Five Numbers: Pseudocode (2/3)

Initialize sum=0 and count=0


1.
0
sum=0; count=0;1
Take a number from user

Find sum+number and assign 4.


2.
3.

14 take a number as input;


sum = sum + number;
count = count + 1;

P
it to sum 5. if count = 5 then
Increment count 6. output sum;

another number from user

C M
If count is less than 5, take

If count is equal to 5, exit


loop and display sum
7.
8.
9.
else

end
go to Step 2;

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 29 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Add User’s Five Numbers: Flowchart (3/3)

Initialize sum=0 and count=0

0 1
4
Take a number from user

Find sum+number and assign


it to sum
Increment count
P 1
C M
If count is less than 5, take
another number from user
If count is equal to 5, exit
loop and display sum

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 30 / 31


Course Goals Logistics Student Input Computers Algorithms Recap

Summary

We will learn the basics of programming in this class

0 1
Algorithms are the first step to solving a problem

14
Algorithms can be represented as a flowchart or pseudocode

P
There are certain rules that must be followed in designing algorithms

M
There is usually more than one way to solve a problem
Multiple different algorithms can solve the same problem

C
Next week: we dive in to programming!

CMP1401: Introduction to Programming with C Week 1 – Oct. 13, 2020 31 / 31

You might also like