Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1 Introduction to Programming

Similar presentations


Presentation on theme: "Chapter 1 Introduction to Programming"— Presentation transcript:

1 Chapter 1 Introduction to Programming
CSC 1101 2/7/18 Chapter 1 Introduction to Programming CSC Computer Programming -1- Dr. Nouf Aljaffan (C) 2017 Nouf Aljaffan

2 Outline The course objectives Advises to success The computer programs
CSC 1101 2/7/18 Outline The course objectives Advises to success The computer programs The C programming language Stages in Program Development Process (C) 2017 Nouf Aljaffan

3 To introduce computational thinking and problem solving skills to beginner students.
To develop an understanding of the nature of programming To familiarize student with the basic of C programming language Aims

4 Learning Outcomes You will be able to
Write small C programs (Structured programming) and proper programming techniques Read and understand much larger programs Learn the basics of new programming languages by yourself

5 The Means 01 02 03 04 05 06 Read a chapter ahead Attend lectures
Study the given chapter 03 Ask questions and get feedback 04 Get hands dirty (trial and Error) 05 Form study groups 06

6 Except for the work you hand in as individual contributions, we strongly encourage you to collaborate and help each other Cooperate on Learning

7 GET HELP and SUPPORT If in doubt if a collaboration is legitimate: ask! Don’t claim to have written code that you copied from others Don’t give anyone else your code (to hand in for a grade) When you rely on the work of others, explicitly list all of your sources – i.e. give credit to those who did the work Don’t study alone when you don’t have to Do help each other (without plagiarizing) Go to my office hours or/and send me an Go prepared with questions The only stupid questions are the ones you wanted to ask but did not

8 What a computer program is?

9 CSC 1101 2/7/18 Computer program is a set of instructions which are given to a computer to be able to perform specific tasks. A specific task can be, for example, “printing a student grade”. (C) 2017 Nouf Aljaffan

10 Layers of Programming High-level language Assembly language
CSC 1101 2/7/18 Layers of Programming High-level language Similar to human language Use mathematical notations (translated via compilers) Assembly language English-like abbreviations representing elementary computer operations (translated via assemblers) Machine language Strings of numbers giving machine specific instructions Machine dependent Easier to use High-level Compiler Assembler More Powerful Low-level (C) 2017 Nouf Aljaffan

11 Why C programming?

12 Why C ? You can’t learn to program without a programming language
Evolved by Ritchie from two previous programming languages, BCPL and B Hardware independent (portable) Programming concepts that you learn using C can be used fairly directly in other languages Including C++, Java, C#, and (less directly) Fortran

13 Where is C Used? Used to develop UNIX
Used to write modern operating systems Just about everywhere Mars rovers, animation, graphics, Photoshop, GUI, OS, compilers, slides, chip design, chip manufacturing, semiconductor tools, etc.

14 The C Standard Library C programs consist of pieces/modules called functions A programmer can create his own functions Advantage: the programmer knows exactly how it works Disadvantage: time consuming Programmers will often use the C library functions Use these as building blocks Avoid re-inventing the wheel If a premade function exists, generally best to use it rather than write your own Library functions carefully written, efficient, and portable

15 Stages in Program Development Process
CSC 1101 2/7/18 1- Analysis of a problem 2- Create the algorithm 3- Compile the program 4- Execute the program 5- Testing and Debugging the Program Stages in Program Development Process (C) 2017 Nouf Aljaffan

16 (1) Analysis of a problem
Human thoughts where it should be given a solution.

17 A- Defining the Problem
Read the problem statement carefully Indicate the requirements Indicate the inputs (look for nouns) Indicate the output (look for nouns) Indicate the instructions(look for verbs)

18 Calculate the Sum and Average of 5 numbers?
CSC 1101 2/7/18 Input five numbers (x1, x2, x3, x4, x5) Instruction Sum = x1+x2+x3+x4+x5 Average = Sum/5 Output Sum Average Example 1 Calculate the Sum and Average of 5 numbers? (C) 2017 Nouf Aljaffan

