0% found this document useful (0 votes)
30 views6 pages

DSA Lab 1

The document outlines a lab experiment on arrays in C programming, including creating an array of integers, inserting and deleting elements, and displaying the array. It provides the objectives, algorithm, Python code for array operations, and an assessment rubric for the lab. The code implements functions for displaying, inserting, and deleting elements from an integer array of size 500.

Uploaded by

obaid ur rehman
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)
30 views6 pages

DSA Lab 1

The document outlines a lab experiment on arrays in C programming, including creating an array of integers, inserting and deleting elements, and displaying the array. It provides the objectives, algorithm, Python code for array operations, and an assessment rubric for the lab. The code implements functions for displaying, inserting, and deleting elements from an integer array of size 500.

Uploaded by

obaid ur rehman
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/ 6

COLLEGE OF ENGINEERING & TECHNOLOGY

UNIVERSITY OF SARGODHA

CE 416: Data Structures and Algorithms (Lab)

Lab 1 Manual
Introduction to Arrays

Instructor & Demonstrator: Engr. Nauman Ahmad Tariq

Student Name OBAID UR REHMAN

Roll No. ELEN51F20R010

Date Performed

Marks obtained

Instructor Signature
CLO-1 Illustrate understanding of key concepts of Data structures
and Algorithms using Python PyCharm Platform
CLO-2 Design a programming application by applying concepts of
Data Structures and algorithms leading to the solution of a moderate
scale-programming problem.
CLO-3 Write lab notes, effective communication and the analysis of
the given problem to perform in the laboratory environment.
CLO-4 Demonstrate involvement in the Project as a team or
individually with respect to the contribution.

OBJECTIVE:
Design, Develop and Implement a menu driven program in C for the following Array
operations
a. Creating Array of N Integer elements.
b. Display of Array elements with suitable headings.
c. Inserting an element (ELEM) at a given valid position (POS).
d. Deleting an element at a given valid position (POS).
e. Exit.
Support the program with functions for each of the above operations

About the Experiment


An Array is a collection of similar / same elements. In this experiment the array can be
represented as one / single dimensional elements.
Menu driven program in c - language to perform various array operations are implemented
with the help of user defined functions as followings;
a. create()
b. display()
c. insert()
d. del()
e. exit()

Algorithm:

Step 1: Start.
Step 2: Read N value.
Step 3: Read Array of N integer elements
Step 4: Print array of N integer elements.
Step 5: Insert an element at given valid position in an array.
Step 6: Delete an element at given valid position from an array.
Step 7: Stop
Python Program Code:

MAX_SIZE = 500
arr = [0] * MAX_SIZE
size = 10

def displayArray():
global size
if size == 0:
print("Array is empty")
return
print("Array Elements:")
for i in range(size):
print(arr[i], end=" ")
print()

def insertElement(elem, pos):


global size
if pos < 0 or pos > size:
print("Invalid position for insertion.")
return
if size == MAX_SIZE:
print("Array is full. Cannot insert more elements.")
return
for i in range(size, pos, -1):
arr[i] = arr[i - 1]
arr[pos] = elem
size += 1
print("Element inserted successfully.")

def deleteElement(pos):
global size
if pos < 0 or pos >= size:
print("Invalid position for deletion.")
return
for i in range(pos, size - 1):
arr[i] = arr[i + 1]
size -= 1
print("Element deleted successfully.")

def main():
global size
while True:
print("\nMenu:")
print("1. Display Array")
print("2. Insert Element")
print("3. Delete Element")
print("4. Exit")
choice = int(input("Enter your choice: "))

if choice == 1:
displayArray()
elif choice == 2:
elem = int(input("Enter the element to insert: "))
pos = int(input("Enter the position to insert: "))
insertElement(elem, pos)
elif choice == 3:
pos = int(input("Enter the position to delete: "))
deleteElement(pos)
elif choice == 4:
print("Exiting the program.")
break
else:
print("Invalid choice. Please try again.")

if __name__ == "__main__":
main()

Output:

D:\Movies\Python\python.exe D:\Movies\Python\Pycharm\DSALAb1.py

Menu:
1. Display Array
2. Insert Element
3. Delete Element
4. Exit
Enter your choice: 1
Array Elements:
0000000000

Menu:
1. Display Array
2. Insert Element
3. Delete Element
4. Exit
Enter your choice: 2
Enter the element to insert: 3
Enter the position to insert: 5
Element inserted successfully.

Menu:
1. Display Array
2. Insert Element
3. Delete Element
4. Exit
Enter your choice: 3
Enter the position to delete: 5
Element deleted successfully.

Menu:
1. Display Array
2. Insert Element
3. Delete Element
4. Exit
Enter your choice: 4
Exiting the program.

Process finished with exit code 0


Assessment Rubric for Lab 1
Method of Evaluation: Lab report.

Outcomes Assessed:

CLO-1 Illustrate understanding of key concepts of Data structures and Algorithms using Dev
C++ Platform.
CLO-2 Design a programming application by applying concepts of Data Structures and
algorithms leading to the solution of a moderate scale-programming problem.
CLO-3 Write lab notes, effective communication and analysis of the given problem to perform
in the laboratory environment.
CLO-4 Demonstrate involvement in the Project as a team or individually with respect to the
contribution.

Performance 5 Excellent 4 Good 3 Satisfactory 2-1 Needs Marks


Improvement
Realization of Fully understand & Close to fully Partially Unable to
Experiment able to illustrate understand & able understands & able understand & able
CLO-1 Arrays to illustrate Arrays to illustrate Arrays to illustrate Arrays

Conducting Completely able to Close to Partially able to Unable to


Experiment successfully completely able to successfully successfully
CLO-2 design and compile successfully design and compile design and compile
C++ programs design and compile C++ programs C++ programs
using Arrays. C++ programs using Arrays. using Arrays.
using Arrays.
Data Collection Completely Close to Partially Unable to
and Data Analysis understand & able completely understand & able understand & able
CLO-3 to demonstrate understand & able to demonstrate to demonstrate
syntax of Arrays to demonstrate syntax of Arrays syntax of Arrays
syntax of Arrays

Individual/Team Completely able to Close to Partially able to Unable to execute


Work execute different completely able to execute different different programs
CLO-4 programs based on execute different programs based on based on Arrays.
Arrays. programs based on Arrays.
Arrays.

Total

You might also like