CPRO1 Introduction to Computer Programming PDF
Document Details
Uploaded by SpellboundNephrite2490
Colegio de Sta. Teresa de Avila
2024
Ms. Image Marie Y. Maiquez
Tags
Related
- CIT 0513 Computer & Programming - Chapter 1 PDF
- CP1 - Introduction To Computer Programming PDF
- Introduction to Computers and Programming PDF
- Ch.01-Introduction to Computers and Programming (1) PDF
- Introduction to Programming with Python PDF
- Lecture 1: Introduction to C++ Programming and Computer Science PDF
Summary
These notes cover Introduction to Computer Programming, including topics such as logic formulation, algorithms, pseudocode, and flowcharts. The document also includes practical examples and activities related to these concepts. It's a teaching material for a course in computer programming.
Full Transcript
CPRO1 INTRODUCTION TO COMPUTER PROGRAMMING LOGIC FORMULATION Ms. Image Marie Y. Maiquez August 2024 CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING...
CPRO1 INTRODUCTION TO COMPUTER PROGRAMMING LOGIC FORMULATION Ms. Image Marie Y. Maiquez August 2024 CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING WHAT IS AN ALGORITHM? A step-by-step problem-solving procedure, especially an established, recursive computational procedure for solving a problem in a finite number of steps. A finite sequence of steps for solving a logical or mathematical problem. A specific set of well-defined, simple mathematical and logical procedures that can be followed to solve a problem in a finite number of steps CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING CHARACTERISTICS OF AN ALGORITHM Specify each step or instruction exactly. There must be no ambiguity. The instructions must be clear. There must be a finite number of steps. The algorithm must terminate. There must be a stopping point. There must be an output. The algorithm must produce the correct result. CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING PSEUDOCODE In the past decade, the algorithms have been defined with the help of pseudocode as they can be interpreted by programmers, regardless of their programming background or knowledge. Pseudocode is the false code or representation of a code that even a layperson having school-level programming knowledge can understand. It cannot be executed on a real computer, but it models and resembles real programming code, and is written at roughly the same level of detail CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING ADVANTAGES OF PSEUDOCODE Clarity: designed to be easily understood by both technical and non-technical individuals. Validation and testing: Before writing actual code, pseudocode can be used to validate the proposed logic and algorithm. It allows for a preliminary assessment of the approach to ensure it will meet the desired objectives. Problem-solving: helps developers and designers think through the problem and its solution systematically. CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING ADVANTAGES OF PSEUDOCODE Easy to modify and iterate: It can be quickly revised and refined without the constraints of a specific programming language. Educational tool: Pseudocode is often used in educational settings to teach programming concepts and problem-solving skills. It provides a bridge between natural language and programming languages, helping students develop algorithmic thinking. CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING PSEUDOCODE 1. BEGIN 2. CREATE Scanner object user_input 3. CREATE variable num1, num2 and sum 4. PRINT “Enter first number” and INPUT num1 5. PRINT “Enter second number” and INPUT num2 6. COMPUTE sum = num1 + num2 7. PRINT “The sum of " + num1 + " and " + num2 + " is “ + sum 8. CLOSE user_input 9. END CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING PSEUDOCODE CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING FLOWCHART A chart that contains symbols referring to computer operations, describing how the program performs These symbols are interconnected by lines and arrows to represent the flow of data or control from one point to another. CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING FLOWCHART Flow Lines Indicated by straight lines with arrows to show the direction of data flow The arrowhead is sometimes not shown when the direction of flow is clear Used to connect blocks by exiting from one and entering another CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING FLOWCHART Terminal Block ovals or rounded rectangles are used to indicate the start and the end of a module or program an oval is labeled with the name of the module at the start Start a start has no flow lines entering it and only one exiting it; an end or exit has one flow line entering it but none exiting it End CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING FLOWCHART Initialization / Declaration Block used for declaring / initializing variables needed to solve a certain process. binding of an identifier to the information that relates to it stating a variable name to be used X=1 Y=2 CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING FLOWCHART Process Block The rectangle indicates a processing block, for such things as calculations, opening and closing files, and so forth A processing block has one entrance and one exit A = 18 B=A-2 CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING FLOWCHART Input/ Output Block the parallelogram indicates input to and output operations an I/O block has one entrance and only one exit Get or Display [variable name] CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING FLOWCHART Decision Block T F CONDITION ACTION WHEN ACTION WHEN TRUE FALSE CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING FLOWCHART FLOWCHART EXAMPLE Create a flowchart that displays the user’s name, birthday, age, gender, and LAST SCHOOL ATTENDED. Your flowchart should display the variables with the following format: Name: Age: BDay: Gender: LAST SCHOOL ATTENDED: CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING FLOWCHART Decision Block the diamond indicates a decision it has one entrance and exactly two exits from the block one exit is the action when the resultant is TRUE and the other exit is the action when resultant is FALSE CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING CONDITIONAL STATEMENTS Conditions are statements that result to a Boolean value. The Boolean value can only be assigned either a TRUE or FALSE value, which is represented by 0 or 1. Conditions are classified into two different categories: Relational Operators Logical Operators CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING CONDITIONAL STATEMENTS Relational Operators compare two values and returns a Boolean value depending on whether the test condition is true or false. Create a flowchart that would print the name of the supervisor under a certain department number. CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING FLOWCHART INDIVIDUAL ACTIVITY (Yellow pad paper) CREATE A FLOWCHART THAT WILL BE ABLE TO ACCEPT AN INPUT NUMBER. DISPLAY "SCHOOL" IF THE INPUT NUMBER IS 1. DISPLAY "HOUSE" IF THE INPUT NUMBER IS 2. ELSE, DISPLAY "NONE". CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING FLOWCHART INDIVIDUAL ACTIVITY (Yellow pad paper) Create a flowchart that will compute for the Average score of a student based on three quizzes. The quiz scores are entered by the user. The scores are integers and may range from 0 to 100, inclusive. However, the Average may have a value having decimal places. CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING LOOPING CONSTRUCTS A loop is a sequence of program instructions that execute repeatedly until a specified condition is met. REPETITION STRUCTURE This kind of structure, often known as a loop or iteration, involves the repetition of one or more instructions until a specific condition is met. CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING LOOPING CONSTRUCTS LOOPING EXAMPLE Create a flowchart that will display the following result: Output: 5 4 3 2 1 Done CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING LOOPING CONSTRUCTS LOOPING EXAMPLE Create a flowchart that will display the following result: Output: 5 4 3 2 1 Done CPRO1: INTRODUCTION TO COMPUTER PROGRAMMING LOOPING CONSTRUCTS ACTIVITY #1 Create a flowchart that will print the sum of all odd numbers from 1 - 100. ACTIVITY #2 Create a flowchart that prints your name five times.