CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1
Chapter 1 Intro to Programming and Program Design Why Program? Computer Systems : Hardware and Software Programs and Programming Languages What is a Program Made of? Input, Processing and Output The Programming Process Procedural and Object-Oriented Programming
Why Program? Computers perform a wide variety of tasks. Computer programmers provide the software for computers. Software transforms a general purpose computer into a specialized tool. Concept - Computers can do many different jobs because they are programmable.
What is Programming? Computers are designed to execute a set of instructions. Programming is the act of creating a set of instructions for a computer to execute. A set of instructions that performs a specific task is called an algorithm. Concept - A program is a set of instructions that a computer follows in order to perform a task.
Concept – Make a general purpose machine perform a specific task. What a programmer does A programmer creates the following things: The logical flow of the instructions The mathematical procedures The appearance of the screens The way information is presented to the user The program's user friendliness Manuals and other forms of written documentation Concept – Make a general purpose machine perform a specific task.
Computer Systems : Hardware and Software Central Processing Unit Main Memory Secondary Storage Input Devices Output Devices Software : loaded from a secondary storage device into main memory Computer CPU Input Device Output Device Main Memory Secondary Storage
Central Processing Unit The CPU consists of two parts Control Unit Performs three functions Fetch Decode Execute Arithmetic & Logic Unit Performs math operations Add Shift And Or Concept - The CPU is the heart of the computer.
Main Memory Referred to as: Holds the program during execution Random Access Memory (RAM) Static or dynamic Volatile Read Only Memory (ROM) Non-volatile Holds the program during execution Divided into equal sections called cells Each cell has a unique address
Secondary Storage Used to store programs and data for long periods of time: Hard Drives Floppy Zip Drives Categorized by speed and capacity Digital Tape CD ROMS Flash Memory Cards
Input Devices Provide data to the CPU to be processed: Keyboards Touch sensitive screens Secondary storage devices Provide information in a variety of formats: Some conform to standards. Some are application unique. Microphones Cameras Scanners
Output Devices Displays or stores data for the user: Monitors Printers Speakers Consider the complexity of multimedia output. Disk Drives Modems Servers
Concept – Software connects the user to the machine The instructions that tell the computer and all of its devices what to do. When and what data to get What and how to manipulate the data When and how to provide it to the user Concept – Software connects the user to the machine
Programming Languages Computers use machine language consisting of numbers only. Humans have difficulty communicating purely in numbers. A programming language provides a way for humans to communicate with a computer Concept - A program language is a special language used to write computer instructions.
Some Popular Programming Languages BASIC Beginners All-purpose Symbolic Instruction Code. A general programming language originally designed to be simple enough for beginners to learn. FORTRAN Formula Translator. A language designed for programming complex mathematical algorithms. COBOL Common Business-Oriented Language. A language designed for business applications. Pascal A structured, general purpose language designed primarily for teaching programming. C A structured, general purpose language developed at Bell Labs. C offers both high-level and low-level features. C++ Based on the C language, C++ offers object-oriented features not found in C. Also invented at Bell Laboratories. Java An object-oriented language invented at Sun Microsystems. Java may be used to develop programs that run over the Internet, in a web browser.
The Importance of C++ C++ is based on the C programming language. C++ is a midlevel language containing both high level and low level instructions. C++ is portable meaning that a C++ program can run a wide range of computers. Concept - The popularity of C++ makes it an important language to learn.
Code Source Code Modified Source code Object Code Executable Code Text written by the programmer. Modified Source code Expanded text produced by the Pre-processor. Object Code Machine level code generated by the compiler. Executable Code Machine level code generated by the linker. Source Code Pre-processor Modified Source Code Compiler Object Code Linker Executable Code
What is a Program Made of? Language Description Element Key Words Words that have a special meaning. Key words may only be used for their intended purpose. Programmer Words or names defined by the programmer. They are Defined symbolic names that refer to variables or programming Symbols routines. Operators Operators perform operations on one or more operands. An operand is usually a piece of data, like a number. Punctuation Punctuation characters mark the beginning or ending of a statement, or separate items in a list. Syntax Rules followed when constructing a program. Syntax dictates how key words and operators may be used, and where punctuation symbols must appear. Concept - There are certain elements common to all computer programming languages.
Concept - Programs are made of a complete statements. Lines and Statements A line is one single line of program text A statement is: A complete instruction that causes the computer to perform some action May consist of more than one line A C++ statement must end in a semicolon (;) Concept - Programs are made of a complete statements.
Concept - A program stores information in variables. Symbolic names that represent locations in the computer’s Random Access M Used to reference information that may change throughout the execution of a program The name of a variable should reflect the purpose of the data it references Concept - A program stores information in variables.
Variable Declarations Variables are either numbers or characters A variable declaration statement informs the compiler: the name that will be assigned to the variable how it should be stored in memory it's initial value (optional) A variable definition statement causes a variable to be created in memory. Concept - Variables must be defined before they are used.
Input, Process, and Output A program takes data as input, processes it and returns new data as output: Input usually comes from some external source but can be the output of another process. Output is usually sent to an external device but could be input to another process. A process determines the content of the output. Concept - The three primary activities of a program are input, processing, and output.
The Programming Process 1. Clearly define what the program is to do. 2. Visualize the program running on the computer. 3. Design a flow or Hierarchy chart. 4. Check the chart for logical errors. 5. Write a pseudocode version of the program. 6. Check the pseudocode for errors. 7. Write the actual program on paper. 8. Desk check the program for syntax or logical errors. 9. Enter the code and compile it. 10 . Correct any errors found during compilation. 11. Run the test data for input . 12. Correct any logical errors found while running the program. Concept - There are a number of steps involved in successfully creating a program.
What is Software Engineering? Users Needs Deliver Analyze Maintain Debug Specify Design Code Test Modify Document Concept - Software engineering encompasses the whole process of crafting computer software.
Procedural and Object-Oriented Programming Procedural programming organizes code into functional subroutines that perform specific types of tasks. Object oriented programming addresses the relationships between program features. Concept - Procedural programming and object-oriented programming are two ways of thinking about software development and program design