Assignment 3-A

Function Library Project

Create a comprehensive math utility library demonstrating functions, pointers, dynamic memory allocation, and references with proper memory management.

5-6 hours
Intermediate
200 Points
Submit Assignment
What You'll Practice
  • Function declarations & definitions
  • Pointers and pointer arithmetic
  • Dynamic memory (new/delete)
  • References and pass-by-reference
  • Header files and modular code
Contents
01

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

02

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!"

03

Requirements

1
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);
2
Implementation File (mathlib.cpp)

Implement all functions using pointers and pointer arithmetic where appropriate.

3
Dynamic Memory Management
  • createArray() - allocate with new
  • resizeArray() - create new, copy, delete old
  • deleteArray() - free memory and set pointer to nullptr
  • No memory leaks allowed!
4
Main Program (main.cpp)

Demonstrate all library functions with test cases and formatted output.

5
Function Overloading

Provide overloaded versions of findMin and findMax for int arrays.

04

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
05

Grading Rubric

CriteriaPoints
Header File Structure20
Statistical Functions40
Dynamic Memory Functions40
Sorting Functions30
Function Overloading20
No Memory Leaks30
Code Quality & Documentation20
Total200