Computer Programming 1 PDF
Document Details
Tags
Summary
This document provides an introduction to computer programming, covering concepts, programming languages, and problem-solving approaches. The material includes lessons, examples, and definitions regarding elements of programming, variables, and data types.
Full Transcript
COMPUTER PROGRAMMING 1 Lesson 1: Programming Concept Elements of Programming Ingredients to all programming matters Computer Programming Programming Paradigm Is the...
COMPUTER PROGRAMMING 1 Lesson 1: Programming Concept Elements of Programming Ingredients to all programming matters Computer Programming Programming Paradigm Is the process of Designing/Building Techniques or style on how you do it. something in a logical way. ○ Automation _______________________________________ ○ Application/Software (Computer & Mobile) Software ○ Operating System Consist of a list of instructions. ○ Games Reason why we can communicate in hardware (Drivers) Programming Language Reasons why we can use applications it is a formal language that will be used like word, calendar, calculator, games, to direct instructions to the computer. etc. (OS) Example: Can contain data ○ Ruby ○ C++ Programmers ○ C# System Programmers ○ Java Application Programmers ○ Kotlin Types of Application Programmers ○ My SQL Database App, Programmers ○ Phyton Web App, Programmers ○ JavaScript Game Developer Why Programming Micro Device Programmers 1. The most in demand work at this time 2. It is Very Rewarding not because of the salary Hardware but the genuine happiness when you create Physical or tangible parts of a computer. something that benefit others Either input device or output device. 3. Well, of course the Salary too. Problem Solving Steps in programming Computers ○ Java Software Planning Created using a collection of codes that Analysis instructs the computer on what it will do Design Programmers Development The People who write program codes Testing and Debugging Hardware Physical components of a computer Elements of Programming system 1) Input The data you type, the click of the Problem Solving mouse Step by step approach to create an 2) Data A place to keep the input effective “Product” COMPUTER PROGRAMMING 1 3) Operation Mathematical, relational and Pseudocode logical operators A Method that allows a programmer to 4) Output Extracted data represent the Algorithm in a more 5) Conditional Execution Helps to manipulate programming related way. the data Pseudocodes are also called false codes 6) Loops Execute a set of instructions until meet because they tend to look like a the specific condition programming language but can still be 7) Subroutine Breaking large program into understood by a person that has little reusable sub-programs understanding in programming. Programming Paradigm Pseudocode naming Convention Styles, Methods, Procedures... On How 1.) Let / Initialize – initialize of variables to Program 2.) Input – indication of a variable to be used in process Lesson 2: Algorithm, Pseudocode and 3.) Output / Print – indication of a value to be Flowchart displayed 4.) IF / ELSE – indication of conditional Programming Algorithm statement Set of Instruction / Rules to be followed 5.) ENDIF – indication of the end of conditional by a Computer Program. Which Should statement contain an Input, Process and an Output. 6.) While – indication of a Loop Statement Depending on the Problem to be solved. 7.) EndWhile – indication of the end of a loop 8.) Begin – indication of a function IPO Model 9.) End – indication of the end of a function Input → Process → Output 10.) Call – indication of a function cal Send Design to laser cutter → Computer works out vector → Laser cuts out Pseudocode: Do’s and Don’ts design Do’s Press call on mobile phone → Phone 1. Proper Naming Convention connect to network → Phone connects 2. Simple and Concise with your friend Don’ts Variables 1. Don’t make it Abstract Math: 2. Don’t make it Generalized A Letter that can Represent any Number Pseudocode Sequential Programming Create Pseudocode for a Program That will A Letter / Word that serve as a display the sum of 2 Numbers inputted by the temporary storage that can represent any user. value. Let numOne = 0, numTwo = 0 and sum = 0 Input numOne and numTwo sum = numOne + numTwo Output sum COMPUTER PROGRAMMING 1 Flowchart Lesson 3: Number System A Method that allows a programmer to represent the Algorithm in a Diagram or Number System an Illustration. It is a particular way on how to Flowcharts represents the sequence of a represent numbers. A number can be programming algorithm by using consisted of a digit or a series of digits. standard graphic symbols that will When you say digit. It is only one represent the input, Process and the symbol that represent a number. The Output. number 143is consist of 3 digits, 1, 4, Flowcharts is a guide in creating and 3 programs. It uses symbols to show the step by step process of how you can Decimal Number System develop a solution to a certain problem. The number system that we use in our Basic Symbols day-to-day life is the decimal number These symbols are the ones often used system. to create a diagram that represents an Decimal number system has base 10 as algorithm that a computer program must it uses 10 digits from 0 to 9. follow. Computer Number System When we type some letters or words, the computer translates them in numbers as computers can understand only numbers. As a computer programmer or an CS/IT professional you should understand the following number system which are frequently used in computer. Conversions 1. Binary to Decimal 2. Decimal to Binary 3. Hexadecimal to Binary 4. Binary to Hexadecimal 5. Hexadecimal to Decimal 6. Decimal to Hexadecimal Computing Binary Number Binary Binary is still the primary language of computers for the following reasons: It is a simple and an elegant design. Binaries 0 and 1 method are quick to detect electrical signals in or off state. COMPUTER PROGRAMMING 1 Positive and Negative poles of magnetic The Programmers developed this media are translated into binary quickly. language so that they can easily understand their programs. Byte The basic unit of information in Third Generation Language computer storage and processing. High - Level Language A byte consist of 8 adjacent binary The high-level language is a program digits (bits), Bit – each of which consist written in English words that even of a 0 and 1 common people can understand. 0 and 1 – bits Types of High-Level Languages 1 byte – equivalent to 8 Procedural Programming bits Object- Oriented Programming Lesson 4: Programming Language Logic Structures Sequence History of Programming Languages “Going to School” 1. Wake up Early 2. Eat Breakfast 3. Brushing teeth 4. Take Shower 5. Put on Uniform 6. Go to School Selection “Going to School” But IF “today” is Friday, wear P.E. Uniform 1. Wake up Early First Generation Language 2. Eat Breakfast Machine Language 3. Brushing Teeth The machine language is written with 4. Take a Shower binary digits, that is 0s and 1s. 5. IF ( today is Friday Put on P.E. Machine Language is the sole Uniform) ELSE ( Put on School programming language which is Uniform) recognized by the computer, though it is 6. Go to School very tedious and the tendency of making Repetition or Looping errors is extremely high. “Going to School” Repeat the entire process in 5 times (Monday – Friday) Second Generation Language 1. Repeat 5 Times Assembly Language a. Wake up Early This programming language uses b. Eat Breakfast mnemonics. Mnemonics are memory c. Brushing Teeth aids which are abbreviated alphabetic d. Take a Shower instructions. e. IF ( today is Friday Put on P.E. Uniform) ELSE COMPUTER PROGRAMMING 1 ( Put on School Lesson 6: User Input and Arithmetic Uniform) Operators f. Go to School End Repeat Built – in Packages Java API has many pre- written classes Lesson 5: Variables and Datatypes to help the programmer manage input database etc. Variables Variables are used to store up temporary Importing Packages data to be used in our program’s import packagename.classname; runtime. import java.util.Scanner; Data type The Type of Date inside our variables. Importing Packages Are types of data to be used in a program import packagename.*; Common Data Types are: import java.util.*; String – Texts Integer – Positive and Negative java.util.Scanner Numbers (no decimal) A class in the java.util Package that Float – Decimal Numbers Data Type helps programmers handle inputs from Character – Single Letter or Symbol the user. Data Type User Input Identifiers String name; It is the Name of the Variable that the Scanner scan = new Scanner(System.in); programmer indicated it is used to Read name = scan.nextLine(); and Write the variables. Rules of Identifiers User Input You cannot use any special characters nextLine(); other than underscore (_). nextInt(); You cannot use Whitespaces. nextShort(); You cannot use numbers alone. nextLong(); You can use numbers but with letters. nextByte(); nextBoolean(); Concatenation nextDouble(); The process of joining Strings together nextFloat(); with the plus operator. You can concatenate Inside a variable or on the Print Statement. COMPUTER PROGRAMMING 1 nextLong(); nextByte(); nextBoolean(); nextDouble(); NextFloat(); Arithmetic Operators int num1 = 7; Arithmetic Operators int num2 = 8; int num1 = 7; int sum = num1 + num2; int num2 = 8; ○ System.out.println(sum); int sum = num1 + num2; System.out.println(sum); Lesson 3: User Input and Arithmetic Operators Built – in Packages Java API has many pre- written classes to help the programmer manage input database etc Importing Packages Import Specific Class ○ import packagename.classname; ○ import java.util.Scanner; Import Whole Package ○ import packagename.*; ○ import java.util.*; java.util.Scanner A class in the java.util Package that helps programmers handle inputs from the user. User Input String name; ○ Scanner scan = new Scanner(System.in); ○ name = scan.nextLine(); nextLine(); nextInt(); nextShort();