0% found this document useful (0 votes)
65 views

Chapter 1 Part 1

The document provides an introduction to computer programming, including: - A brief history of computers and programming languages from machine language to modern languages. - An explanation of what a computer program is, the importance of programming, and the relationship between compilers, interpreters, and assemblers. - Guidelines for writing good programs, including producing reliable output, program efficiency, interactivity with users, and readability through proper formatting, indentation, spacing, and comments.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Chapter 1 Part 1

The document provides an introduction to computer programming, including: - A brief history of computers and programming languages from machine language to modern languages. - An explanation of what a computer program is, the importance of programming, and the relationship between compilers, interpreters, and assemblers. - Guidelines for writing good programs, including producing reliable output, program efficiency, interactivity with users, and readability through proper formatting, indentation, spacing, and comments.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 34

CHAPTER 1

Introduction
(Part 1)
CSC 128
FUNDAMENTALS OF COMPUTER PROBLEM SOLVING

By: Umi Hanim Mazlan, FSKM


CONTENTS
• A Brief History of Computer and Programming
Languages

• Introduction to Programming
▫ What is a computer program
▫ Importance of computer program
▫ Importance of good program
▫ Relationship between compilers, interpreters,
assemblers and programs
Objectives
• In this chapter you will :

▫ Learn history of computer


▫ Learn about history and evolution of
programming language
▫ Learn about programming
▫ Learn about importance of computer program
▫ Learn about the relationship between compilers,
interpreters, assembler and program
Computer History
• The word computer was first used and recorded
in 1613
• Referring to a person who carried out
calculations or computations
• From the end of 19th century onwards though the
word began to take on its more familiar
meaning, describing a machine that carries out
computations
Computer History
• Early digital computers:
▫ Zuse Z3
▫ Atanasoff Berry Computer
▫ Collosus
▫ Harvard Mark I – IBM ASCC
▫ ENIAC
▫ Manchester Small-Scale Experimental Machine
▫ EDSAC
▫ Manchester Mark 1
▫ CSIRAC
Programming Languages History
 To write a program for a computer, we must
use a computer language

 Over the years computer languages have


