Add containers project with CMake setup and array-related functionality
- Implement `printArrayAtPosition` in `functions.cpp` with input validation. - Created `main.cpp` to demonstrate array operations using C arrays and `std::vector`. - Updated `ClassA` and `IComparable` with constructors, destructors, and deep copy logic. - Adjusted IntelliJ project configuration for new containers module.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "functions.h"
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
// C array
|
||||
int numbers[5] = {1, 2, 3, 4, 5}; // stack array
|
||||
const int count = 10;
|
||||
int numbers2[count];
|
||||
|
||||
int count2 = 10;
|
||||
int* numbers3 = new int[count2]; // heap array
|
||||
delete[] numbers3;
|
||||
numbers3 = nullptr;
|
||||
|
||||
// numbers[10] = 100;
|
||||
std::cout << "size of numbers: " << sizeof(numbers) << std::endl;
|
||||
|
||||
printArrayAtPosition(numbers, 19);
|
||||
|
||||
// vector
|
||||
std::vector<int> v = {1, 2, 3, 4, 5};
|
||||
|
||||
std::cout << "size of v: " << v.size() << "/" << v.capacity() << std::endl;
|
||||
|
||||
v.push_back(6);
|
||||
|
||||
std::cout << "size of v: " << v.size() << "/" << v.capacity() << std::endl;
|
||||
|
||||
// v[20] = 100;
|
||||
printArrayAtPosition(v.data(), 2);
|
||||
|
||||
v.pop_back();
|
||||
|
||||
std::cout << "size of v: " << v.size() << "/" << v.capacity() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user