Computer Programming I: Understanding Computers, Data, and Software - Chapter 1, Exercises of Computer science

An introduction to computer programming from a beginner's perspective. It covers the basics of computers, data, information, hardware, and software. The document also discusses the concept of programming, including the five-step process and the difference between system and application software. Additionally, it introduces the concept of flowcharts and structured flowcharts.

Typology: Exercises

2020/2021

Uploaded on 02/11/2022

eren-jaeger-12
eren-jaeger-12 🇵🇭

2 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer
Programming I
CHAPTER 1: Programming
Concepts
COMPUTER
- An electronic device that accepts
data from user, processes it,
produces results, displays them to
users, and stores result for future
usage.
DATA
- A collection of unorganized or
unstructured facts and figures
- Does not only provide information
regarding patterns, contexts, etc.
INFORMATION
- A structured data (organized
meaningful and processed data)
- A computer is used to process data
and convert it into information
HARDWARE
- Mechanical device that makes up
computer.
- Consists of interconnected
electronic devices that we can use to
control computer’s operation, input,
and output.
- Collection of several components
working together. Some are
essential, some for advancement.
EXAMPLES: CPU, Keyboard, Mouse,
Hard Disk, Printer, Scanner, External
Hard Disk, Monitor, Speaker
PROGRAM
- A set of instructions that drives
computer to do stipulated tasks
SOFTWARE
- Instructions are programmed in a
computer language, translated into
machine language, and executed by
computer
[ TWO TYPES OF SOFTWARE ]
a) System Software
- operates directly on hardware
devices of computer
- provides platform to run an
application, supports user
functionality
EXAMPLES: Operating Systems
(Windows, Linux, Unix, etc.)
b) Application Software
- designed for benefit of users to
perform one or more tasks.
EXAMPLES: MS Apps (Word), Oracle
PROGRAMMING
- Act of writing instructions that
consist of statements in a form of
specific programming language
[ 5-STEP PROCESS OF
PROGRAMMING ]
1. Define the problem
2. Design the solution or program
3. Code the program
4. Test the program
5. Document the program
[ PROBLEM-DEFINITION STEPS ]
1. Specify program objectives and
identify the users of the program.
2. Specify the output requirements.
3. Specify the input requirements.
4. Specify processing requirements.
5. Study feasibility of implementing
the program.
6. Document the analysis.
[ PROGRAM DESIGNING ]
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Computer Programming I: Understanding Computers, Data, and Software - Chapter 1 and more Exercises Computer science in PDF only on Docsity!

Computer

Programming I

CHAPTER 1: Programming

Concepts

COMPUTER

  • An electronic device that accepts data from user, processes it, produces results, displays them to users, and stores result for future usage. DATA
  • A collection of unorganized or unstructured facts and figures
  • Does not only provide information regarding patterns, contexts, etc. INFORMATION
  • A structured data (organized meaningful and processed data)
  • A computer is used to process data and convert it into information HARDWARE
  • Mechanical device that makes up computer.
    • Consists of interconnected electronic devices that we can use to control computer’s operation, input, and output.
    • Collection of several components working together. Some are essential, some for advancement. EXAMPLES : CPU, Keyboard, Mouse, Hard Disk, Printer, Scanner, External Hard Disk, Monitor, Speaker PROGRAM
    • A set of instructions that drives computer to do stipulated tasks SOFTWARE
    • Instructions are programmed in a computer language, translated into machine language, and executed by computer [ TWO TYPES OF SOFTWARE ] a) System Software
    • operates directly on hardware devices of computer
    • provides platform to run an application, supports user functionality EXAMPLES: Operating Systems (Windows, Linux, Unix, etc.) b) Application Software
      • designed for benefit of users to perform one or more tasks. EXAMPLES : MS Apps (Word), Oracle PROGRAMMING
      • Act of writing instructions that consist of statements in a form of specific programming language [ 5 - STEP PROCESS OF PROGRAMMING ]
      1. Define the problem
      2. Design the solution or program
      3. Code the program
      4. Test the program
      5. Document the program [ PROBLEM-DEFINITION STEPS ]
      6. Specify program objectives and identify the users of the program.
      7. Specify the output requirements.
      8. Specify the input requirements.
      9. Specify processing requirements.
      10. Study feasibility of implementing the program.
      11. Document the analysis. [ PROGRAM DESIGNING ]
  1. Determine the program logic through top-down approach and modularization, using hierarchy charts.
  2. Design details using pseudo-code and/or flowcharts.
  3. Test design with a structural walkthrough. Structural walkthrough consists of reviewing process with other programmers and system analyst and scrutinize (“walkthrough”) the programmer’s work. PROGRAM CODING
  • step which translates logic of the program based on the pseudo-code (algorithm) or flowcharts in high-level programming language
  • use syntax and semantics of specific language NOTE: Coding is a subset of programming. Coding is writing lines of codes, while programming creates executable machine program [ STEPS IN PROGRAM CODING ]
  1. Determine the appropriate programming language to use.
    1. Code the program in the specific programming language decided on. PROGRAM TESTING a) Desk Checking:
    • Verifying the programming and logic of an algorithm before launching b) Debugging
    • Detecting, locating, removing errors in program c) Running Data PROGRAM DOCUMENTING
    • written descriptions of what program is all about and how to use [ STEPS FOR DOCUMENTATION ]
    1. Write user documentation. This is the manual that is prepared to help the user use the programs.
    2. Write operator documentation. This manual gives the computer operator information on what to do when the program flashes an error message.
      1. Write program documentation. The program documentation consists of the testing of the whole programs. This 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 solution to given problem (most difficult)
      • after a method, translate this to the required language (ex. C language) FLOWCHART
      • consists of shapes that contain simple statements called instructions and are connected

