Introduction to Operating System
An operating system is a program that acts as an
interface between the software and the computer
hardware.
It is an integration set of specialized programs
that are used to manage overall resources and
operations of the computer.
It is specialized software that controls and
monitors the execution of all other programs that
reside in the computer, including application
programs and other system software.
Introduction to Operating System
Characteristics of Operating System
Memory Management -- It keeps tracks of primary
memory i.e what part of it are in use by whom, what part
are not in use etc. Allocates the memory when the process
or program request it.
Processor Management -- Allocate the processor(CPU) to
a process. Deallocate processor when processor is no long
er required.
Device Management -- Keep tracks of all devices. This is
also called I/O controller. Decides which process gets the
device when and for how much time.
File Management -- Allocates the resources. De-allocates
the resource. Decides who gets the resources.
Introduction to Operating System
Security -- By means of passwords & similar other
techniques, preventing unauthorized access to programs &
data.
Job accounting -- Keeping track of time & resources used
by various jobs and/or users.
Control over system performance -- Recording delays
between request for a service & from the system.
Interaction with the operators -- T he interaction may
take place via the console of the computer in the form of
instructions. Operating System acknowledges the same, do
the corresponding action and inform the operation by a
display screen.
Error-detecting aids -- Production of dumps, traces, error
messages and other debugging and error-detecting
methods.
What Is a Computer?
Computer
Performs computations and makes logical
decisions
Millions / billions times faster than human
beings
Computer programs
Sets of instructions by which a computer
processes data
Hardware
Physical devices of computer system
Software
Programs that run on computers
Computer Organization
Six logical units of computer system
Input unit
Mouse, keyboard
Output unit
Printer, monitor, audio speakers
Memory unit
Retains input and processed information
Arithmetic and logic unit (ALU)
Performs calculations
Central processing unit (CPU)
Supervises operation of other devices
Secondary storage unit
Hard drives, floppy drives
Machine Languages, Assembly
Languages, and High-level
Languages
Three types of programming languages
Machine languages
Strings of numbers giving machine specific
instructions
Example:
+1300042774 (these would really be in binary)
+1400593419
+1200274027
Assembly languages
English-like abbreviations representing
elementary computer operations (translated via
assemblers)
Example:
LOAD
ADD
STORE
BASEPAY
OVERPAY
GROSSPAY
Machine Languages, Assembly
Languages, and High-level Languages
High-level languages
Instructions closer to everyday English
English is a natural language. Although high level
programming languages are closer to natural
languages, it is difficult to get too close due to the
ambiguities in natural languages (a statement in
English can mean different things to different people
obviously that is unacceptable for computer
programming). However, this is a big research area of
computer science.
Use mathematical notations (translated via
compilers)
Example:
grossPay = basePay + overTimePay
Interpreter Executes high level language programs
without compilation.
7
Debugging with High Level
Languages
The process of finding and removing
programming errors is called
debugging.
There are types of errors or bugs are
occurred while writing a program in
high level languages like C, C++.
Types of Errors
Syntactic Errors
Input code is not legal
Caught by compiler (or other translation mechanism)
Semantic Errors
Legal code, but not what programmer intended
Not caught by compiler, because syntax is correct
Logical / Algorithmic Errors
Problem with the logic of the program
Program does what programmer intended,
but it doesn't solve the right problem
Introduction to C++
The Evolution of Programming
Languages
High-level languages include Basic,
FORTRAN, COBOL, Pascal, C, C++, C#,
and Java
Compiler: translates a program written
in a high-level language machine
language
Introduction to C++
Background
C++ was developed by Bjarne
Stroustrup at Bell Laboratories
Originally called C with classes
The name C++ is based on Cs increment
operator (++)
Indicating that C++ is an enhanced version of C
Widely used in many applications and
fields
Well-suited to Programming in the
Large
Introduction to C++
Processing a C++ Program
#include <iostream.h>
int main()
{
cout << "My first C++ program.";
return 0;
}
Sample Run:
My first C++ program.
Introduction to C++
To execute a C++ program:
Use an editor to create a source
program in C++
Preprocessor directives begin with #
and are processed by a the preprocessor
Use the compiler to:
Check that the program obeys the rules
Translate into machine language (object
program)
Introduction to C++
To execute a C++ program (cont'd.):
Linker:
Combines object program with other
programs provided
by the SDK to create executable code
Loader:
Loads executable program into main
memory
The last step is to execute the program
Introduction to C++
To execute a C++ program (cont'd.):
Introduction to C++
Programming with the Problem Analysis
CodingExecution Cycle
Programming is a process of problem solving
One problem-solving technique:
Analyze the problem
Outline the problem requirements
Design steps (algorithm) to solve the problem
Algorithm:
Step-by-step problem-solving process
Solution achieved in finite amount of time
Introduction to C++
Introduction to C++
Run code through compiler
If compiler generates errors
Look at code and remove errors
Run code again through compiler
If there are no syntax errors
Compiler generates equivalent machine
code
Linker links machine code with system
resources
Introduction to C++
Once compiled and linked, loader can
place
program into main memory for execution
The final step is to execute the program
Compiler guarantees that the program
follows the rules of the language
Does not guarantee that the program will
run correctly
Introduction to C++
Example 1
Design an algorithm to find the perimeter
and area of a rectangle
The perimeter and area of the rectangle
are given by the following formulas:
perimeter = 2 * (length + width)
area = length * width
Introduction to C++
Example 1
Algorithm:
Get length of the rectangle
Get width of the rectangle
Find the perimeter using the following
equation:
perimeter = 2 * (length + width)
Find the area using the following equation:
area = length * width
The Parts of a C++ Program
The cout Object
Variables, Constants, and the
Assignment Statement
Identifiers
Integer Data Types
The char Data Type
The C++ string Class
Floating-Point Data Types
The bool Data Type
Variable Assignments and Initialization
Arithmetic Operators
Comments
The cin Object
Mathematical Expressions
Overflow and Underflow
Named Constants
Multiple and Combined Assignment
Relational Operators
The if Statement
The if/else Statement
The if/else if Statement
Nested if Statements
Logical Operators
Validating User Input
The Conditional Operator
The switch Statement
1. Sum of Two Numbers
Write a program that stores the integers 62 and 99 in variables, and
stores the sum of these two in a variable named total. Display the total
on the screen.
2. Triangle Pattern
Write a program that displays the following pattern on the screen:
*
***
*****
*******
3. Miles per Gallon
Write a program that calculates a cars gas mileage. The program should
ask the user to
enter the number of gallons of gas the car can hold and the number of
miles it can be
driven on a full tank. It should then calculate and display the number of
miles per gallon
the car gets.
4. Celsius to Fahrenheit
Write a program that converts Celsius temperatures to Fahrenheit
temperatures. The
formula is F = 9/5 C + 32
where F is the Fahrenheit temperature and C is the Celsius temperature.
The program