Computer Programming Fundamentals PDF

Document Details

AppealingTaylor2736

Uploaded by AppealingTaylor2736

Polytechnic University of the Philippines

Tags

computer programming software programming languages computer science

Summary

This document provides a general overview of computer programming concepts. It covers the basics of hardware and software, different types of software, and programming steps. It also explains various programming methodologies and concepts.

Full Transcript

COMPUTER PROGRAMMING **COMPUTER --** an electronic device that accepts data from the user **DATA --** unstructured facts and figures; no information for patterns, context, etc. **INFORMATION --** structured data **HARDWARE AND SOFTWARE** **HARDWARE --** mechanical devices that makes up the **CO...

COMPUTER PROGRAMMING **COMPUTER --** an electronic device that accepts data from the user **DATA --** unstructured facts and figures; no information for patterns, context, etc. **INFORMATION --** structured data **HARDWARE AND SOFTWARE** **HARDWARE --** mechanical devices that makes up the **COMPUTER.** - **Interconnected electronic devices** that will control the computer's **information, input, and output** **COMPUTER HARDWARE --** components working together **SOFTWARE --** Set of instructions; is called a **program** **2 Types of software** - **System software** - **Application software** **SYSTEM SOFTWARE** - Operates directly on hardware devices of computer - Platform to run applications - Linux, Unix, Windows, etc. **APPLICATION SOFTWARE** - To perform one or more task - Word, Excel, PowerPoint, Oracle **Program or Software** - list of instructions that the computer must follow to be able to process data into information. - To solve a problem, we need to use our **mind power or logic** to develop the detailed instructions. **Five steps of programming:** - Define the problem - Design the solution/program - Code the program - Test the program - Document the program **Top-down approach -** overall task is first fixed in terms of generalized sub-tasks; more defined. **Modularization -** long programs are split into smaller programs **Pseudo-code -** plain language description of the steps in an algorithm or another system. **Program coding -** step which translates the logic of the program based on the pseudo-code (algorithm) or flowcharts into a high-level programming language **Syntax --** grammatical structure **Semantics --** meaning and interpretation **Program Testing -** desk checking, debugging and running real data to make sure that the program works **Desk checking --** reading through the program or correcting it manually **Debugging --** detecting, locating, and removing error **Syntax errors --** typographical error or incorrect format **Logical errors --** incorrect use of control structures (mistake in a program's source code; type of runtime error that simply produce the wrong output or may cause the program to crash while running.) **Documenting the program -** written descriptions of what the program is all about and how to use it. - **User documentation -** This is the manual that is prepared to help the user use the program. - **Operator documentation -** This manual gives the computer operator information on what to do when the **program flashes an error message** - **Program documentation -** The documentation helps train the new programmers to maintain existing system. Maintenance here means keeping the programs in working conditions, error free and up to date. **PROGRAM LOGIC FORMULATION** - step-by-step development of a solution to a given problem - most difficult part of solving a problem with a computer **FLOWCHART** - boxes with different shapes that contain simple statements or sentence commonly called instructions and connected by lines. A diagram of a flowchart Description automatically generated![A diagram of a process Description automatically generated](media/image2.png) **TYPES OF FLOWCHARTS** - System Flowchart (process chart) - Indicates a flowchart for a **targeted system** as a whole - Program Flowchart - Used to describe processing procedures based on a **detailed analysis**. **FLOWCHART DEVELOPMENT** - steps that comprise a flowchart must be organize in an orderly, understandable and clear manner. **STRUCTURED FLOWCHART** - orderly, understandable, and clear solution. - using three most basic methods of control 1. **SEQUENTIAL STRUCTURE** - Strictly sequential manner - Executed exactly once - Simplest method of control - Easy to develop and understand 2. **SELECTION STRUCTURE** - One of the several alternative actions is selected and executed - Use of decision-making - Use a decision block or diamond block - Alt action will be represented using processing block 3. **REPETITION STRUCTURE** - One or more steps is performed repeatedly **ALGORITHM** - Set or series of instructions - Single thought - English language - Aka pseudo code **ALGORITHM DEVELOPMENT** - Similar with flowchart - organized in orderly, understandable, and clear manner **PSEUDOCODE** - A mixture of language and symbols, terms and other feature commonly used one or more high-level languages. - **HIGH-LEVEL LANGUAGES** - Programs used by the computer - **Symbolic names(identifiers) -** represent quantities being processed by the algorithm. - **Read or enter --** input operation - **Display, print, and write --** output operation **UNIT 2: BASIC PROGRAM STRUCTURE** **Basic Combined Programming Language (BCPL) --** 1967 by **Martin Richards** **B --** 1970 by Ken Thompson; first UNIX system on the DEC PDP-7. BCPL and B are type "less" languages **C --** 1972 by Dennis Ritchie; designed for and implemented on the UNIX operating system on the DEC PDP-II. C has data types while B does not. **Turbo C --** 1987 by Borland International Corporation; run on various microcomputer systems. **Source code --** Text that users can read **Interpreter --** Reads source code **Compiler --** source code to object code **Object code --** executed by the computer **Compile time --** events occur while compiling **Run time -** events occur while program is executing **Syntax error --** detected during run time **Logical error --** detected when output is incorrect **Runtime error -** Occur during run time like when program asks for int or number but user inputs string or words. **Library --** Collection of pre-written codes **Turbo C --** Version of C; Complete environment to create, test, and run programs. **COMPONENTS OF TURBO C** 1. **Editor** - Use to create program source code 2. **Extended C language** - significantly extended from the "base bone" language of Ritchie's specifications. Makes the Turbo C compatible with the **new proposed and ANSI Standard**. 3. **Compiler** - Convert source code to binary or machine code 4. **Debugger** - Testing programs and locating errors 5. **Run time environment** - Capability for running programs within the Turbo C system 6. **User Interface (UI)** 1. **IDENTIFIERS -- LANGUAGE ELEMENT OF C** - Names used to reference variables, functions, labels, and other user-defined objects. - Sequence of letters, numbers, or underscore. 1. **RULES IN NAMING IDENTIFIERS** a. Can vary from one to several characters. First character must be a letter or an underscore with subsequent characters being letters, numbers, or underscore. Must not have space or hyphen. b. Must consist of alphabetic characters, digits, and underscores only. c. First 63 characters are significant. Identifiers are case sensitive. d. Cannot be the same as Turbo C keyword and should not have the same name as a function. 2. **SIMPLE DATA TYPES -- LANGUAGE ELEMENT OF C INT** - Whole number with optional + or -, followed by sequence of digits. - Cannot contain commas. - Used for controlling loops and conditional statements. - Byte size: 4, Minimum Value: -2147483648, Minimum Value: +2147483647. **2.1.1. SHORT INT** \- Byte size: 2, Minimum value: -32768, Minimum Value: +32767. **2.1.2. LONG INT** **-** Byte size: 4, Minimum Value: -2147483648, Minimum Value: +2147483647 **2.1.3. UNSIGNED INT** \- Byte size: 16, Minimum Value: 0, Minimum Value: 65536. **2.2. FLOAT** **2.3. DOUBLE** \- Special float that can store more significant digits. \- Occupies 8 bytes \- Can include exponent ranging from 1.7 E -308 to 1.7 E +308 **2.4. CHAR** \- Single letter, digit, punction mark, or control symbols enclosed within single quotation mark. \- Can be assigned with an integer value between -128 and +127. **2.4.1 UNSIGNED CHAR** \- Can be assigned with an integer value from 0 to 255. **2.5. VOID** \- Used to declare explicitly a function as returning no value. \- Used to declare a function having no parameters \- Used to create generic pointers **3. VARIABLES -- LANGUAGE ELEMENT OF C** \- Are identifiers which can be assigned a value within a program \- Has 32 valid characters namely: letters, digits, and underscore. **3.1. VARIABLE DECLARATION** **3.2. VARIABLES INITIALIZATION** \- Process of assigning values to variables **3.2.1. INITIALIZATION BY ASSIGNMENT** \- By assignment statement with equal sign. **3.2.2. INITIALIZATION USING SCANF** \- Getting user input **3.2.3. INITIALIZATION DURING DECLARATION** \- Adding value when the variable is declared **3.3. GLOBAL AND LOCAL VARIABLES** **3.3.1. GLOBAL VARIABLES** \- Initialized at the start of the program, initialized to zero if no other initializer is specified. **3.3.2 LOCAL VARIABLES** \- Initialized each time the function in which they are declared is entered. **4. CONSTANTS -- LANGUAGE ELEMENT OF C** \- Refer to fixed values that may not be altered by the program. **4.1. CHARACTER CONSTANT** \- Constant character enclosed in single in single quotes. **4.2. INTEGER CONSTANT** \- Constant int **4.3. FLOATING POINT CONSTANT** \- Constant number with decimal **4.4. STRING CONSTANT** \- Constant string **4.5. DECLARED CONSTANT** \- This declaration is introduced by the word \#define follow by a constant name and its value. **5. MODIFIERS** **5.1 ACCESS MODIFIERS** **5.1.1 CONST** \- Variables declared under this modifier cannot be changed during the execution of the program. **5.1.2 USING \#DEFINE** \- Used at the beginning of the program, also used for declaring constants **5.2. TYPE MODIFIERS** \- Used to alter meaning of the base type to more precisely fit the needs of various situation. **ASSIGNMENT STATEMENT** \- Process of assigning values to variables \- Equal sign is the assignment operator. **OPERATORS** \- Symbol that tells the compiler specific mathematical, relational, or logical manipulations. **THE CONDITIONAL STATEMENTS/CONSTRUCTS** **SINGLE SELECTION CONSTRUCTS** The **if statements** - is relational, logical, equality expression of an expression from any domain is permissible (allowed). - The easiest way to do conditions - If expression is nonzero, then statement1 is executed and statement2 is skipped; if expression is zero, then statement1 is skipped and statement2 is executed. In both cases control then passes to the next statement. - An if-else statement can be used as the statement part of another if statement, this is what you call **nested if** **MULTIPLE SELECTION CONSTRUCTS** The **switch statements** - a multiway conditional statement generalizing the if-else statements - The switch expression may be any expression which evaluates to an int, conditional, char or double value. The case list consists of constants whose type matches that of the switch expression. - **Break keyword -** means at that point, execution should jump to the end of the **switch** statement. **system("cls")** = clear screen function **UNCONDITIONAL TRANSFER STATEMENTS** The **break** and **continue** statements 1. The **break** statement - To terminate a case. - To force termination of a loop, bypassing inside the loop, the loops is immediately terminated. 2. The **continue** statement - causes the current iteration of the loop to stop and causes the next iteration of the loop to begin immediately. The **continue** statement may only occur inside **for**, **while**, and **do **loops.

Use Quizgecko on...
Browser
Browser