[go: up one dir, main page]

0% found this document useful (0 votes)
19 views3 pages

Lab#1 (DSA)

Tas

Uploaded by

laibaahir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Lab#1 (DSA)

Tas

Uploaded by

laibaahir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PMAS-Arid Agriculture University, Rawalpindi.

Gujrat Institute of Management Sciences

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

Task: Implement 1D, 3D arrays using OOP.

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.

3. Indexing: Accessed via indices, starting from zero.

4. Fixed Size: The size of an array is defined at the time of declaration.

5. Efficient Access: Provides efficient random access to elements.

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]]

 Usage: Great for representing matrices, grids, or tables.

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>

using namespace std;

class car{

public:
PMAS-Arid Agriculture University, Rawalpindi.
Gujrat Institute of Management Sciences

void function() {

int arr[2][2][2];

for (int i=0;i<2;i++) {

for (int j=0;j<2;j++) {

for (int k=0;k<2;k++) {

cin>>arr[i][j][k];

} } }} };

int main() {

car d;

d.function();

You might also like