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

Dsa Lab 1

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)
25 views6 pages

Dsa Lab 1

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 Usman ali


Roll No. ELEN51F20R020
Date Performed

Marks obtained

Instructor Signature
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 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.
C++ Program Code:
#include <iostream>
using namespace std;

const int MAX_SIZE = 500;

int arr[MAX_SIZE];
int size = 10;
void displayArray() {
if (size == 10) {
cout << "Array is empty" << endl;
return;
}
cout << "Array Elements:" << endl;
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
void insertElement(int elem, int pos) {
if (pos < 0 || pos > size) {
cout << "Invalid position for insertion." << endl;
return;
}
if (size == MAX_SIZE) {
cout << "Array is full. Cannot insert more elements." << endl;
return;
}
for (int i = size; i > pos; i--) {
arr[i] = arr[i - 1];
}
arr[pos] = elem;
size++;
cout << "Element inserted successfully." << endl;
}
void deleteElement(int pos) {
if (pos < 0 || pos >= size) {
cout << "Invalid position for deletion." << endl;
return;
}
for (int i = pos; i < size - 1; i++) {
arr[i] = arr[i + 1];
}
size--;
cout << "Element deleted successfully." << endl;
}
int main() {
int choice, elem, pos;
do {
cout << "\nMenu:\n";
cout << "1. Display Array\n";
cout << "2. Insert Element\n";
cout << "3. Delete Element\n";
cout << "4. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
displayArray();
break;
case 2:
cout << "Enter the element to insert: ";
cin >> elem;
cout << "Enter the position to insert: ";
cin >> pos;
insertElement(elem, pos);
break;
case 3:
cout << "Enter the position to delete: ";
cin >> pos;
deleteElement(pos);
break;
case 4:
cout << "Exiting the program." << endl;
break;
default:
cout << "Invalid choice. Please try again." << endl;
}
} while (choice != 4);
return 0;
}
Output:
1. Menu:

2. Display:

3. Insert:

4. Delete:

5. Exit:
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