0% found this document useful (0 votes)
5 views28 pages

PPS Unit 1&2

The document provides a comprehensive overview of computer systems, detailing the components such as the input unit, CPU, and output unit, along with their functions. It also explains software, operating systems, programming concepts like source and object code, and the differences between compilers and interpreters. Additionally, it covers algorithms, flowcharts, and pseudocode, emphasizing their importance in programming and problem-solving.

Uploaded by

kaushal raha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views28 pages

PPS Unit 1&2

The document provides a comprehensive overview of computer systems, detailing the components such as the input unit, CPU, and output unit, along with their functions. It also explains software, operating systems, programming concepts like source and object code, and the differences between compilers and interpreters. Additionally, it covers algorithms, flowcharts, and pseudocode, emphasizing their importance in programming and problem-solving.

Uploaded by

kaushal raha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

PMPS

Unit1
Q1) (5) Components of a computer system with diagram.
Ans:
A Computer is an electronic device that receives input, stores or processes the input as per user
instructions and provides output in desired format.
They consist of hardware components, such as the central processing unit (CPU), input/output
devices (like keyboards, mice, monitors), and memory, storage devices, networking components.
These components work together to perform various tasks, ranging from simple calculations to
complex computations to provide desired results.
Components of a Computer
There are three important components of a computer:

1. Input Unit
2. Central Processing Unit(CPU)
3. Output Unit

1. Input Unit:
The input unit consists of input devices that are attached to the computer.
These devices take input in human understandable language and convert it into binary
language that the computer understands. Some of the common input devices are keyboard,
mouse, joystick, scanner, etc.

2. Central Processing Unit:


A Central Processing Unit (CPU) is the primary component of a computer system responsible
for executing instructions and performing arithmetic, logic, and control operations.
The CPU operates on a cycle known as the fetch-decode-execute cycle. It fetches instructions
from memory, decodes them to understand what operation needs to be performed, and
then executes those instructions, and then either stores the output or displays it on the
output device.
The CPU is responsible for various data processing operations, communication between
input and output devices, and the storage of data, instructions, and intermediate results.
It consists of three main units:

• Control Unit (CU)


• Arithmetic and Logical Unit (ALU)
• Memory Unit

1. Control Unit (CU):


→ The Control Unit manages and coordinates the operations of the CPU. It controls the
flow of data and instructions within the CPU and between the CPU and other parts of
the computer system.
→ It fetches instructions from memory according to the program counter's value,
decodes these instructions, and then directs the operations needed to carry out the
instruction.
→ The CU generates control signals that manage the operation of other parts of the
CPU, such as the ALU and registers.
2. Arithmetic Logic Unit (ALU):
→ The ALU is responsible for performing arithmetic (addition, subtraction,
multiplication, division) and logic (AND, OR, NOT, XOR) operations on data.
→ It operates on binary data, manipulating the values stored in the CPU's registers
according to the instructions received from the Control Unit.
→ The ALU produces results of arithmetic and logic operations, which are then stored
back in registers or memory, depending on the instruction's requirements.

3. Memory Unit:

→ Memory Unit is used to store data and instructions. Computer memory is the storage
space in the computer, where data is to be processed and instructions required for
processing are stored.

Memory is primarily of two types –

I. Primary Memory (Main Memory)


Primary memory refers to the main storage area directly accessible by the CPU. It is
volatile, meaning it loses its contents when the power is turned off.
Primary memory is typically used to store data and instructions that the CPU needs to
access quickly during its operation.
The most common type of primary memory is Random Access Memory (RAM), RAM
is characterized by fast access times but relatively limited storage capacity compared
to secondary memory, which comes in various forms such as Dynamic RAM (DRAM)
and Static RAM (SRAM).

II. Secondary Memory (Secondary Storage)


Secondary memory refers to storage devices that provide long-term, non-volatile
storage. It retains data even when the power is turned off, making it suitable for
storing data for extended periods.
Secondary memory devices generally have slower access times compared to primary
memory but offer larger storage capacities and lower cost per byte.
Ex. Hard disk drives (HDDs), solid-state drives (SSDs), optical disks (such as CDs and
DVDs), and magnetic tape.

3. Output Unit:
The output unit, also known as the output device, refers to any hardware component that is
responsible for presenting processed data or information from the computer to the user or
another device.
Output devices convert the electronic signals produced by the computer into a human-readable
or machine-understandable form. These devices play a crucial role in displaying, presenting, or
transmitting
The output unit accepts the information from the CPU and displays it in a user readable form.

