























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to computer programming, focusing on the concept of functions and procedural programming. It covers the basics of programming, the role of functions, and the process of developing a simple program using C language. The document also explains the use of global and local variables, selection constructs, and iteration statements. Students will learn how to write and declare functions, as well as the difference between standard library functions and user-defined functions.
Typology: Assignments
1 / 31
This page cannot be seen from the preview
Don't miss anything!
























Student’s signature (^) khoi
Summative Feedback: Resubmission Feedback:
Chapter 2: PRINCIPLES OF PROCEDURAL PROGRAMMING
b) Computer Program Computer programming is way make computer can understand the things humans want to do. It is like a guide for computer. Guide can known as code, and computer programmers write code to solve problem or perform a specific task. Figure 1.3- 3 : Computer program c) What is coding and how can computer work? What is the coding? Code is types of coding languages used by programmer to get a computer to behave anything you want it make. If fill of full line of code, it called a script. Program develop process Step 1: Problem Definition Step 2: Program Design Step 3: Coding Step 4: Debugging Step 5: Testing Step 6: Documentation Step7: Maintenance
Procedural Programming can say the first that new developer will have to learn. Basically, the procedural code is the one in directly instruction a device finish a task in logical step.
Content: This programming will print one line to say “Hello world” on the screen Process: We will use the “printf” command in C language to call the computer screen to print “Hello World” Figure 1.3- 5 : Flowchart of ”Hello world” Figure 1.3- 6 : Code simple program Figure 1.3- 7 : Result of simple program
Defenition of variable : datatype variable ; Local variable: it was laid inside a function or block. Specially, it is declared override the same variable name in the larger scope and just used with same name but different function. Global variables: global variables meanings visible and outside any function and they use it on any function in the program. Figure 1.3- 8 : Global and variables Global variables are declared outside any function, and they can be accessed (used) on any function in the program. For example, variable a in line 4 is a global variable, and then it can be accessed by all the function in the program Local variables are declared inside a function, and can be used only inside that function. It is possible to have local variables with the same name in different functions. For example, b in line 9 is a local variable and then it can be accessed only inside the function my_test(). Even the name is the same, they are not the same. It's like two people with the same name. Even the name is the same, the persons are not.
Figure 1.3- 11 : If statement Figure 1.3- 12 : code if statement Explanation: See if check my target my subject just equal 5, if it is, the subject is pass or not, the subject is fail c) Switch case statements Definition: The switch case statements is used when we have multiple options and we need to perform a different task for each option.
Figure 1.3- 13 : Switch case statement Example: it’s very useful when you out of the switch body. Whenever “break” statement is encountered in the switch body, the control comes out of the switch case statement. Figure 1.3- 14 : Code switch-case
Figure 1 .3- 17 : While loop statement Do While loop: Definition: The do while loop is similar while loop, but the condition is checked after the loop body is execute. This ensure that the loop is run at least once Example: print a table of number 2 using do while loop Figure 1.3- 18 : Do while loop statement
Definition: A function is a block of statements that performs a specific task. Suppose you are building an application in C language and in one of your program, you need to perform a same task more than once Function declaration syntax: return_type function_name( parameter list ); Figure 1.3- 19 : Function declaration syntax Type of Functions: 2 types Standard library functions User-defined functions Figure 1.3- 20 : Library function and user-defined function
A value parameter is a formal parameter identification a memory location that is set aside while the procedure is dynamic, and into which the contents of an actual parameter will be copied at the time the procedure is called
There are different ways in which parameter data can be passed into and out of methods and functions. Important of method Parameter passing
a) In/Out variables Input variables struct student(): to store the object name student with the information as id and grades struct StudentDetail { o Int id; o float grade; }typedef StudentDetail; Int id: IDs of student Float grade: Grade of student StudentDetail student[100]: to store information of list of student Output variables List information of all student Information student with finding by ID Student information who has the highest grade Student information who has the lowest grade b) Main Variables Int for choice: get input user choice from menu Int for n: to store count of list friend Int for index: input index search information Int for id: input id search information Figure 1.3- 22 : Main variables in function
c) Switch case/selection variables Figure 1.3- 23 : Choice menu function Use the switch case to declare the integer value to get the user’s choice from the keyboard and process. A menu must use a switch case because there are too many different options for menu.
Function input ID: Local variable: int id Figure 1.3- 24 : input ID Function Function inputgrade: Local variable: float grade Figure 1.3- 25 : Input local variable function