Computer Programming Fundamentals PDF
Document Details
Uploaded by Deleted User
Tags
Related
Summary
This document provides an introductory overview of computer programming concepts. It covers topics like data representation, variables, algorithms, and different programming paradigms. The document also explores the differences in the approach to computer programming algorithms and computer coding.
Full Transcript
HW 1) What do computers do? - What are the main components of any computer? - - - [Data vs Information] Information = data + metadata - - Every data is represented in binary Computers can only process binary [Text in binary] Assign a decimal to each letter symbol - [...
HW 1) What do computers do? - What are the main components of any computer? - - - [Data vs Information] Information = data + metadata - - Every data is represented in binary Computers can only process binary [Text in binary] Assign a decimal to each letter symbol - [Audio in binary] - [Images in binary] - - [Video in binary] - What is computer program? - - [Computer Algorithm] - - Represented by 1) pseudocode 2) flowchart 1)Pseudocode: - 2\) Flowchart: - - - - - - Computer code vs computer algorithm Difference: +-----------------------------------+-----------------------------------+ | Computer code | Computer algorithm | +===================================+===================================+ | written in computer **programming | Written in **human friendly | | language** | language** | | | | | eg) python, c | eg) pseudocode, flowcharts | +-----------------------------------+-----------------------------------+ | Actually **writing** code that | **Thinking** how to complete the | | completes the task | task | | | | | | Happen before, think **before** | | | writing computer code | +-----------------------------------+-----------------------------------+ | Represent a computer algorithm | | +-----------------------------------+-----------------------------------+ Similarity: - - Computational thinking - (thinking like a computer) [4 steps of computation thinking:] 1\. Decomposition - - - 2.Pattern Recognition - - - 3\. Abstraction - - - 4\. Algorithm Design - - [Source code vs Machine code] **Source code** \- computer program written in programming language (eg. python, c **Machine code** \- computer program written in binary \- easily make mistakes, because less friendly Conversion from source code to machine code = Code Translation 2 type of code translation 1. - 2. - Examples: **[Scratch]** HW 9 \~ 11)Variables Definition- an unknown symbol that represents other data Function- for **later use**, **temporary storage** for data → no need to write same value multiple times; **convenient** Switch costume vs Next costume - - - **Start sound vs Play sound** Play sound - play sound until it finishes, rest of the code can not run while it is playing → for background music that plays forever - Start sound - start sound and rest of the code runs while it is still playing → for short sound effects Scrolling background: - - - - - **[C language]** What is IDE? **Integrated Development Environment** - software that can write and run code - - - Basic element of programming: - - - - - 1\. Data \- Computers X know meaning of binary sequence → X know data type of the data they process **-** Declaring a variable = creating variable \- structure: Data type variable identifier = data; \- 2 ways to represent data 1. 2. - - - \- variable identifier → to use a variable for 1) assign data to a variable 2) access data(reach the data from the cell) Formatted string parameter - 어떤 data type으로 print 할지, display in certain format \- printf("%d", a); Float vs Int 3 and 3.0 is different 3 = integer, 3.0 = flating point number - - **Pointer** - a variable that store memory address of other variables - - **Single characters vs String** character - consist of only ONE character - - String - consists of 0 or 1 or multiple characters - - - **Int vs Char** Similarity - - - - Difference - - - Formatted string always contain a formatted string parameter eg) "I have %d brothers", 2 Regular string X need formatted string parameter eg) "I have 2 brothers" **Escape Sequence** Definition: a character or series of characters that help users to do a special action, because it has a special meaning inside a string - **Char Array vs char pointer** Char array - collection of individual characters - Char pointer - string, multiple characters - - Do the same thing but use different data types **Declaration vs Initialization** Declaration - declaring the variable identifier, data type, and length of array inside \[\] Data type identifier \[size\] Initialization - assigning the data to a variable for the first time → no size in \[\], after \[\] have = {contents} Data type identifier \[\] = {contents} \- by writing contents, computer can infer the length of array **Branching** - used to compare data - eg) \>, \=, \ - - - **Functions** 1. 2. **Return Statement** int main (void){ return 0; } Return type - data type in front of function Return value - Return statement - word *return* + return value - - Data type of return type and return value is same