Primary memory
1. Primary memory, also known as main memory, is the computer's immediate storage area that the CPU
accesses to store and retrieve data for processing purposes.
2. Primary memory includes Random Access Memory (RAM) and Read-Only Memory (ROM).
3. Primary memory is faster than secondary memory, enabling quick data access for running programs and
processes.
4. Minimal latency in accessing data.
5. Primary memory is volatile in nature.
6. Data stored in it is lost when the computer is turned off or restarted.
7. Primary memory has limited capacity compared to secondary memory, which can impact the number and size
of programs that can run simultaneously.
8. A computer can’t run without primary memory.
9. Generally, more expensive per unit of storage.

Secondary memory
1. Secondary memory refers to storage devices that are used for long-term data storage.
2. Secondary memory includes storage devices like hard drives, solid-state drives, CDs, DVDs, and USB drives.
3. Slower than primary memory.
4. Higher latency in accessing data.
5. Data in secondary memory is non-volatile.
6. data stored in it won’t be erased even when power is off.
7. Secondary memory may have higher memory capacity than primary memory.
8. A computer may run without secondary memory.
9. Generally, it’s cheaper per unit of storage.

What is Software/program?
Software refers to a set of instructions, data, or programs that are used to operate computers and perform specific
tasks.

Software includes applications, scripts, and programs that run on devices, making it the variable part of a computer
while hardware remains the invariable part.

Examples: MS Word, Excel, Photoshop etc.

Operating System:
An operating system is a type of software known as system software.

An operating system (OS) is a type of system software that acts as a middleman between hardware components and
application software. It manages resources like memory, CPU, and storage devices, providing an interface for users to
interact with the computer.

It's the foundation on which other software runs, ensuring efficient use of resources and smooth task execution.
Examples : Linux, Apple macOS, and Microsoft Windows.

What is C Program?
C programs consist of a series of statements written in the C language syntax, which are then compiled into machine-
readable code by a compiler. Once compiled, the program can be executed by the computer to perform the desired
tasks.

Programs in C typically start with a main() function, which serves as the entry point for the program. Within the main()
function and other functions defined by the programmer, various statements and expressions are used to carry out the
desired computations, input/output operations, and other tasks.
C program is called a middle level language because it is codable in c language in high level language; humanly
understandable language, and the compiler in it, compiles the code written in high level language to low level
language; binary language that computer understands.

It acts as a bridge between high level language and low-level language. That’s why it is called middle level language.

Source Code:
Source code refers to the code of a computer program in human-readable form programming language, such as C,
Python, Java, or others.
It consists of instructions and commands written by programmers to specify the desired behavior of a software
application. Source code is typically created using a text editor or Visual Code type of coding software and is saved in
files with specific file extensions corresponding to the programming language used (eg .c for C).

Source code must be translated into machine-executable form through a process called compilation or interpretation
before it can be executed by a computer.

Object Code:
Object code refers to the machine-readable form of a computer program generated by translating the source code
through a compiler or interpreter. It consists of binary code, typically represented as a series of ones and zeros, which
corresponds to specific instructions and data understandable by the computer's processor.

Difference between Source Code and Object Code :

S.
SOURCE CODE OBJECT CODE
No.

Object code is generated by compiler or other


01. Source code is generated by human or programmer.
translator.

02. Source code is high level code. Object code is low level code.

Source code is written in plain text by using some high Object code is translated code of source code.
03.
level programming language. It is in binary format.

04. Source code is human understandable. Object code is not human understandable.

Object code is machine understandable and


05. Source code is not directly understandable by machine.
executable.
S.
SOURCE CODE OBJECT CODE
No.

It is written in a high-level language like C, C++, Java, It is written in machine language through
06.
Python, etc., or assembly language. compiler or assembler or other translator.

07. It can be easily modified. It’s hard to modify.

It contains comments for better understanding by It does not contain comments for
08.
programmer. understanding by machine.

It contains more number of statements than


09. It contains less number of statements than object code.
source code.

Object code is output of compiler or any other


12. Source code is input to compiler or any other translator.
translator.

Language translators like compiler, assembler, interpreter Object code is machine code so it does not
15.
are used to translate source code to object code. require any translation.

Compiler Vs Interpreter:
It is basically a computer program used to convert codes or instructions written in a programming language into
machine code. (human-readable code to a binary 0 and 1 bits language for a computer processor to understand).

