Title: CIS162AB - C
1CIS162AB - C
- Introduction to C
- CIS105 Review
- Juan Marquez
- 01_intro.ppt
2Two-Part Presentation
- Part 1
- CIS105 Review
- Part 2
- Introduction to C
- Compiling Process
3CIS105 Review (part 1)
- Hardware
- Information Processing Cycle
- Software
- Programming Languages Generations
- Software Development Life Cycle
4A Computer is an electronic device consisting of
hardware.
- Input Devices
- Keyboard
- Mouse
- Scanner
- Output Devices
- Console (Display)
- Printer
- Storage Devices
- Hard drive
- Zip Disk
- Flash Disk
- Internally
- Central Processing Unit (CPU)
- CPU Executes Instructions
- Memory (RAM)
5Hardware Model
The hardware configuration is used to support the
Information Processing Cycle.
6Information Processing Cycle
Output from one process can serve as input to
another process.
7What do we need to operate the hardware and
transform data into information?
Software!
8Software Two Major Categories
- Operating System (OS)
- Application Software
9Operating System (OS)
- Software that allocates and monitors computer
resources including memory allocation, storage,
and security. - Various devices are controlled using system
programs called drivers. - OS ExamplesWindows, UNIX, DOS, VMS, etc.
10Computer Resources
- As we go through the course, we will want to
conceptually understand - Memory allocation
- Storage
- Well cover storage later, but lets look at
memory now
11Main Memory
- Random Access Memory (RAM).
- Contents are lost when power is turned off.
- Measured in bytes.
- Each byte stores eight bits.
- BIT Binary Digit (0 1)
- Each byte is considered a location.
- Each byte has an address to identify its
location. - Application currently running and the data being
manipulated must be loaded in memory (RAM). - CPU only gets and stores data in RAM.
12Question
- What is a nibble?
- A nibble is half a byte.
- A byte is 8 bits, and a nibble is 4 bits.
13Memory Locations
Address 1 Address 2 Address 3 Address 4 Address
5 Etc All consecutive
14Memory Allocation
Applications
15Application Software
- Actual software we use to process raw data into
information. - Application ExamplesWord, Excel, Powerpoint,
Access, etc. - Application software is used in many industries.
- Business Accounting, Sales
- Manufacturing Inventory, Labor
- Education Enrollment, Research
- Personal Budgeting, School
16How is software developed, and in particular, how
is application software developed?
By using a programming language!
17Syntax
- There are several languages to choose from.
- Each language has a set of commands that can be
used. - Each language has a set of syntax rules that must
be followed. - Syntax determines many things like how commands
are entered and how each command should end
(period, semi-colon, etc).
18Programming Categories
- Procedural Programming
- The programmer must specify in the correct
sequence what to do and how to do it. Emphasis
is on the procedures for solution. - Programmer controls the processing for users.
- Procedural techniques are used in all categories.
- Object Oriented Programming
- Programming using predefined classes and/or
programmer defined classes to build programs. - Event Programming
- Usually related to GUI programs.
- Program reacts to events, like a user clicking on
a mouse. - User has a little more control of the processing,
because they can decide which text to enter
first. - The program ultimately validates the data, so
maintains some control.
19Generations of Programming Language
- Machine Language (1GL)
- Low-level (2GL)
- High-Level (3GL)
- Query Languages (4GL)
- Natural Languages (5GL)GL Generation Language
20Machine Language (1GL)
- Code is Machine or CPU dependent.
- So it is not portable.
- Very cryptic and difficult to code.
- Sample code
- 1001 1010 0110 0101 1100 0011
- Series of binary digits (bits, 0-1).
- Actual code that can be processed by CPU.
21Low-level (2GL)
- Called Assembly.
- Source code is machine and CPU dependent.
- Still cryptic and difficult to code.
- Sample code
- add P,TL (add price to total)
- add T,TL (add tax to total)
- This code is transformed to machine language by a
program called an assembler.
22High-level (3GL)
- Languages are ANSI.
- American National Standards Institute
- Machine and CPU independent.
- Code is more English like.
- COBOL code
- Add tax to price giving total. (note period)
- C, C, and Java Code
- total tax price
- Code is transformed to executable machine
language by using special programs called a
compiler and linker.
23Compiler and Linker
- Compiler
- Verifies the program is coded with commands it
recognizes and that the proper syntax was used. - Creates an object file (machine language).
- Linker
- A program that combines the programs object file
with object code of standard routines from the
library. - Creates the final executable file.
24Procedural Languages
- 1st, 2nd, and 3rd GLs are procedural.
- The programmer must specify in the correct
sequence what to do and how to do it. - Instructions are in detail and precise.
25Query Languages (4GL)
- 4GLs are nonprocedural.
- Programmers must only specify what to do.
- The tool figures out how.
- Many report writers fall into this category.
- Focus, Datatrieve, and SQL (Structured Query
Language) - There are still syntax rules to follow.
- Sample SQL Code
- Select sum(enrolled) from enrollment where course
CIS163AA
26Natural Languages (5GL)
- A computer language that incorporates the
concepts of knowledge-based systems, expert
systems, inference engines, and natural language
processing . - Very loose syntax rules.
- Sample code
- What is the total enrollment in the Java courses?
- Must define enrollment and Java (CIS163AA) for
the product. - Some loose definitions include Visual Basic, but
VB is not a 5GL. It does not meet the definition
above.
27Programming
- Programming is solving a problem using a
computer. - A program is a set of specific instructions for a
computer to follow. - It is a complex process and each program takes on
a life of its own called SDLC. - Software Development Life Cycle
28SDLC
- Software Development Life Cycle.
- There are various methodologies to develop
programs, but most follow the same process. - The actual name for each step in the process may
vary by vendor.
29SDLC 3 Phases, 8 Steps
- Problem Solving Phase
- Problem Definition
- Algorithm Design
- Implementation Phase
- Build, Test, Install, and Training
- Support Phase
- Maintenance
- Obsolete
30SDLC - Problem Solving Phase
- Problem definition (Analysis of the task)Users
need a screen to do a Sales Order
Calculation.(qty, price, tax, freight) - Algorithm Design (Solution)Desk check with
common and extreme data.
31Problem Solving Diagrams
- Diagrams are independent of programming
language.
- Analysis Diagrams / Tools
- Data Flow Diagram (DFD)
- Entity Relationship Diagrams (ERD)
- Functional Descriptions
- Use Case Diagrams (Object-Oriented)
- Design Diagrams / Tools
- Input Output Charts (IPO)
- Flowcharts - detailed logic
- Structure charts modules identified
- Class Diagrams (Object-Oriented)
- We will see examples of these throughout the
course.
32SDLC Implementation Phase
- Implement or Build (Code the program).
- Test the program using test data.Actual output
must match expected results. - Deploy or install.May require data conversion or
hardware upgrades. - Training User Documentation.
33SDLC Support Phase
- Maintenance change program as needednew tax
rates, new freight carrier, etc.zip4, Y2K, new
area code. - Obsolete program is discarded due to requiring
too much effort to corrector new technology (DOS
to Windows).
34On Your Homework Assignments
- I will provide
- problem definition
- You will
- Design Algorithm
- Build
- Test
35C Introduction (part 2)
- C History (brief)
- Sample Program
- Coding Style
- Some C statements
- Compile, Link, and Execute
- Programming Errors
36History of C
- C was derived from C.
- C was developed by ATT Bell Laboratories in the
late 70s. - C was used to write UNIX, which is an Operating
System (OS). - C was then used to develop commercial
applications to run on UNIX. - Eventually C compilers were developed for other
OSs.
37Features of C
- C is a high-level language with features of a
low-level language. - C can directly manipulate the computers memory
like an OS (consider UNIX history). - Can be difficult to understand and use if coded
cryptic.
38Introduction to C
- C was developed to be a better C (1980s).
- Most C programs compile as C programs, because
many of the old libraries are still maintained in
C. - C has the capability to do object-oriented
programming (OOP) through the use of classes. - We will learn how to develop classes in the last
section of this course.
39Coding Style
- Block layout indent related code.
- Make programs easy to read.
- Use whitespace between commands and sections.
- Open and closing braces on separate lines .
- Each command on a separate line.
- Each statement ends with a semicolon ( ).
- Declare all variables at the top.
40Sample C Program
- //P01 Hello World - Juan Marquez TR 100pm
- include ltiostreamgt
- using namespace std
- void main( )
-
- cout ltlt Hello World by Juan Marquez \n\n"
41Text files to Machine Language
- C programs are text files .
- In Windows they have a .cpp extension,P01.cpp.
- C programs can be written in any text editor,
such as Notepad or Wordpad. - Well be using Microsoft Visual C, which
includes a text editor. - Text files must be converted to machine language.
- How?
- By compiling
42Compiling
Text Editor
P01.cpp
WarningsErrors
Compiler
P01.obj
Library iostream
Linker
P01.exe
43Three Categories of Errors
- Syntax Errors and Warnings
- Logic Errors
- Run-time Errors
- Actually are logic errors.
44Syntax Errors Warnings
- Detected by compiler, but corrected programmer.
- Violation of grammar rules.
- Mistyped commands.
- Compiler tells you what the error is,or what it
thinks it is. - Compiler tries to tell you where the error
occurred. - Warnings
- Passes syntax rules but not normally coded this
way. - Programmer should check for possible logic error.
45Logic Errors
- Detected and corrected by programmer.
- Program designed or written incorrectly.
- Output generated does NOT match expected output.
- Simple to very complex.
- Using (multiply) instead of (add)
- Test, test, text and verify results.
- This is where programmers earn their money.
46Run-time Errors
- Usually discovered by user, but corrected by
programmer. - Program terminates unexpectedly.
- Error access violation
- Usually based on a logic error.
- Divide by zero
- Users do something programmer didnt expect them
to do. - Processing unexpected input, such as entering
letters instead of numbers. - Users need to document what they were doing when
the error occurred to help programmer.
47Summary
- Hardware Components
- Information Processing Cycle
- Software Categories
- Generations of Programming Languages
- Software Develop Life Cycle (SDLC)
- Compiling Process
- Types of Errors