ALGORITHM

  • set or series of instruction for carrying a task in English language
  • procedure to produce required output from given input
  • subsequent to flowcharts ALGORITHM DEVELOPMENT
  • similar to steps in flowchart PSEUDO CODE
  • mixture of language and symbols, terms and other feature commonly used one or more high-level languages ALGORITHM STRUCTURE
  • displayed in a structure diagram how one will be performed
  • useful in describing algorithms for more complex problem

Computer

Programming I

CHAPTER 2 : introduction to c

C LANGUAGE

  • A general-purpose programming language featuring economy of expression, modern control flow, and data structures and operations
  • “System programming language”: useful for writing compilers and OS
  • high-level language concentrating problems at hand BRIEF HISTORY
    • Martin Richards (1967) developed Basic Combined Programming Language or BCPL
    • Ken Thompson (1970) developed B for UNIX System
    • Dennis Ritchie (1972) expanded B to C language, added data types - Borland International Corporation (1987) developed a version of C called Turbo C for microcomputers/IBM INTERPRETER
  • reads source code of program and perform instructions one line at a time COMPILER
  • reads entire program and converts to code executed by computer COMPILE TIME
  • occur during compilation RUN TIME
  • occur while program is executing OBJECT CODE 0R BINARY CODE
  • translation of program executed b computer

SOURCE CODE

  • text of program that user can read LIBRARY
  • collection of pre-written [ TYPES OF ERRORS ] a) Syntax Error
  • typographical, incorrect format
  • detected during compiled time b) Logic Error
  • incorrect use of control structures c) Runtime or Semantic Error
  • not able to perform operations while program is running d) Linker Error
  • occurs when executable files are not found nor created TURBO C
  • more than version of C language
  • includes complete environment to create, test, and run programs

[ THREE USES OF VOID ]

  1. To declare explicitly a function as returning no value.
  2. To declare explicitly a function having no parameters.
  3. To create generic pointers. c) Variables
  • are identifiers which can be assigned a value within a program.
  • 32 valid characters (letters, digits, underscore) VARIABLE DECLARATION
  • used to name an object
  • the declaration gives them symbolic name and definition reserves memory for them
  • usually found at the beginning of the statement EXAMPLE : int x, y, z; char a, b ; double s; float ave; char Sname[30]; VARIABLE INITIALIZATION
  • process of assigning, starting values to variables

[ STEPS IN INITIALIZING VARIABLES ]

  1. Assignment statement (=) to assign values to variables of any types EX. int num = 24;
  2. By using function scanf (user input) EX. scanf (“%d”, &num);
  3. By assigning values during declaration EX. double num1 = 124.09; [ HOW TO ASSIGN VALUES TO VARIABLES ]
  4. The variable must be on the left side of the equal sign. Values must be on the right side of the equal sign.
  5. Any expression can be assigned on the variable.
  6. Expressions are not allowed on the left side of the assignment operator. The assignment operator directs C to assign to the variable on the left side the value on the right side.

GLOBAL VARIABLES

  • at the start of program
  • are initialized to zero if no other initializer is specified
  • declared OUTSIDE functions of computer program LOCAL VARIABLES
  • initialized each time the function in which they are declared is entered
  • declared INSIDE function of program d) Constants
  • fixed values that may not be altered by program
  • Literal Constants if Turbo C CHARACTER CONSTANTS
  • enclosed in single quotes INTEGER
  • number without fractional components FLOATING-POINT
  • requires use of decimal point followed by fractional component

