PPS Lab Manual - 2024
PPS Lab Manual - 2024
B.E. Semester 1
Computer Engineering
Place: __________
Date: __________
By using this lab manual students can go through the relevant theory and procedure
in advance before the actual performance which creates an interest and students can
have basic idea prior to performance. This in turn enhances pre-determined outcomes
amongst students. Each experiment in this manual begins with competency, industry
relevant skills, course outcomes as well as practical outcomes (objectives). The
students will also achieve safety and necessary precautions to be taken while
performing practical.
This manual also provides guidelines to faculty members to facilitate student centric
lab activities through each experiment by arranging and managing necessary
resources in order that the students follow the procedures with required safety and
necessary precautions to achieve the outcomes. It also gives an idea that how
students will be assessed by providing rubrics.
Utmost care has been taken while preparing this lab manual however always there is
chances of improvement. Therefore, we welcome constructive suggestions for
improvement and removal of errors if any.
i) * ii) * iii) * * *
** * * **
*** * * * *
Vision:
To provide globally competitive technical education
Remove geographical imbalances and inconsistencies
Develop student friendly resources with a special focus on girls’ education and support
to
weaker sections
Develop programs relevant to industry and create a vibrant pool of technical
professionals
Vision:
To be a premier engineering institution, imparting quality education for innovative
solutions relevant to society and environment.
Mission:
To develop human potential to its fullest extent so that intellectual and innovative
engineers can emerge in a wide range of professions.
To advance knowledge and educate students in engineering and other areas of
scholarship that will best serve the nation and the world in future.
To produce quality engineers, entrepreneurs and leaders to meet the present and future
needs of society as well as environment.
Vision and Mission of Computer Department:
Vision:
To achieve excellence for providing value-based education in Computer Engineering
through innovation, team work and ethical practices
Mission:
To produce computer science and engineering graduates according to the needs of
industry, government, society and scientific community.
To develop partnership with industries, government agencies and R and D
Organizations
To motivate students/graduates to be entrepreneurs.
To motivate students to participate in reputed conferences, workshops, symposiums,
seminars and related technical activities
5. Modern tool usage: Create, select, and apply appropriate techniques,resources, and
modern engineering and IT tools including prediction and modeling to complex engineering
activities with an understanding of the limitations.
8. Ethics: Apply ethical principles and commit to professional ethics andresponsibilities and
norms of the engineering practice.
12. Life-long learning: Recognize the need for, and have the preparation and abilityto engage
in independent and life-long learning in the broadest context of technological change.
• Design, develop, test and evaluate computer based systems by applying standard software
engineering practices and strategies in the area of algorithms, web design, data structure, and
computer network
• To prepare the students for a successful career and work with values and social concern
bridging the digital divide and meeting the requirements of Indian and multinational companies.
Terminal Symbol: In the flowchart, it is represented with the help of a circle for denoting the
start and stop symbol. The symbol given below is used to represent the terminal symbol.
Input/output Symbol: The input symbol is used to represent the input data, and the output symbol
is used to display the output operation.
Processing Symbol: It is represented in a flowchart with the help of a rectangle box used to
represent the arithmetic and data movement instructions. The symbol given below is used to
represent the processing symbol.
Connector Symbol: The connector symbol is used if flows discontinued at some point and
continued again at another place. The following symbol is the representation of the connector
symbol.
Flow lines: It represents the exact sequence in which instructions are executed. Arrows are used
to represent the flow lines in a flowchart. The symbol given below is used for representing the
flow lines:
Internal storage symbol: The symbol given below is used to represent the internal storage
symbol.
Advantages of Flowchart in C:
Following are the various advantages of flowchart:
Communication: A flowchart is a better way of communicating the logic of a program.
Synthesis: Flowchart is used as working models in designing new programs and software
systems.
Efficient Coding: Flowcharts act as a guide for a programmer in writing the actual code in a
high-level language.
Proper Debugging: Flowcharts help in the debugging process.
Effective Analysis: Effective analysis of logical programs can be easily done with the help of a
related flowchart.
Proper Documentation: Flowchart provides better and proper documentation. It consists of
various activities such as collecting, organizing, storing, and maintaining all related program
records.
Testing: A flowchart helps in the testing process
Student Name [Enrollment Number] Page 18 of 82
Examples of flowchart
Draw a flowchart for finding average of 3 Numbers.
Good Average Good Average Good Satisfactory Good Satisfactory Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks
Good Average Good Average Good Satisfactory Good Satisfactory Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks
the desktop icon: by double clicking it. The below window will be visible soon.
Practical-3
Good Average Good Average Good Satisfactory Good Satisfactory Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks
Good Average Good Average Good Satisfactory Good Satisfactory Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks
Output:
IF-ELSE Statement:
The if-else is statement is an extended version of If. The general form of if-else is as follows:
if (test-expression)
{
True block of statements
}
Else
{
The general syntax of how else-if ladders are constructed in ‘C’ programming is as follows:
if (test - expression 1)
{
statement1;
}
else if (test - expression 2)
{
Statement2;
}
else if (test - expression 3)
{
Statement3;
}
else if (test - expression n)
{
Statement n;
}
else
{
default;
}
Statement x;
This type of structure is known as the else-if ladder. This chain generally looks like a ladder
hence it is also called as an else-if ladder. The test-expressions are evaluated from top to bottom.
Whenever a true test-expression if found, statement associated with it is executed. When all the n
test-expressions becomes false, then the default else statement is executed.
Good Average Good Average Good Satisfactory Good Satisfactory Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks
The switch statement allows us to execute one code block among many alternatives.
You can do the same thing with the if...else..if ladder. However, the syntax of the switch
statement is much easier to read and write.
switch (expression)
case constant1:
// statements
break;
case constant2:
// statements
break;
default:
// default statements
The expression is evaluated once and compared with the values of each case label.
If there is a match, the corresponding statements after the matching label are executed. For
example, if the value of the expression is equal to constant2, statements after case constant2: are
executed until break is encountered.
If there is no match, the default statements are executed.
Loops in programming are used to repeat a block of code until the specified condition is met. A
loop statement allows programmers to execute a statement or group of statements multiple times
without repetition of code.
Student Name [Enrollment Number] Page 51 of 82
There are mainly two types of loops in C Programming:
Entry Controlled loops: In Entry controlled loops the test condition is checked before entering
the main body of the loop. For Loop and While Loop is Entry-controlled loops.
Exit Controlled loops: In Exit controlled loops the test condition is evaluated at the end of the
loop body. The loop body will execute at least once, irrespective of whether the condition is true
or false. do-while Loop is Exit Controlled loop.
do-while loop in C
The do-while loop continues until a given condition satisfies. It is also called post tested loop. It
is used when it is necessary to execute the loop at least once (mostly menu driven programs).
do {
//code to be executed
} while (condition);
The while loop in c is to be used in the scenario where we don't know the number of iterations in
advance. The block of statements is executed in the while loop until the condition specified in
the while loop is satisfied. It is also called a pre-tested loop.
while(condition){
//code to be executed
For Loop in C
The for loop in C language is used to iterate the statements or a part of the program several
times. It is frequently used to traverse the data structures like the array and linked list.
Syntax:
//
Good Average Good Average Good Satisfactory Good Satisfactory Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks
In C, we can divide a large program into the basic building blocks known as function. The
function contains the set of programming statements enclosed by {}. A function can be called
multiple times to provide reusability and modularity to the C program. In other words, we can
say that the collection of functions creates a program. The function is also known as procedureor
subroutinein other programming languages.
Advantage of functions in C
By using functions, we can avoid rewriting same logic/code again and again in a
program.
We can call C functions any number of times in a program and from any place in a
program.
We can track a large C program easily when it is divided into multiple functions.
Reusability is the main achievement of C functions.
However, Function calling is always a overhead in a C program.
Function Aspects
Function declaration A function must be declared globally in a c program to tell the compiler
about the function name, function parameters, and return type.
Function call Function can be called from anywhere in the program. The parameter list must not
differ in function calling and function declaration. We must pass the same number of functions
as it is declared in the function declaration.
Function definition It contains the actual statements which are to be executed. It is the most
important aspect to which the control comes when the function is called. Here, we must notice
that only one value can be returned from the function.
Types of Functions
User-defined functions: are the functions which are created by the C programmer, so that
he/she can use it many times. It reduces the complexity of a big program and optimizes the code.
Return Value
A C function may or may not return a value from the function. If you don't have to return any
value from the function, use void for the return type.
Let's see a simple example of C function that doesn't return any value from the function.
void hello(){
printf("hello c");
If you want to return any value from the function, you need to use any data type such as int, long,
char, etc. The return type depends on the value to be returned from the function.
Let's see a simple example of C function that returns int value from the function.
int get(){
return 10;
In the above example, we have to return 10 as a value, so the return type is int. If you want to
return floating-point value (e.g., 10.2, 3.1, 54.5, etc), you need to use float as the return type of
the method.
A function may or may not accept any argument. It may or may not return any value. Based on
these facts, There are four different aspects of function calls.
There are two methods to pass the data into the function in C language, i.e., call by value and call
by reference.
There are two methods to pass the data into the function in C language, i.e., call by value and call
by reference.
Call by value in C
In call by value method, the value of the actual parameters is copied into the formal
parameters. In other words, we can say that the value of the variable is used in the
function call in the call by value method.
In call by value method, we can not modify the value of the actual parameter by the
formal parameter.
In call by value, different memory is allocated for actual and formal parameters since the
value of the actual parameter is copied into the formal parameter.
Student Name [Enrollment Number] Page 60 of 82
The actual parameter is the argument which is used in the function call whereas formal
parameter is the argument which is used in the function definition.
Call by reference in C
In call by reference, the address of the variable is passed into the function call as the
actual parameter.
The value of the actual parameters can be modified by changing the formal parameters
since the address of the actual parameters is passed.
In call by reference, the memory allocation is similar for both formal parameters and
actual parameters. All the operations in the function are performed on the value stored at
the address of the actual parameters, and the modified value gets stored at the same
address.
Good Average Good Average Good Satisfactory Good Satisfactory Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks
Good Average Good Average Good Satisfactory Good Satisfactory Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks
Arrays are used to store multiple values in a single variable, instead of declaring separate
variables for each value. To create an array, define the data type (like int) and specify the name
of the array followed by square brackets []. To insert values to it, use a comma-separated list,
inside curly braces:
To access an array element, refer to its index number. Array indexes start with 0: [0] is the first
element. [1] is the second element, etc.
This statement accesses the value of the first element [0] in myNumbers:
Example
printf("%d", myNumbers[0]);
// Outputs 25
Advantage of C Array
2) Ease of traversing: By using the for loop, we can retrieve the elements of an array easily.
3) Ease of sorting: To sort the elements of the array, we need a few lines of code only.
4) Random Access: We can access any element randomly using the array.
1) Fixed Size: Whatever size, we define at the time of declaration of the array, we can't
exceed the limit. So, it doesn't grow the size dynamically like LinkedList which we will
learn later.
The two-dimensional array can be defined as an array of arrays. The 2D array is organized as
matrices which can be represented as the collection of rows and columns. However, 2D arrays
are created to implement a relational database lookalike data structure. It provides ease of
holding the bulk of data at once which can be passed to any number of functions wherever
required.
data_type array_name[rows][columns];
C Pointers
The pointer in C language is a variable which stores the address of another variable. This
variable can be of type int, char, array, function, or any other pointer. The size of the pointer
depends on the architecture. However, in 32-bit architecture the size of a pointer is 2 byte.
Consider the following example to define a pointer which stores the address of an integer.
int n = 10;
int* p = &n;
Declaring a pointer
The pointer in c language can be declared using * (asterisk symbol). It is also known as
indirection pointer used to dereference a pointer.
Pointer to array
int arr[10];
int *p[10]=&arr;
Student Name [Enrollment Number] Page 69 of 82
Pointer to a function
void(*p)(int) = &display;
Pointer to structure
struct st {
int i;
float f;
}ref;
struct st *p = &ref;
Advantage of pointer
1) Pointer reduces the code and improves the performance, it is used to retrieving strings, trees,
etc. and used with arrays, structures, and functions.
3) It makes you able to access any memory location in the computer's memory.
Usage of pointer
In c language, we can dynamically allocate memory using malloc() and calloc() functions where
the pointer is used.
Pointers in c language are widely used in arrays, functions, and structures. It reduces the code
and improves the performance.
The address of operator '&' returns the address of a variable. But, we need to use %u to display
the address of a variable.
In C, there are cases where we need to store multiple attributes of an entity. It is not necessary
that an entity has all the information of one type only. It can have different attributes of different
data types. For example, an entity Student may have its name (string), roll number (int), marks
(float). To store such type of information regarding an entity student, we have the following
approaches:
Construct individual arrays for storing names, roll numbers, and marks.
Use a special data structure to store the collection of different data types.
What is Structure
Structure in c is a user-defined data type that enables us to store the collection of different data
types. Each element of a structure is called a member. Structures ca; simulate the use of classes
and templates as it can store various information The ,struct keyword is used to define the
structure. Let's see the syntax to define the structure in c.
struct structure_name
data_type member1;
data_type member2;
data_type memeberN;
};
struct employee
{ int id;
char name[20];
float salary;
};
Student Name [Enrollment Number] Page 71 of 82
Declaring structure variable
We can declare a variable for the structure so that we can access the member of the structure
easily. There are two ways to declare structure variable:
1st way:
Let's see the example to declare the structure variable by struct keyword. It should be declared
within the main function.
struct employee
{ int id;
char name[50];
float salary;
};
The variables e1 and e2 can be used to access the values stored in the structure. Here, e1 and e2
can be treated in the same way as the objects in C++ and Java.
2nd way:
Let's see another way to declare variable at the time of defining the structure.
struct employee
int id;
char name[50];
float salary;
}e1,e2;
Let's see the code to access the id member of p1 variable by. (member) operator.
p1.id
C Structure example
#include<stdio.h>
#include <string.h>
struct employee
{ int id;
char name[50];
int main( )
e1.id=101;
return 0;
In programming, we may require some specific input data to be generated several numbers of
times. Sometimes, it is not enough to only display the data on the console. The data to be
displayed may be very large, and only a limited amount of data can be displayed on the console,
and since the memory is volatile, it is impossible to recover the programmatically generated data
again and again. However, if we need to do so, we may store it onto the local file system which
is volatile and can be accessed every time. Here, comes the need of file handling in C.
File handling in C enables us to create, update, read, and delete the files stored on the local file
system through our C program. The following operations can be performed on a file.
There are many functions in the C library to open, read, write, search and close the file. A list of
file functions are given below:
We must open a file before it can be read, write, or update. The fopen() function is used to open
a file. The syntax of the fopen() is given below.
The file name (string). If the file is stored at some specific location, then we must mention the
path at which the file is stored. For example, a file name can be like
"c://some_folder/some_file.ext".
The mode in which the file is to be opened. It is a string. We can use one of the following modes
in the fopen() function.
Mode Description
Good Average Good Average Good Satisfactory Good Satisfactory Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks
AIM: Write a C Program using the concept of pointer, structure & File.
(a) Write a program to access elements using pointer.
(b) Design a structure student_record to contain name, branch and total
marks obtained. Develop a program to read data for 10 students in a class and
print them.
(c) A file named data contains series of integer numbers. Write a c program
to read all numbers from file and then write all odd numbers into file named
“odd” and write all even numbers into file named “even”. Display all the
contents of these file on screen
Good Average Good Average Good Satisfactory Good Satisfactory Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks