410 likes | 575 Views
INTRODUCTORY CONCEPTS. EC201- FUNDAMENTAL PROGRAMMING. Introduction To Computers. A computer is a device capable of performing computations and making logical decisions at speeds millions (even billions) of times faster than human beings can.
E N D
INTRODUCTORY CONCEPTS EC201- FUNDAMENTAL PROGRAMMING DTK, JKE, PTSB (V 10.12)
Introduction To Computers • A computer is a device capable of performing computations and making logical decisions at speeds millions (even billions) of times faster than human beings can. • A computer is a system made of two major components: hardware and software. DTK, JKE, PTSB (V 10.12)
A computer system DTK, JKE, PTSB (V 10.12)
Computer Hardware DTK, JKE, PTSB (V 10.12)
Computer Software DTK, JKE, PTSB (V 10.12)
Computer Languages Evolution • We must use a computer language to write a program for a computer. Programmers write instructions in various programming languages, some directly understandable by computers and others requiring intermediate translation steps. Hundreds of computer languages are in use today. These may be divided into three general types: 1. Machine languages (1940s) 2. Assembly languages (1950s) 3. High-level languages (1960s)
Machine Languages • Any computer can directly understand only its own machine language. • Machine language is the "natural language" of a computer and as such is defined by its hardware design. • The instructions in machine language must be in streams of 0 and 1 because the internal circuit of a computer is made of switches, transistors, and other electronic devices that can be in one of two states: off or on. The off state is represented by 0; the on state is represented by 1. • The only language understood by a computer is machine language.
Assembly Languages • An assembly language is a low-level language for programming computers. • It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture. • This representation is usually defined by the hardware manufacturer, and is based on abbreviations (called mnemonics) that help the programmer remember individual instructions, registers, etc. • A special program called an assembler is used to translate mnemonics code into machine language.
High-level Languages • High-level language are portable to many different computers. • High-level language are design to relieve the programmer from the details of the assembly languages. • High-level language still must be convert to machine language and the process is called compilation. • FOTRAN is the first widely used high-level language.
Introduction To Programming DTK, JKE, PTSB (V 10.12)
Types Of Programming Languages DTK, JKE, PTSB (V 10.12)
Structured Programming • A special type of procedural programming • Provides additional tools to manage the problems that larger programs were creating. • Requires that programmers break program structure into small pieces of code that are easily understood. • Frowns upon the use of global variables and instead uses variables local to each subroutine. • One of the well known features of structural programming is that it does not allow the use of the GOTO statement. • It is often associated with a "top-down" approach to design. • The top-down approach begins with an initial overview of the system that contains minimal details about the different parts. • Subsequent design iterations then add increasing detail to the components until the design is complete. • The most popular structured programming languages include C, Ada, and Pascal. DTK, JKE, PTSB (V 10.12)
Modular Programming • Breaking down the design of a program into individual components (modules) that can be programmed and tested independently. It is a requirement for effective development and maintenance of large programs and projects. • Modular programming has evolved into object-oriented programming, which provides formal rules for developing self-contained software modules • Building a program in modules, or independent routines, is common practice. • The module performs a function and then returns control back to the program or instruction that called it. • Modular programming has evolved into object-oriented programming, which provides stricter rules for developing self-contained routines. DTK, JKE, PTSB (V 10.12)
Object-Oriented Programming (OOP) • Object-oriented programming focuses on data before anything else. • How data is modeled and manipulated through the use of objects is fundamental to any object-oriented program. DTK, JKE, PTSB (V 10.12)
Comparison Structured Programming/ Modular Programming Object-Oriented Programming Save time and energy when writing simple programs that implement classes or complex functions as would be the case in object-oriented programming. In most cases straightforward pieces of code would get the job done. Ideal for development of small programs as it would beat the purpose spending a lot of time and energy designing classes when an entire working program could be developed within the same time period. Small programs are easy to maintain and most fit within a single page or so, making more sense for the Web developer to visualize the program code. Easy to read and understand as you would simply need to follow the source code as it is written on the file as you would be guaranteed that there are no jumps or deviations to other pieces of code in other files. Its suitability for sustaining huge software and web development projects. Better option than using structured programming when you have massive code bases. The sheer nature of object-oriented programs allows the developer to save a lot of time and energy when developing programs as the components of the programs are in the form of objects which can be plugged into the program wherever they are needed. Having an application with several hundred buttons implemented as objects would be pretty easy to maintain, for example, if the developer wanted to change the style or behavior of all the buttons, it would simply entail changing a single object which defines everything about the button and this would change every instance of the button object. More complex than structured programming as there is a lot as far as design the decisions that need to be made and consequently the entire task of managing the project may be a bit difficult to the inexperienced web developer. DTK, JKE, PTSB (V 10.12)
Problem Solving (Problem Solving in Everyday in Life) • People make decisions everyday • Should I watch TV or go out to cinema, what career, what course? • What happens when bad decisions are made in business? • Wrong decisions cost money; time and resources are wasted, important to know how to make a decision. DTK, JKE, PTSB (V 10.12)
Stages Involved In Problem Solving DTK, JKE, PTSB (V 10.12)
Elements Of Problem Analysis DTK, JKE, PTSB (V 10.12)
Design Tools For Problem Solving DTK, JKE, PTSB (V 10.12)
Flowchart • Type of diagram that represents an algorithm or process, showing the steps as boxes of various kinds, and their order by connecting these with arrows. • Step-by-step solution to a given problem. • Process operations are represented in these boxes, and arrows connecting them represent flow of control • Data flows are not typically represented in a flowchart, in contrast with data flow diagrams; rather, they are implied by the sequencing of operations • Used in analyzing, designing, documenting or managing a process or program in various fields DTK, JKE, PTSB (V 10.12)
Nod and Symbol DTK, JKE, PTSB (V 10.12)
Flow Chat Example 1 • HPNM more then 3.7 Start Insert HPNM Yes if HPNM > 3.7 Good No Try Again End DTK, JKE, PTSB (V 10.12)
Start Insert key Free Gear Turn key to on position NO NO Engine on in 6 second > 5 time YES YES Release the key Call the garage End Flow Chat Example 2 • Process of starting the car engine DTK, JKE, PTSB (V 10.12)
Pseudocode • An artificial and informal language that helps programmers develop algorithms • A "text-based" detail (algorithmic) design tool. • The rules of Pseudocode are reasonably straightforward • All statements showing "dependency" are to be indented. These include while, do, for, if, switch DTK, JKE, PTSB (V 10.12)
Pseudocode Example 1 • Look at the diagram carefully. How can you break it up into multiple, simpler to do parts. DTK, JKE, PTSB (V 10.12)
Draw 4 rectangles • one is tall and thin • three are short and form a stack of rectangles next to the first - OR - • Draw 7 lines (4 horizontal and 3 vertical) • 4 lines form the perimeter of a big rectangle • 1 line splits this rectangle in half vertically • 2 lines split the right half of the rectangle into 3, equally sized rectangles - OR - • Draw 13 line segments (6 horizontal and 7 vertical) • This is hard to describe; so, I'm choosing not to go any further with it. But, it is a way of looking at the problem. DTK, JKE, PTSB (V 10.12)
Pseudocode(Written on Paper) • Draw a square • Draw the vertical line that splits the square in half • Draw the top horizontal line spliting the right half • Draw the bottom horizontal line spliting the right half DTK, JKE, PTSB (V 10.12)
Comparison Pseudocode Flow Chat Insert HPNM If HPNM greater than 3.7 Display “Good” Else Display “Try Again Start Insert HPNM Yes if HPNM > 3.7 Good No Try Again End DTK, JKE, PTSB (V 10.12)
IPO Chart • Tabular representation of the modules to explain the data communication between modules as well as the function of the module itself • As a design document, the items of data as well as the process should be described in English, not C • It would then be able to be implemented in any procedural language • 4 columns: module name, I, P, and O • Variable number of rows: 1 header row followed by 1 row for each module in the design • VERY IMPORTANT: Input and Output describe DATA. They do NOT describe input from file/keyboard or output to file/screen. Those tasks are part of a module's PROCESS – what it does. DTK, JKE, PTSB (V 10.12)
IPO Chart Example • Create a program to read in the length and width of a rectangle from the keyboard, calculate the area and perimeter, and display the input and calculations to screen DTK, JKE, PTSB (V 10.12)
Structure chart • Graphical representation of the modules (user-defined, not built-ins) to be implemented in a program, demonstrating in what order they will be called and which functions call which other functions DTK, JKE, PTSB (V 10.12)
Structure chart • Create a program to read in the length and width of a rectangle from the keyboard, calculate the area and perimeter, and display the input and calculations to screen • main() will call getInput() and wait for it to finish, then main() will call calcAreaPerim() and wait for it, then it will call displayReport() and wait, then main() will finish DTK, JKE, PTSB (V 10.12)
Types Of Error In Programming DTK, JKE, PTSB (V 10.12)
Syntax Error • In computer science a syntax error refers to an error in the syntax of a sequence of characters or tokens that is intended to be written in a particular programming language. • For compiled languages syntax errors occur strictly at compile-time. A program will not compile until all syntax errors are corrected. For interpreted languages, however, not all syntax errors can be reliably detected until runtime, and it is not necessarily simple to differentiate a syntax error from a semantic error; many don't try at all. • A syntax error may also occur when an invalid equation is entered into a calculator. This can be caused, for instance, by opening brackets without closing them, or less commonly, entering several decimal points in one number DTK, JKE, PTSB (V 10.12)
Run-Time Error • An error that occurs during the execution of a program. In contrast, compile-time errors occur while a program is being compiled. • Runtime errors indicate bugs in the program or problems that the designers had anticipated but could do nothing about. • For example, running out of memory will often cause a runtime error. DTK, JKE, PTSB (V 10.12)
Logical Error • In computer programming, a logic error (sometimes called a semantic error) is a bug in a program that causes it to operate incorrectly, but not to terminate abnormally (or crash). • A logic error produces unintended or undesired output or other behavior, although it may not immediately be recognized as such. • Logic errors occur in both compiled and interpreted languages. • Unlike a program with a syntax error, a program with a logic error is a valid program in the language, though it does not behave as intended. DTK, JKE, PTSB (V 10.12)
Your First C Program /* The greeting program. This program demonstrates some of the components of a simple C program. Written by: your name here Date: date program written */ #include <stdio.h> //allows program to output data to the screen main() //function main begins program exexution { printf("Welcome to C"); //display message return 0; //indicate that program ended successfully } //end function main DTK, JKE, PTSB (V 10.12)