STRING or LITERAL STRING

  • consists of phrase enclosed within double quotations, text messages DEFINED DECLARATION (# DEFINE)
  • declares constants throughout the program, found after the header file library EXAMPLE : #include <stdio.h> #define price 500 #define pi 3. MODIFIER
  • alter the meaning of the base type to more precise need of situation ACCESS MODIFIERS
  1. Const
  • variables under this modifier can’t be changed during program execution
  • initial value before start SYNTAX: const <data-type> variable = value; EX.: const float version = 3.20;
  1. Using # define e) Operators
    • symbol that tells the compiler to perform specific mathematical, relational, or logical manipulations ARITHMETIC OPERATORS Symbol Use
      • (Asterisk) Multiplication / (Slash) Division
      • Addition
      • Subtraction -- (Unary Minus) Negation % (Modulus) Gets remainder ++ Increment, add one to value
        • Decrement, subtract one () Parenthesis
    1. Unary Operators
    • requires single operand UNARY PLUS: no change to quantity after UNARY MINUS: causes sign of following quantity to be changed
    1. Binary Operators
    • requires two operands like addition or multiplication
    1. Combined Operators
    • C’s shorthand operation
      1. Increment or Decrement
      • If the operator follows its operand, C uses the operands value before incrementing or decrementing it. Lvalue (left value): an object that has an identifiable location in memory Rvalue (right value): no identifiable location in memory EX. X = 10; Y = ++X; (pre-increment, add agad 1) [ RESULT: X is 11, Y is 11 ] X = 10; Y = X ++; (post-increment, X is still same as Y dahil di nag-add ng 1) [ RESULT: X is 11, Y is 10 ] RELATIONAL OPERATORS
      • relationship values can have with one another, determine relationship of quantity Symbol Indication

        Greater than < Less than = Greater than or equal to <= Less than or equal to == Equal to ! = Not equal to

#include <stdio.h> = library file/a header file which has the necessary information to include the input/output related functions in our program. Example printf, scanf etc. .h = header file %p = use for memory address %d = integer %s = String %f = decimal numbers %c = single char %u = use for NULL / is an unsigned integer/can hold only positive value. %[^\ns] = para pwede may SPACE sa string char = single character char [number of characters] = multiple character pow = power or raised to sqrt = square root ceil = round up floor = round down /n = new line (escape sequence) /t = new tab & = pointer and it is NOT NEEDED FOR STRINGS (%lf) = use for scanf for double or decimal numbers (4 decimal places) / Note: walang space dapat ("%lf") (%f) = use for scanf and printf for double or decimal numbers ( decimal places) (%c)= use for scanf and print single character / Note : kelangan walang space ("%c") (%.1f) = field width / reduce decimal point into 1 fgets (variable) = store string of characters / verify how many characters we input /store line of text scanf = need value of characters [20] stdin = Standard input /* */ =Comments const = constant di nababago return = breaks out the function / return value back to the caller && = Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. (A && B) is false. || = Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true. (A || B) is true. ! = Called Logical NOT Operator / NEGATION OPERATOR kung ano yung mali yun yung piniprint kung ano yung tama yun yung hindi ipprint (baliktad/opposite). It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false. if(!(A && B)) is true. (3 != 2) is true else = di na nag check ng condition diretso na agad : if (a > b) printf(a) else printf(b) else if = nag ccheck ng condition : if (a > b) printf(a) else if (b >a ) printf(b) for loop = (initialization; condition;increment & decrement || upadate statement);

= decrement (j--) (--j) < = invrement (j++) (++j) index = h e l l oworld 0123 456789 ASCII table

+= (sum is equals to variable) (sum += c; ) switch statements = mas madaling basahin / allows us to execute one code block break = end of block case '+': default = parang else case = colon lang (:) printf("%.1lf + %.1lf = %.1lf",n1, n2, n1+n2); break; array = container of variables struct = pinagsasama sama yung mga data types kelangan may semi colon sa dulo / struct variable{ }; strcpy = The strcpy() function copies the string pointed by source (including the null character) to the destination./kinokopya yung isang data type na walang laman .EX KOKOPYAHIN NG STR2 YUNG LAMAN NG STR int main() { char str1[20] = "C programming"; char str2[20] = " "; puts() = command na nag pprint ng data na galing sa declaration. Ex. char Mystr[] = "The puts() functions"; puts(Mystr); boolean = True or False //case sensitive //SMALL LETTERS ONLY / 0 = false 1 = true '\0' = is referred to as NULL character or NULL terminator It is the character equivalent of integer 0(zero) as it refers to nothing // example sa words 0 nagsisimula yung pag bilang ng bawat letters. pointer (%p) =another type of data for memory address / print hexadecimal number voin main() - function // = comments in single line /* */ = comments as a group 15==15?100:200 = pag true ( or kaliwa) pag false (200 or kanan) = Ternary getch(); = hanggat walang na iinput user di papasok sa susunod na statement compound sentence = may curly braces {} single sentence = walang curly