add lab3 solution

This commit is contained in:
2025-02-12 12:09:42 -05:00
parent b469d0a85d
commit edb1a007c0
2 changed files with 13 additions and 8 deletions

View File

@@ -20,6 +20,6 @@ double compute_slope(const Point &a, const Point &b) {
double run_x = b.get_x() - a.get_x(); double run_x = b.get_x() - a.get_x();
double run_z = b.get_z() - a.get_z(); double run_z = b.get_z() - a.get_z();
double run = sqrt(run_x*run_x + run_z*run_z); double run = sqrt(run_x*run_x + run_z*run_z);
//double answer = rise / run; double answer = rise / run;
return rise / run; return rise / run;
} }

View File

@@ -44,10 +44,10 @@ void identifyMeanAndMin(const std::string& filename) {
float* avg; float* avg;
/** PART 1: ADD CODE BELOW **/ /** PART 1: ADD CODE BELOW **/
numElements = new int;
sum = new int;
smallestNum = new int;
avg = new float;
/** PART 1: ADD CODE ABOVE **/ /** PART 1: ADD CODE ABOVE **/
*numElements = 0; *numElements = 0;
@@ -66,10 +66,11 @@ void identifyMeanAndMin(const std::string& filename) {
/** PART 2: MODIFY CODE BELOW **/ /** PART 2: MODIFY CODE BELOW **/
for (int i = MAX_ARRAY_SIZE; i >= -1; i--) { for (int i = *numElements - 1; i >= 0; i--) {
// If we're at the beginning of the for loop, initalize *smallestNum // If we're at the beginning of the for loop, initalize *smallestNum
// Else, compare *smallestNum to current element in the for loop // Else, compare *smallestNum to current element in the for loop
if (i == MAX_ARRAY_SIZE) {
if (i == *numElements - 1) {
*smallestNum = *(intArray + i); *smallestNum = *(intArray + i);
} }
@@ -98,7 +99,11 @@ void identifyMeanAndMin(const std::string& filename) {
/** PART 3: ADD AND/OR MODIFY CODE BELOW **/ /** PART 3: ADD AND/OR MODIFY CODE BELOW **/
delete intArray; delete[] intArray;
delete numElements;
delete sum;
delete avg;
delete smallestNum;
/** PART 3: ADD AND/OR MODIFY CODE ABOVE **/ /** PART 3: ADD AND/OR MODIFY CODE ABOVE **/
} }