1. Execution Process:
• Compiler: Translates the entire source code into machine code before execution.
• Interpreter: Translates and executes the source code line by line, dynamically.
2. Output:
• Compiler: Produces an executable file containing machine code that can be run independently.
• Interpreter: Executes the source code directly without producing a separate executable file.
3. Optimization:
• Compiler: Performs optimization techniques during the translation process to improve performance.
• Interpreter: Does not typically perform optimization as it translates and executes code line by line.
4. Error Handling:
• Compiler: Detects errors in the entire source code during compilation and provides detailed error
messages.
• Interpreter: Halts execution at the first encountered error and provides error messages for that specific
line of code.
5. Memory Usage:
• Compiler: Generally produces smaller executable files as it optimizes code during compilation.
• Interpreter: Requires additional memory to store the interpreter program and the source code being
executed.
6. Execution Speed:
• Compiler: May have faster execution speed once the program is compiled into machine code.
• Interpreter: Tends to have slower execution speed as it translates and executes code line by line.
7. Portability:
• Compiler: The compiled executable may be portable across different platforms.
• Interpreter: The interpreter itself is often less portable, allowing the source code to be executed on
different platforms without recompilation.
8. Debugging:
• Compiler: Debugging can be more challenging as errors are detected during compilation.
• Interpreter: Debugging may be easier as errors are reported in real-time during execution.
9. Resource Usage:
• Compiler: Requires more system resources (such as CPU and memory) during the compilation process.
• Interpreter: Requires resources during execution but less during the initial startup.

Algorithm:
An algorithm refers to a step-by-step procedure or a set of instructions, written in human understandable language for
the representation, of logic for a specified task or operation.
It outlines the logical sequence of actions required to achieve the desired outcome using the syntax and features.
An algorithm is a set of steps

Algorithm helps programmers to write their logic of solving particular problem/program on the paper, verify and
correct if needed. Also, it lets programmers to make their solution effective an efficient.

Properties of Algorithm:

• It should terminate after a finite time.


• It should produce at least one output.
• It should take zero or more input.
• It should be deterministic means giving the same output for the same input case.
• Every step in the algorithm must be effective i.e. every step should do some work.

Keywords in algorithm:
Keywords are predefined or reserved words that have predefined special meanings in the C programming language.
These words are part of the language syntax and cannot be used for other purposes, such as naming variables or
functions.
Keywords are fundamental components of C programming and are used to define the structure, control flow, and
behaviour of programs.

Here are the keywords commonly used in algorithms in C:


1. int: Declares an integer variable.
2. float: Declares a floating-point variable.
3. char: Declares a character type variable or array.
4. if: Starts an if statement.
5. else: Specifies the alternative condition in an if-else statement.
6. for: Starts a for loop.
7. while: Starts a while loop.
8. return: Returns a value from a function.
9. void: Specifies a function that returns no value or a pointer to void.

Algorithm to find the greatest number among three numbers entered by the user:
1. Start
2. Declare three variables num1, num2, and num3 to store the three numbers.
3. Input the values of num1, num2, and num3 from the user.
4. If num1 is greater than or equal to num2 and num1 is greater than or equal to num3, then:
• Output num1 as the greatest number.
5. Else, if num2 is greater than or equal to num1 and num2 is greater than or equal to num3, then:
• Output num2 as the greatest number.
6. Else:
• Output num3 as the greatest number.
7. End

Flow Chart

A flowchart is a graphical representation of an algorithm or a process. It uses different shapes and symbols to represent
different steps or actions in the algorithm, along with arrows indicating the flow of control or data between these
steps. Flowcharts are commonly used to visualize the logic of a program or the sequence of steps in a process.
Flowcharts are usually drawn using some standard symbols as illustrated below:

Draw a flowchart to calculate area and circumference of circle for given radius:

Pseudo Code:

Pseudocode is a simplified and human-readable description of a computer algorithm, written in plain


language with a focus on the logic and flow of the algorithm, rather than specific programming syntax. It
helps programmers plan and understand algorithms before writing actual code.
Here are the advantages of using pseudocode:
1. Language Neutrality: Pseudocode is not tied to any specific programming language, allowing
programmers to express algorithms in a universal way that can be easily translated into any
programming language.

2. Clarity: Pseudocode focuses on the logic and flow of the algorithm, making it easier to identify errors
and understand the overall structure of the solution.

3. Simplicity: Pseudocode uses plain language and simple syntax, making it easy to understand for both
programmers and non-programmers.

4. Ease of Communication: Pseudocode serves as a common language for communicating ideas and
collaborating with other programmers, project stakeholders, and team members.

5. Planning and Design: Pseudocode helps programmers plan and design algorithms before
implementation, allowing for better organization and optimization of code.

6. Flexibility: Pseudocode allows for experimentation and exploration of different algorithmic


approaches without the constraints of a specific programming language syntax.

7. Debugging: Pseudocode can aid in the debugging process by providing a clear and concise
representation of the algorithm, making it easier to identify and fix errors.

Pseudo Code for addition of two numbers:


Loop
A loop in C is a programming construct that allows a based on a condition or a set number of iterations. It
enables the automation of repetitive tasks and simplifies the handling of situations where the same code
needs to be executed multiple times.

A loop in programming refers to a control structure that allows a specific block of code or statements to be
executed repeatedly until a specified condition is valid.

It enables the automation of repetitive tasks and simplifies the handling of situations where the same code
needs to be executed multiple times.

For Loop:

