computer science-i (csit121) dr. junaid ahmed zubairi suny college @ fredonia room 210, fenton...
Post on 19-Dec-2015
236 views
TRANSCRIPT
Computer Science-I (CSIT121)
Dr. Junaid Ahmed Zubairi
SUNY College @ Fredonia
Room 210, Fenton
X-4694, [email protected]
Introduction In this course, we learn how to use
the computer effectively to solve problems
Let us go over the syllabus and then start the introductory topics.
Syllabus Textbook:
Programming and Problem Solving With C++, 2nd Edition, Nell Dale, Chip Weems and Mark Headington, Jones and Bartlett 2000
Grading System: Assigned Works 40% Exam-I 30% Exam-II 30%
Topics Introduction to Computers Overview of C++ Top Down Design Selection Repetition Function Arguments Formatting and Files Arrays and Structures User defined classes Recursion
Introducing Computers A computer is a device capable of
performing computations What is the difference between a
calculator and a computer? Answer: Taking Logical Decisions Example: if Result=0 then
R1 <= R2*R3-5; elseR1 <= R2
History of Computers 2000BC Abacus used for computations
1890 Hollerith designs electronic census reader and later founds IBM
1939 J. Atanasoff designs first electronic digital computer
1946 Von Neumann proposes stored program computer
1977 Apple Computer launched
1981 IBM PC launched
History of Computers 1970 UNIX first version released
1971 Pascal language developed
1972 C language developed
1973 Part of UNIX implemented in C
1985 C re-implemented as C++
1996 C++ standard released
Types of Computers Microcomputers (PDA, Lap-top,
Desk-top and Workstation computers)
Minicomputers and Mainframes
Supercomputers
Hardware of Computers Computers consist of
CPU Memory (Primary/Secondary) Input devices Output devices
What is a floppy drive? What is a SIMM? What is a modem?
CPU Operation
CPU is the brain of the computer It coordinates all operations and
performs specified instructions It has to bring the instructions from
main memory (fetch) It executes the current instruction
as specified (execute) It stores the results in memory if
required
Memory Operation
Memory consists of storage cells that are numbered
Computer can store and retrieve values in memory by addressing the cells and setting bits
A cell may consist of 8 bits in which case it is called a Byte
A bit can only have value 0 or 1.
Types of Memory
Main Memory consists of RAM and ROM.
ROM stores permanent settings for the computer.
RAM stores user programs temporarily when the programs are being executed
A user program cannot run if it is not loaded into RAM
Types of Memory
Secondary Memory consists of Hard disks, floppy disks, CD-ROMS, DVD’s, and tapes etc.
Hard disks contain the operating system of the computer and the user programs and data files.
Floppy disks are removable Tapes are used for backup CD-ROMS distribute software
Input/Output Devices
A keyboard is the most important input device.
Can you identify the most important output device?
Some non-traditional computers require other I/O devices such as control panels, digital displays
What is a NIC?
Programming the Computer Computer speaks ‘1’ and ‘0’ Lowest level programming
language is the machine language it uses Hex or mnemonics to convey 1’s and 0’s to the computer
0x2004=0010 0000 0000 0100 A high-level language would
resemble human-language if price > my_limit then don’t_buy
High Level to Low Level Languages
C++ Program
My_var = this_data+next_data
Compilation and Linking
0001010100111111 //Load R5 from Memory 0001010000111110 //Load R4 from Memory0110011001010100 //Add R4,R5 & store result in R60011011000111101 //Store R6 into Memory
High Level languages
Some high level languages include FORTRAN (Engineering and Science), COBOL (Business), Pascal (Instructional), Lisp (AI), C++, Java (General).
Programs written in these languages are finally translated to ‘1’s and ‘0’s before being executed
A Program’s Stages From Source to Execute
Source File
Compiler Object File
Linker/Loader
ExecutableFile
Sections of Programs
A program running in the computer would have
data input instructions e.g. read (price, my_limit)
data manipulation instructions e.g. is price > my_limit?
data output instructions e.g. write (don’t_buy)
A Problem Solving Strategy Assume that you have a problem
to be solved on computer Think about the problem
specification and identify I/O Plan on program design with data
design and procedural design Implement the program Test and debug the program
NiMo’s varying rates
Example: Niagara Mohawk wants to apply different rates to its customers. If the customer burns more than 1000 units in a month, rate B is applied else rate A is applied. You need to develop a software function that can give the total charges as output given a customer’s consumption.
NiMo’s varying rates
You develop the data model for this problem
What is the input to your function? Answer: consumption, A, B What is the output? Answer: charges What formula to be used? Answer (A or B)*consumption
Top Down Design
If you are given a complex problem, you are better off dividing it into sub-problems
Target is to let each sub-problem deal with one aspect of the software
Thus you can rapidly develop the software to solve complex problems
NiMo’s varying rates
In our example, the program can be divided into three sections:
Answer: Input, processing, output Write a code segment to get the
rates Write a code segment to process
the charges Write a code segment to output the
charges
Algorithm Development
Once given a problem, you need to develop an algorithm to solve it
An algorithm is a series of steps needed in a certain order to solve a problem
Algorithm refinement is done to break it into smaller modules
Desk check is done to make sure it will indeed solve the problem
Software Testing
Once you have coded the program, you should test it to make sure it works
Testing is related to the requirements developed in problem analysis phase
Testing is exhaustive Testing is a specialized field
Documentation
When you develop a program, make sure that you document it properly
Documentation consists mainly of User Guide Administrator Guide Comments in the source code Description of strategy
Maintenance
A program being used requires maintenance over a period of time
What are the reasons for maintenance?
Answer: Bug discovery, finding out some limitations, future expansion of requirements
Example: yy or yyyy for year tracking
Structured Programming Structured programming calls for
Top Down modular design Each module can be refined further
until single-minded modules are achieved
Sharing of data among modules should be reduced to avoid confusion during debugging
Object Oriented Programming An object is a data and procedural
abstraction data represents attributes procedures represent behavior OOP hides attributes and behavior
in classes Classes are used as templates to
create objects
Think about Objects
We find objects everywhere!! A table is an object Table’s attributes include its height,
width, material used etc. Table’s behavior includes its
usage. For example, you can study on a table or eat on a table but you cannot travel on a table!!
Think about Objects
A car is an object The attributes of a car include its
make, model, color, number of seats etc.
The behavior of a car includes stopping on applying brake, accelerating on applying gas, turning, moving from a place to another place
Objects hide information
Objects hide the attributes and behavior from others
Information hiding means the details of implementation are hidden
Objects can communicate through interfaces
Do you need to know how car brakes or accelerator work?
Our Approach
In this course, we primarily focus on structured programming
A good structured programming background would help you a lot in object oriented programming
The behavior of objects will be ultimately built from structured programming constructs