Assignment Overview
Build a Math Utility Library that demonstrates mastery of functions, pointers, memory management, and references. Your library will provide array operations, statistical functions, and dynamic memory utilities.
Functions (3.1)
Declaration, definition, overloading
Pointers (3.2)
Pointer operations, arrays
Memory (3.3)
new, delete, dynamic arrays
References (3.4)
Pass by reference, const ref
The Scenario
DataCrunch Analytics
You're a developer at DataCrunch Analytics. The team needs a reusable C++ library for numerical computations. Your task is to build the core utility functions.
"We need functions for array statistics, dynamic array management, and matrix operations. The library must be efficient - use pointers where appropriate and avoid memory leaks!"
Requirements
Header File (mathlib.h)
Create function declarations with proper prototypes:
// Array Statistics
double findMin(const double* arr, int size);
double findMax(const double* arr, int size);
double calculateMean(const double* arr, int size);
double calculateMedian(double* arr, int size);
double calculateStdDev(const double* arr, int size);
// Dynamic Array Functions
double* createArray(int size);
void resizeArray(double*& arr, int oldSize, int newSize);
void deleteArray(double*& arr);
// Swap and Sort (using references)
void swap(double& a, double& b);
void bubbleSort(double* arr, int size);
void selectionSort(double* arr, int size);
Implementation File (mathlib.cpp)
Implement all functions using pointers and pointer arithmetic where appropriate.
Dynamic Memory Management
createArray()- allocate withnewresizeArray()- create new, copy, delete olddeleteArray()- free memory and set pointer to nullptr- No memory leaks allowed!
Main Program (main.cpp)
Demonstrate all library functions with test cases and formatted output.
Function Overloading
Provide overloaded versions of findMin and findMax for int arrays.
Submission
Required Repository Name
cpp-math-library
cpp-math-library/
├── mathlib.h # Header file with declarations
├── mathlib.cpp # Implementation file
├── main.cpp # Test program
├── sample_output.txt # Sample output
└── README.md # Documentation
Grading Rubric
| Criteria | Points |
|---|---|
| Header File Structure | 20 |
| Statistical Functions | 40 |
| Dynamic Memory Functions | 40 |
| Sorting Functions | 30 |
| Function Overloading | 20 |
| No Memory Leaks | 30 |
| Code Quality & Documentation | 20 |
| Total | 200 |