C Programming,Klase Notes
No comments
Module 1. Lesson 3: Structure of C Program
Lesson 2. Read and Learn
Algorithm and Flowcharting
The Algorithm
-is a limited number of instructions that outline the steps to be taken in order to address a particular problem or set of related problems.
Criteria for Algorithm
Input – there is a data that needs to be processed.
Output – there is a report to be printed.
Definiteness – instructions must be clear and free from ambiguous.
Finiteness - If we follow an algorithm's steps step by step, in every scenario, the algorithm must end after a set number of steps.
Effectiveness - Each stage must be simple enough that it could theoretically be completed by a person using only paper and a pencil. Furthermore, every step must be both realistic and certain.
The Pseudocode
Is an outline of the logic of the program you will write. It is like doing a summary of the program before it is written. This expresses the logic of what you want the program to do.
The Flowchart
The "use of symbols and phrases to designate the logic of how a problem is solved" (SCHN95).
"A common method for defining the logical steps of flow within a program by using a series of symbols to identify the Input, Process, and Outputs(IPO's) function within a program" (TRA196).
A flowchart is a two-dimensional depiction of an algorithm that uses preset graphic symbols to show the various operations and the direction of control. (SWAZ89).
"A diagram showing the order in which a series of actions or procedures should be carried out. It serves as the program's blueprint. (LAPU86).
BASIC SYMBOLS USED IN FLOWCHARTING
Payroll System: A simple payroll system that compute for the total salary of an employee. There will be four different modules showing the algorithms, flowcharts and pseudocode that shows the order of processing a payroll.
Control Module: to control the processing of the solution.
Read Module: to enter the data needed in the solution. Two types of modules here for the salaried and hourly employee.
Calculation Module: To process the data for each employee.
Print Module: To print the processed information.
Figure 1.0 The algorithms, flowcharts and pseudocodes for a simple Payroll System.
Logic Structures
Sequence – Processes are carried out independently of one another in a clear way.
Examples:
Create a flowchart that can accept and display a number. Make the corresponding algorithms and pseudocode.
Draw a flowchart that computes and shows the sum and product of two numbers. Write its equivalent algorithms and pseudo code.
Create a flowchart that will convert an inputted number in Fahrenheit to its equivalent measure in Celsius. Formula: C = (5/9) x (F-32)
Selection (IF-Then- Else) – There is a choice between two options.
Examples:
Create a flowchart that accept values for A and B. Compare the two values inputted and print which is higher with qualifier “Higher” on the printed page. Write the equivalent algorithm and pseudocode.
Create a flowchart that will input a grade of student and determine whether the grade is passed or failed. Print the name, grade, remarks of student. Write its equivalent algorithm and pseudocode.
ABC Consultancy plans to give a year-end bonus to each of its employee. Draw a flowchart which will compute the bonus for every employee. Employee’s salary over 2,000 will get 1,500 bonus and less than 2,000 will get 50% bonus. Print the name and the corresponding bonus for each employee. Write each equivalent algorithms and pseudocode.
Construct a flowchart that will accept the evaluation grade of student and determine its equivalent remarks. Print the name of the student and the remarks obtained. Remarks are based on the following criteria: Write its equivalent algorithms and pseudocode.
1.0 – 3.0 Passed
3.01 – 3.5 Conditional
3.51 – 4.0 Failed
Above 4.0 Dropped
Repetition Structure (Iteration Statements)
Do – While
The repetitive execution of an operation or routing when the condition is true is made possible by this structure. Before running any process statement, the condition is assessed. Control flows out of the structure if the condition is false, otherwise the process is carried out.
Examples:
Construct a flowchart that will count from 1 to 10 and print each number counted using the do-while –repetition structure. Write its equivalent algorithm.
Quiz #5
Identify the following terms.
Algorithm
Flowchart
Pseudocode
Program
Give what is asked.
Criteria for algorithm:
Six Steps in Problem Solving
Activity 5
Create a flowchart that will accept three numbers and display the highest and lowest numbers inputted.
Draw a flowchart that will determine the voter is qualified to vote or not. Age must be eighteen (18) and above.
Create a flowchart that convert and display an inputted number from hours to its equivalent minutes. 1 hour = 60 minutes.
Draw a flowchart that will determine if the user is an authorized user of the system. Password is pass.
Create a flowchart that will compute and display the sum of 3 inputted numbers.
Construct a flowchart that will accept 10 numbers and display the positive and negative numbers inputted.
Create a flowchart that will swap the values of two inputted numbers as A and B respectively.
Module 2 References
Workbook in C programming : computer programming 1 / Paulion H. Gatpandan and Azenith M. Rollan.
Kernighan, Brian W. and Ritchie, Dennis M. The C Programming Language 2nd Edition
Schildt, Herbert. Turbo C/C++ The Complete Reference 2nd Edition
Sellapan, P. C++ Through Examples Includes Object-Oriented Programming
Uckan, Yuksel. Program Solving Using C
http://www.cprogramming.com
http://www.cplusplus.com
http://www.cplusplus.com/doc/tutorial
http://www.stroustrup.com
http://www.research.att.com/~bs/homepage.html
http://halls-of-vahalla.org/
http://creativecommons.org/
http://www.tutorialspoint.com
0 comments:
Post a Comment
If possible, leave a positive comment. No hate speech or elicit comments. Thank you.