Professional Documents
Culture Documents
UNIVERSITY OF SARGODHA
Lab 1 Manual
Introduction to Arrays
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
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 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.
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.
Total