19 Example 3 Read a word and capitalize the second letter word
CSC 1101 2/7/18 Example 3 Read a word and capitalize the second letter word Input Processing Output (C) 2017 Nouf Aljaffan

20 (2) Create the algorithm
Plan for solution and use basic statements and expression to develop the algorithm

21 Programming algorithm
CSC 1101 2/7/18 Programming algorithm You can think the programming algorithm as a a recipe that describes the exact steps needed for computer to solve a problem or reach a goal. You can think the programming algorithm as a recipe that describes the exact steps needed for computer to solve a problem or reach a goal (C) 2017 Nouf Aljaffan

22 Programming algorithm
Ingredients Inputs Word for a recipe Procedure Output Results

23 Programming algorithm has a start and an end
Programming algorithm is NOT a Computer CODE Programming algorithm has a start and an end Programming algorithm leads to a solution

24 B-Planning the Solution
CSC 1101 2/7/18 Pseudocode is a semi-programming language used to describe the steps in an algorithm. Flowchart is a graphical representation of an algorithm. B-Planning the Solution (C) 2017 Nouf Aljaffan

25 Example: Write a Program to Print the Sum of two integer Numbers
CSC 1101 2/7/18 Example: Write a Program to Print the Sum of two integer Numbers Start the program Read the first number and save in the variable ( N1 ) Read the second number and save in the variable ( N2 ) Sum the both numbers and save the result in the variable ( Sum )  Sum = N1 + N2 Print the variable ( Sum ) End the program start Read N1 Read N2 Sum = N1 + N2 Print Sum End (C) 2017 Nouf Aljaffan

26 (3) Compile the program Generate the source code using any programming languages. Then, compile the program.

27 CSC 1101 2/7/18 A-Coding the Program .C (C) 2017 Nouf Aljaffan

28 What is a Compiler It is a software that checks the correctness of the source code according to the language rules. If the code is free of errors: The source code will be translated into machine code. Create of an “object ” file Else: Syntax errors are raised if some rules were violated.

29 CSC 1101 2/7/18 Preprocessor In C , a preprocessor program executes automatically before the compiler translation phase begin. Preprocessor indicate that certain manipulations are to be performed on the program before compilation. (C) 2017 Nouf Aljaffan

30 (4) Execute the program If the code is error free, the program can be executed to create the output

31 4-Running The Program Linking Phase
CSC 1101 2/7/18 4-Running The Program Linking Phase Occurring before running the code Linking the object code with the code for the missing functions to produce an executable image (with no missing pieces). If the program compiles and links correctly, a file called a.out is produced. Load Phase: Before a program can be executed, the program must first be placed in memory. The computer, under the control of its CPU, executes the program one instruction at a time (C) 2017 Nouf Aljaffan

32 Basics of a Typical C Program Development Environment
Basics of a Typical C Program Development Environment Program is created in the editor and stored on disk. Preprocessor program processes the code. Loader puts program in memory. CPU takes each instruction and executes it, possibly storing new data values as the program executes. Compiler creates object code and stores it on disk. Linker links the object code with the libraries Loader Primary Memory Compiler Editor Preprocessor Linker . Disk CPU Phases of C++ Programs: Edit Preprocess Compile Link Load Execute

33 (5) Testing and Debugging the Program
To ensure there is no errors

34 5-Testing and Debugging the Program
CSC 1101 2/7/18 5-Testing and Debugging the Program Testing Be sure that the output of the program conforms with the input. There are three types of errors: Syntax Errors (Compiler Error): occurs when the compiler cannot recognize a statement because it violates the rules of the language. Logical Errors: The program run but provides wrong output. Runtime errors: The program stop running suddenly when asking the OS executing a non accepted statement (divide by zero, etc). Debugging Find, Understand and correct the error (C) 2017 Nouf Aljaffan

35 Conclusion The course objectives The computer programs
CSC 1101 2/7/18 Conclusion The course objectives The computer programs The C programming language Stages in Program Development Process (C) 2017 Nouf Aljaffan

36 Any Questions


Download ppt "Chapter 1 Introduction to Programming"

Similar presentations


Ads by Google