evolved form machine language to natural
languages.
g es es g es
g ua
g ua ua g
g an
La
n n el
La ev s l L
in
e
lic h-L age u ra ng)
c h bo g u t vi
a m Hi ng Na vol
M Sy La (e

1940s 1950s 1960s 1970s 1980s 1990s


Programming Languages History
• 1st generation (low-level language)
- Machine Language is the basic language of the computer, representing data as
1’s and 0’s.
• 2nd generation
- Assembly language (low-level language) that allows a computer user to write
a program using simple word instead of numbers.
• 3rd generation
- High-level language resembles some human language (English)
- Ex: COBOL, FORTRAN, BASIC.
- Procedural languages.
• 4th generation
- Very high-level language, much more user-oriented and allow users to
develop programs with fewer commands compared with procedural
languages
- Ex: SQL, NOMAD
• 5th generation
- Natural Language uses human language to give people a more natural
connection with computers.
Programming Languages Evolution
• Early computer were programmed in machine
language
• To calculate wages = rates * hours in
machine language :
100100 010001 //Load
100110 010010 //Multiply
100010 010011 //Store
Programming Languages Evolution
• Assembly language instructions are mnemonic
• Assembler: translates a program written in
assembly language into machine language
Programming Languages Evolution
• Using assembly language instructions,
wages = rates • hours can be written as:

LOAD rate
MULT hour
STOR wages
Programming Languages Evolution
• Using high level language instructions, wages
= rates • hours can be written as:
#include <iostream.h>
int main()
{
int rates;
int hours;
int wages;

cout << “Insert rates: ”;


cin >> rates;
cout << “\nInsert hours : ”;
cin >> hours;

wages = rates * hours;


cout << “\nTotal wages :” <<wages;
return 0;
}
What is Computer?
• Computer is an electronic device that accept
input, processes data, store data and generate the
output

• Device capable of performing computations and


making decisions at speeds millions and even
billions of times faster than human being can
(H.M., Deitel and P.J., Deitel, 2001)

• Programmable machine designed to follow


instructions (Tony Gaddis, 2007)
Basic components of a computer
systems
Hardware
 Device that processes data to create information (ex:
input, output, storage and processing devices)

Software
 Step-by-step instructions that tell the computer how
to do its work.
 It is also called a program.
 It’s purpose to convert data to useful information
Basic components of a computer
systems

SOFTWARE

SYSTEM SOFTWARE
• provides an environment for user
to execute the application APPLICATION SOFTWARE
software.
•Enables the application software • end user software.
to interact with computer •A program that performs a
hardware. common task to the user.
•Eg. Operating System •Eg. Word, Excel.
Main Hardware Component Categories
Main Hardware Component Categories
• Input Devices
▫ Is usually a keyboard where programs and data
are entered into the computer.
▫ Ex: mouse, pen/stylus, touch screen, audio input
unit
• CPU, Central Processing Unit
▫ Function is to execute instructions, such as
arithmetic calculations, comparisons among data,
and movement of data inside the system
Main Hardware Component
Categories
• Main memory/Primary Storage
▫ Is a place where the programs and data are stored
temporarily during processing.
▫ The data in primary storage are erased when you
turn off a personal computer or you log off from a
time-sharing computer
• Secondary Storage Devices
▫ It is the place where the programs and data are
stored permanently
Main Hardware Component
Categories
▫ When you turn off the computer, your programs
and data remain in the secondary storage ready f0r
the next time you need them
▫ Ex: Hard disk
• Output Devices
▫ Is usually a monitor or a printer where the output
will be shown.
▫ If the output is shown on the monitor; we say we
have a soft copy. if it is printed on the printer, we
say we have a hard copy.
▫ Ex: monitor, printer
Basic Operation in Computer
System
STORAGE
•Store the data or information for
future use (permanently or
INPUT temporarily)
•Whatever data that is PROCESSING •E.g. Hard disk, memory
inserted into a computer
using input devices •Convert input data into
•E.g. Mouse, keyboard information.
•E.g. CPU OUTPUT
•Generate the useful
information using output
devices
•E.g. Monitor, printer
Computer Program
• Program is a set of instructions that the computer needs to
follow to process the data into information.
• Programming Language contains set of instructions, data
and rules that are used to construct a program. Ex: C++, C,
VB
• Programming is the act of designing/writing and
implementing computer programs using the programming
languages.
• Programmer is a person who writes a computer program.

>> SO, without programmers, no programs; without programs, a


computer cannot do anything
The Importance of Programming
Easy to express tasks from a particular problem
domain.
Allow user to instruct computer to do a specific
task in a certain instances.
A skill required for a computer scientist and
software engineering.
A skill required to create a successful computer
program.
Good Programming Styles
• Reliability of Output
▫ Good program should produce correct output
▫ During testing phase different set of input data is used to
ensure the reliability of output

• Program’s Efficiency
▫ Good program should be reliable and efficient in the
sense that it is produces no errors during execution
process
▫ Program must achieve its purpose so that the final result
can be trusted
▫ Use of pseudocode or flowchart to outline the program
Good Programming Styles
• Interactivity

▫ Interaction between user and the program is well defined


▫ Interactivity is important so that the user knows the
processing status
▫ User-friendly programs allow user to respond to the
instructions correctly and allow them key in valid input

• Program readability

▫ Readability is concerned with how other person views


one’s program
▫ Use of indention and comment increase the level of
readability
Good Programming Styles
• Spacing

▫ Each instruction begins with new line

• Indent

▫ Each instruction has indention depends on its structure


▫ Makes the structure of the program clearer and easy to
read
▫ A statement within a statement should be indented to
show the user which statement is subordinate of the
other
Good Programming Styles
• Comments

▫ Help a human reader to understand the program


▫ Can be placed anywhere within a program
▫ Will not be executed by compiler
▫ C++ supports two types of comments
 Line Comment
 Block Comment
Good Programming Styles
• Comments (Cont…)

▫ Line comment
 Begin with two slashes (//)
 Ex: //This is Line comment

▫ Block Comment
 Begin with the symbol /* and end with the symbol */
 Use for statements that span across two or more
lines
 Ex: /* This program calculates the salary of
employees */
Example
// Programmer: Umi Hanim Mazlan line comment

/* Date : 19 July 2010


Title : Greeting program */ block comment

#include <iostream.h>

int main() spacing

{
--> cout<< “Hello world!\n”;

return 0; indent
}
Program Errors
• Also known as bugs
• Debugger (software tool) – trace through a
program to find bugs (logic errors)
• Can be divided into:
▫ Compile-Time errors or syntax error
 detect by compiler
▫ Run-Time errors or logic
 is detected when the program is being running
Program Errors (Cont…)
• Syntax errors
▫ Syntax error is an error in the structure or spelling of a
statement
▫ Can be detected by compiler

• Example
1 cout << “/n There are five syntax errors”
2 cot >> “Correct Them;

Invalid use of backslash (/) in Line 1


Missing semicolon (;) in Line 1
Keyword cout is misspelled in Line 2
Invalid use of symbol (>>) in Line 2
Missing a closing quote( ” ) in Line 2
Program Errors (Cont…)
• Logic errors
▫ Refer to unexpected or unintentional errors
resulted from some flaw in the program’s logic
▫ Compiler cannot fix logic error
▫ Some indication of logic errors
 No output
 Unappealing or misaligned output
 Incorrect numerical results
 Premature program termination
Program Errors (Cont…)
Logic errors (Cont…)
Example

1 int radius = 4.562, num = -4, count = 0;


2 float total = 10.0, average;
3 average = total/count;
4 cout << “Average is “;
5 cout << “\n the square root of ” << num << “ is ” << sgrt(num);

Assigning invalid values to variable of type integer in Line 1


Attempting to divide by zero in Line 3
Missing numerical output in Line 4
Taking the square root of a negative number in Line 5
Language Translator
 A program that accepts a human-readable
source statements and produces machine-
readable instructions. There are Assembler,
Compiler, Interpreter.
Program Translator (Cont…)

SOURCE CODE • a program is a plain text written


using any text editor

ASSEMBLER INTERPRETER
COMPILER
• a program that • a program that translates • a program that translates
translates the assembly high-level language into source code of high-level
language program into machine language. language into machine
machine language. •Translate the source code language.
once and saves to be reused. •Each instruction is
•Requires less memory and interpreted into machine
runs faster. language.
•Eg. PASCAL, C++, COBOL •Program is easier to develop.
•Eg. BASIC.
End of Chapter 1
(Part 1)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy