-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.cpp
More file actions
51 lines (41 loc) · 1.05 KB
/
array.cpp
File metadata and controls
51 lines (41 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
using namespace std;
const int MAX_SIZE = 100;
class StaticList {
private:
int data[MAX_SIZE];
int size;
public:
// Constructor to initialize the list
StaticList() {
size = 0;
}
// Function to add an element to the list
void addElement(int element) {
if (size < MAX_SIZE) {
data[size] = element;
size++;
} else {
cout << "List is full. Cannot add more elements.\n";
}
}
// Function to display the elements of the list
void displayList() const {
cout << "Elements of the list: ";
for (int i = 0; i < size; i++) {
cout << data[i] << " ";
}
cout << endl;
}
};
int main() {
// Create an object of the StaticList class
StaticList myList;
// Add elements to the list
myList.addElement(10);
myList.addElement(20);
myList.addElement(30);
// Display the elements of the list
myList.displayList();
return 0;
}