The for loop in C Language provides functionality to repeat a set of statements a defined number of times.
For loop is used in the case where we need to execute some part of the code until the given condition is
satisfied.

It is used if the number of iteration is known in advance.

For loop contains the initialization, condition, and updating statements as part of its syntax.
While Loop:

The While loop in C Language provides functionality to repeat a set of statements a defined number of times.
While loop is used in the case where we need to execute some part of the code until the given condition is
satisfied.

The while loop in c is to be used in the scenario where we don't know the number of iterations in advance.

Unlike the for loop, the while loop does not have an explicit initialization or update section within the loop
syntax. Instead, these operations are typically handled outside the loop.

Do While

Do while is a loop statement used to repeat some part of the code till the given condition is fulfilled. It is a
form of an exit-controlled or post-tested loop where the test condition is checked after executing the body
of the loop.
Due to this, the statements in the do while loop will always be executed at least once no matter what the
condition is.

Key Differences:
• The for loop is used when the number of iterations is known and has a predefined structure.
• The while loop is used when the condition for loop continuation needs to be checked before each
iteration.
• The do-while loop is used when the loop body must be executed at least once, regardless of the
condition, and then the condition is checked for further iterations.
Switch Case Statements

The switch case statement is an alternative to the if else if ladder that can be used to execute the conditional
code based on the value of the variable specified in the switch statement. The switch block consists of cases
to be executed based on the value of the switch variable.

how it works:

• The switch expression is evaluated once


• The value of the expression is compared with the values of each case
• If there is a match, the associated block of code is executed
• The break statement breaks out of the switch block and stops the execution
• The default statement is optional, and specifies some code to run if there is no case match

The break Keyword

Break keyword in switch case statement is used to terminate a loop, when there’s not further testing and
execution of code is needed.
When C reaches a break keyword, it breaks out of the switch block.
When a match is found, this will stop the execution of more code and case testing inside the block.
The continue Keyword

The continue statement works similar to break statement. The only difference is
that break statement terminates the loop whereas continue statement passes control to the conditional test.
When c reaches a continue keyword.
It is used to obtain more values that the value we got.
Used to get multiple results as value.

The default keyword


The code inside default keyword is executed when no case is matched with the given expression.

Leap Year Program using conditional statements.


Greatest number among three
Variable:
A variable is a name of a memory location that is used to store data.
It is a way to represent memory location through identifier so that it can be easily identified.
(This identifier follows certain rules, such as starting with a letter or underscore, and can include letters,
digits, and underscores. The choice of identifier should be meaningful and descriptive to convey the purpose
or nature of the data stored in the variable.)
Top of Form

Its value can be changed, and it can be reused many times.


The example of declaring the variable is given below:
1. int a;
2. float b;
3. char c;
Here, a, b, c are variables. The int, float, char are the data types

DataTypes

A data type in C programming denotes the type of data that a variable can hold.
It defines the format and size of the data that can be stored within a variable.

For instance, an integer data type can store whole numbers, while a floating-point data type can store
numbers with decimal points.
Each data type has its own characteristics and usage, such as integers for whole numbers, floating-point for
decimal numbers, and character for individual characters like letters or symbols.

The choice of data type determines the range of values a variable can hold and the operations that can be
performed on it.
Operators

Operators in C are symbols that


represent operations to be
performed on operands. They are
used to manipulate data and
perform various computations in
expressions.
An operator is a symbol that
represents operations to be
perform certain mathematical or
logical manipulations.
Control Statements:
Control statements in C are programming constructs that are used to control the flow of execution in a
program.
These statements are used to determine the order, in which instructions are executed, making decisions
based on specific conditions, controlling program flow, repeating actions.
Syntax and Logical Errors
1. Syntax Error:
• Definition: Syntax errors occur due to violations of the language's grammatical rules or syntax.
• Cause: These errors arise from misspelled keywords, missing semicolons, incorrect use of
operators, or improper structure.
• Identification: The compiler detects syntax errors during the compilation phase and displays
error messages, preventing successful compilation of the code.
• Impact: Syntax errors prevent the program from being executed until they are fixed. They
hinder the translation of source code into machine-readable instructions.
• Example: Forgetting to include a closing parenthesis in a function call or using an undefined
variable name.
2. Logical Error:
• Definition: Logical errors occur when the program produces unintended or incorrect results
due to flawed logic or algorithmic errors.
• Cause: These errors stem from mistakes in the design or implementation of the program's
logic, leading to incorrect calculations, decisions, or behaviors.
• Identification: Logical errors may not be detected by the compiler or produce error messages.
They often manifest as unexpected program behavior during runtime.
• Impact: Logical errors may result in incorrect program output or undesired behavior, such as
infinite loops or incorrect calculations.
• Example: Incorrect condition in an if statement leading to incorrect branching, incorrect
algorithm implementation resulting in incorrect output.

You might also like