Mid Term

24
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

description

ghsthwththwst

Transcript of Mid Term

Page 1: Mid Term

• 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

Page 2: Mid Term

• 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

Page 3: Mid Term

• 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.

Introduction to Operating System

Page 4: Mid Term

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

Page 5: Mid Term

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

Page 6: Mid Term

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 BASEPAYADD OVERPAYSTORE GROSSPAY

6

Page 7: Mid Term

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

Page 8: Mid Term

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++.

Page 9: Mid Term

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

Page 10: Mid Term

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

Page 11: Mid Term

Introduction to C++• Background• C++ was developed by Bjarne Stroustrup at Bell

Laboratories – Originally called “C with classes” – The name C++ is based on C’s 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”

Page 12: Mid Term

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.

Page 13: Mid Term

– 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++

Page 14: Mid Term

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++

Page 15: Mid Term

To execute a C++ program (cont'd.):

Introduction to C++

Page 16: Mid Term

Programming with the Problem Analysis– Coding–Execution Cycle Programming is a process of problem solving One problem-solving technique: Analyze the problemOutline the problem requirementsDesign steps (algorithm) to solve the problem• Algorithm:• Step-by-step problem-solving process• Solution achieved in finite amount of time

Introduction to C++

Page 17: Mid Term

Introduction to C++

Page 18: Mid Term

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

Page 19: Mid Term

• 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++

Page 20: Mid Term

• 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++

Page 21: Mid Term

• 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

Introduction to C++

Page 22: Mid Term

The Parts of a C++ ProgramThe cout ObjectVariables, Constants, and theAssignment StatementIdentifiersInteger Data TypesThe char Data TypeThe C++ string ClassFloating-Point Data TypesThe bool Data TypeVariable Assignments and InitializationArithmetic OperatorsComments

Page 23: Mid Term

The cin ObjectMathematical ExpressionsOverflow and UnderflowNamed ConstantsMultiple and Combined AssignmentRelational OperatorsThe if StatementThe if/else StatementThe if/else if StatementNested if StatementsLogical OperatorsValidating User InputThe Conditional OperatorThe switch Statement

Page 24: Mid Term

1. Sum of Two NumbersWrite 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 PatternWrite a program that displays the following pattern on the screen:

****

************

3. Miles per GallonWrite a program that calculates a car’s gas mileage. The program should ask the user toenter the number of gallons of gas the car can hold and the number of miles it can bedriven on a full tank. It should then calculate and display the number of miles per gallonthe car gets.4. Celsius to FahrenheitWrite a program that converts Celsius temperatures to Fahrenheit temperatures. Theformula is F = 9/5 C + 32where F is the Fahrenheit temperature and C is the Celsius temperature. The programshould prompt the user to input a Celsius temperature and should display the corresponding Farenheit temperature.5. Minimum/MaximumWrite a program that asks the user to enter two numbers. The program should use the conditional operator to determine which number is the smaller and which is the larger.