Lab#1 (DSA)
Lab#1 (DSA)
Lab # 1 (Task)
Subject Title: DSA Course code:
Semester: BS (CS & SE) 3rd Department: CS &SE
Objective: To understand and implement the functionality of an array in DSA using basic logic of OOP.
Topic: Arrays
Array:
1. Structure: An array is a collection of items stored at contiguous memory locations.
2. Types: Can store multiple items of the same or different data type.
6. Use Case: Ideal for situations where you need to store a fixed-size sequential collection of eleme
nts.
Types:
1-Dimensional Array:
Structure: A list of elements in a single line.
Example: [1, 2, 3, 4, 5]
Usage: Useful for storing simple lists like a list of numbers or strings.
Implementation:
#include<iostream>
Using namespace std;
Class A {
public:
void take(){
PMAS-Arid Agriculture University, Rawalpindi.
Gujrat Institute of Management Sciences
int array[2];
for(int i=0;i<5;i++)
cin>>array[i];
}}};
int main(){
A a;
a.task();
}
2-Dimensional Array:
Structure: An array of arrays, forming a grid or table.
Example: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
3-Dimensional Array:
Structure: An array of 2D arrays, forming a cube-like structure.
Example: [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
Usage: Useful for complex data structures like 3D matrices, or for representing multiple layers of
2D grids.
Implementation:
#include<iostream>
class car{
public:
PMAS-Arid Agriculture University, Rawalpindi.
Gujrat Institute of Management Sciences
void function() {
int arr[2][2][2];
cin>>arr[i][j][k];
} } }} };
int main() {
car d;
d.function();