Update MP2
parent
92d6102039
commit
ec700702c8
@ -0,0 +1,142 @@
|
|||||||
|
//
|
||||||
|
// Created by caleb on 3/6/24.
|
||||||
|
//
|
||||||
|
#import <iostream>
|
||||||
|
#import <vector>
|
||||||
|
#include <exception>
|
||||||
|
#include <climits>
|
||||||
|
|
||||||
|
class OutOfBoundsException: public std::exception {
|
||||||
|
virtual const char* what() const throw()
|
||||||
|
{
|
||||||
|
return "Method attempted to call a vector location that was larger than the vector itself.";
|
||||||
|
}
|
||||||
|
} OutOfBoundsException;
|
||||||
|
|
||||||
|
int getTotal(std::vector<int> arr) {
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < arr.size(); ++i) {
|
||||||
|
sum += arr[i];
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getTotal(std::vector<std::vector<int>> arr) {
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < arr.size(); ++i) {
|
||||||
|
sum += getTotal(arr[i]);
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getAverage(std::vector<int> arr) {
|
||||||
|
return getTotal(arr) / arr.size(); // NOLINT(*-narrowing-conversions)
|
||||||
|
}
|
||||||
|
|
||||||
|
int getAverage(std::vector<std::vector<int>> arr) {
|
||||||
|
return getTotal(arr) / arr.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
int getRowTotal(std::vector<std::vector<int>> arr, int desiredRow) {
|
||||||
|
// validate
|
||||||
|
if (desiredRow > arr[desiredRow].size()) {
|
||||||
|
throw OutOfBoundsException;
|
||||||
|
}
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < arr[desiredRow].size(); ++i) {
|
||||||
|
sum += arr[desiredRow][i];
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getColumnTotal(std::vector<std::vector<int>> arr, int desiredColumn) {
|
||||||
|
// validate
|
||||||
|
if (desiredColumn > arr.size()) {
|
||||||
|
throw OutOfBoundsException;
|
||||||
|
}
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < arr.size(); ++i) {
|
||||||
|
sum += arr[i][desiredColumn];
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getHighestInRow(std::vector<std::vector<int>> arr, int desiredRow) {
|
||||||
|
// validate
|
||||||
|
if (desiredRow > arr[desiredRow].size()) {
|
||||||
|
throw OutOfBoundsException;
|
||||||
|
}
|
||||||
|
int highest = INT_MIN;
|
||||||
|
for (int i = 0; i < arr[desiredRow].size(); ++i) {
|
||||||
|
if (arr[desiredRow][i] > highest) {
|
||||||
|
highest = arr[desiredRow][i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return highest;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getLowestInRow(std::vector<std::vector<int>> arr, int desiredRow) {
|
||||||
|
// validate
|
||||||
|
if (desiredRow > arr[desiredRow].size()) {
|
||||||
|
throw OutOfBoundsException;
|
||||||
|
}
|
||||||
|
int lowest = INT_MAX;
|
||||||
|
for (int i = 0; i < arr[desiredRow].size(); ++i) {
|
||||||
|
if (arr[desiredRow][i] < lowest) {
|
||||||
|
lowest = arr[desiredRow][i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lowest;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getHighestInColumn(std::vector<std::vector<int>> arr, int desiredColumn) {
|
||||||
|
// validate
|
||||||
|
if (desiredColumn > arr.size()) {
|
||||||
|
throw OutOfBoundsException;
|
||||||
|
}
|
||||||
|
int highest = INT_MIN;
|
||||||
|
for (int i = 0; i < arr.size(); ++i) {
|
||||||
|
if (arr[i][desiredColumn] > highest) {
|
||||||
|
highest = arr[i][desiredColumn];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return highest;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getLowestInColumn(std::vector<std::vector<int>> arr, int desiredColumn) {
|
||||||
|
// validate
|
||||||
|
if (desiredColumn > arr.size()) {
|
||||||
|
throw OutOfBoundsException;
|
||||||
|
}
|
||||||
|
int lowest = INT_MAX;
|
||||||
|
for (int i = 0; i < arr.size(); ++i) {
|
||||||
|
if (arr[i][desiredColumn] < lowest) {
|
||||||
|
lowest = arr[i][desiredColumn];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lowest;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string printVector(std::vector<int> arr) {
|
||||||
|
std::string output = "{";
|
||||||
|
for (int i = 0; i < arr.size(); ++i) {
|
||||||
|
output.append(std::to_string(arr[i]));
|
||||||
|
if ((arr.size() - 1) > i) {
|
||||||
|
output.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output.append("}");
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string printVector(std::vector<std::vector<int>> arr) {
|
||||||
|
std::string output = "{\n";
|
||||||
|
for (int i = 0; i < arr.size(); ++i) {
|
||||||
|
output.append(printVector(arr[i]));
|
||||||
|
if ((arr.size() - 1) > i) {
|
||||||
|
output.append(",\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output.append("\n}");
|
||||||
|
return output;
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// Created by caleb on 3/6/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MP2_CALEBFONTENOT_CLION_2DARRAYOPERATIONS_H
|
||||||
|
#define MP2_CALEBFONTENOT_CLION_2DARRAYOPERATIONS_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
int getTotal(std::vector<int> arr);
|
||||||
|
int getTotal(std::vector<std::vector<int>> arr);
|
||||||
|
|
||||||
|
int getAverage(std::vector<int> arr);
|
||||||
|
int getAverage(std::vector<std::vector<int>> arr);
|
||||||
|
|
||||||
|
int getRowTotal(std::vector<std::vector<int>> arr, int desiredRow);
|
||||||
|
int getColumnTotal(std::vector<std::vector<int>> arr, int desiredColumn);
|
||||||
|
|
||||||
|
int getHighestInRow(std::vector<std::vector<int>> arr, int desiredRow);
|
||||||
|
int getLowestInRow(std::vector<std::vector<int>> arr, int desiredRow);
|
||||||
|
|
||||||
|
int getHighestInColumn(std::vector<std::vector<int>> arr, int desiredColumn);
|
||||||
|
int getLowestInColumn(std::vector<std::vector<int>> arr, int desiredColumn);
|
||||||
|
|
||||||
|
std::string printVector(std::vector<int> arr);
|
||||||
|
std::string printVector(std::vector<std::vector<int>> arr);
|
||||||
|
|
||||||
|
#endif //MP2_CALEBFONTENOT_CLION_2DARRAYOPERATIONS_H
|
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
cmake --build /home/caleb/ASDV-Cpp/Assignments/MP2_CalebFontenot_clion/cmake-build-debug --target all -j
|
Binary file not shown.
@ -1,18 +1,35 @@
|
|||||||
# ninja log v5
|
# ninja log v5
|
||||||
0 363 1709704257681942810 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
0 353 1709774862988641657 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||||
0 25 1709704333049275905 build.ninja 4f9c96c928b44f5a
|
0 25 1709776586463940833 build.ninja 4f9c96c928b44f5a
|
||||||
373 427 1709703559957882338 MP2_CalebFontenot_clion 32f5091ba2f7c719
|
|
||||||
1 377 1709704341778548085 CMakeFiles/MP2_CalebFontenot_clion.dir/rockPaperScissors.cpp.o 3c611e61c65d5f2f
|
1 377 1709704341778548085 CMakeFiles/MP2_CalebFontenot_clion.dir/rockPaperScissors.cpp.o 3c611e61c65d5f2f
|
||||||
378 426 1709704341826549583 MP2_CalebFontenot_clion b1e68aaee7799e43
|
1 385 1709776397897671852 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||||
1 353 1709704428914284883 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
385 436 1709776397947672742 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
353 406 1709704428966286526 MP2_CalebFontenot_clion b1e68aaee7799e43
|
1 486 1709776909610255954 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||||
0 367 1709704460530286122 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
486 540 1709776909662256789 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
367 423 1709704460584287836 MP2_CalebFontenot_clion b1e68aaee7799e43
|
1 391 1709777002952746019 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||||
0 385 1709704576044976334 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
392 444 1709777003003746829 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
385 432 1709704576089977781 MP2_CalebFontenot_clion b1e68aaee7799e43
|
1 434 1709777403803008881 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||||
1 376 1709704712826400106 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
1 497 1709777403866009853 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||||
376 431 1709704712881401895 MP2_CalebFontenot_clion b1e68aaee7799e43
|
497 547 1709777403915010609 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
1 371 1709704731305001505 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
1 462 1709778672519150590 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||||
372 430 1709704731362003361 MP2_CalebFontenot_clion b1e68aaee7799e43
|
1 487 1709778672544151092 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||||
1 398 1709704841528604451 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
487 565 1709778672621152637 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
398 452 1709704841580606157 MP2_CalebFontenot_clion b1e68aaee7799e43
|
0 466 1709778868815008595 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||||
|
466 519 1709778868866009578 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
|
0 443 1709778918707966837 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||||
|
443 499 1709778918762967889 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
|
1 444 1709778995379425134 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||||
|
444 496 1709778995430426099 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
|
0 479 1709779063921715938 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||||
|
0 488 1709779063930716107 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||||
|
488 543 1709779063983717101 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
|
1 461 1709779158015470987 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||||
|
461 515 1709779158068471971 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
|
0 449 1709779333918709617 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||||
|
449 503 1709779333971710586 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
|
1 477 1709779373170426152 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||||
|
477 529 1709779373221427082 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
|
1 494 1709779531940306563 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||||
|
494 557 1709779532001307664 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
|
0 463 1709780164528184443 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||||
|
463 518 1709780164582185648 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue