Update MP2
This commit is contained in:
parent
92d6102039
commit
ec700702c8
142
Assignments/MP2_CalebFontenot_clion/2DArrayOperations.cpp
Normal file
142
Assignments/MP2_CalebFontenot_clion/2DArrayOperations.cpp
Normal file
@ -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;
|
||||
}
|
29
Assignments/MP2_CalebFontenot_clion/2DArrayOperations.h
Normal file
29
Assignments/MP2_CalebFontenot_clion/2DArrayOperations.h
Normal file
@ -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
|
@ -4,4 +4,6 @@ project(MP2_CalebFontenot_clion)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
add_executable(MP2_CalebFontenot_clion main.cpp
|
||||
rockPaperScissors.cpp)
|
||||
rockPaperScissors.cpp
|
||||
2DArrayOperations.cpp
|
||||
2DArrayOperations.h)
|
||||
|
2
Assignments/MP2_CalebFontenot_clion/build.sh
Executable file
2
Assignments/MP2_CalebFontenot_clion/build.sh
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
cmake --build /home/caleb/ASDV-Cpp/Assignments/MP2_CalebFontenot_clion/cmake-build-debug --target all -j
|
@ -39,7 +39,7 @@
|
||||
{
|
||||
"directoryIndex" : 0,
|
||||
"id" : "MP2_CalebFontenot_clion::@6890427a1f51a3e7e1df",
|
||||
"jsonFile" : "target-MP2_CalebFontenot_clion-Debug-09c3b71a7da4287bde03.json",
|
||||
"jsonFile" : "target-MP2_CalebFontenot_clion-Debug-d3c01b322ca9d00e6fc5.json",
|
||||
"name" : "MP2_CalebFontenot_clion",
|
||||
"projectIndex" : 0
|
||||
}
|
@ -26,7 +26,7 @@
|
||||
"objects" :
|
||||
[
|
||||
{
|
||||
"jsonFile" : "codemodel-v2-62f2326d2e99006d14ca.json",
|
||||
"jsonFile" : "codemodel-v2-fb3b9160ce314057a50e.json",
|
||||
"kind" : "codemodel",
|
||||
"version" :
|
||||
{
|
||||
@ -86,7 +86,7 @@
|
||||
},
|
||||
"codemodel-v2" :
|
||||
{
|
||||
"jsonFile" : "codemodel-v2-62f2326d2e99006d14ca.json",
|
||||
"jsonFile" : "codemodel-v2-fb3b9160ce314057a50e.json",
|
||||
"kind" : "codemodel",
|
||||
"version" :
|
||||
{
|
@ -50,7 +50,8 @@
|
||||
"sourceIndexes" :
|
||||
[
|
||||
0,
|
||||
1
|
||||
1,
|
||||
2
|
||||
]
|
||||
}
|
||||
],
|
||||
@ -84,7 +85,15 @@
|
||||
"sourceIndexes" :
|
||||
[
|
||||
0,
|
||||
1
|
||||
1,
|
||||
2
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "Header Files",
|
||||
"sourceIndexes" :
|
||||
[
|
||||
3
|
||||
]
|
||||
}
|
||||
],
|
||||
@ -101,6 +110,17 @@
|
||||
"compileGroupIndex" : 0,
|
||||
"path" : "rockPaperScissors.cpp",
|
||||
"sourceGroupIndex" : 0
|
||||
},
|
||||
{
|
||||
"backtrace" : 1,
|
||||
"compileGroupIndex" : 0,
|
||||
"path" : "2DArrayOperations.cpp",
|
||||
"sourceGroupIndex" : 0
|
||||
},
|
||||
{
|
||||
"backtrace" : 1,
|
||||
"path" : "2DArrayOperations.h",
|
||||
"sourceGroupIndex" : 1
|
||||
}
|
||||
],
|
||||
"type" : "EXECUTABLE"
|
Binary file not shown.
@ -1,18 +1,35 @@
|
||||
# ninja log v5
|
||||
0 363 1709704257681942810 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||
0 25 1709704333049275905 build.ninja 4f9c96c928b44f5a
|
||||
373 427 1709703559957882338 MP2_CalebFontenot_clion 32f5091ba2f7c719
|
||||
0 353 1709774862988641657 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||
0 25 1709776586463940833 build.ninja 4f9c96c928b44f5a
|
||||
1 377 1709704341778548085 CMakeFiles/MP2_CalebFontenot_clion.dir/rockPaperScissors.cpp.o 3c611e61c65d5f2f
|
||||
378 426 1709704341826549583 MP2_CalebFontenot_clion b1e68aaee7799e43
|
||||
1 353 1709704428914284883 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||
353 406 1709704428966286526 MP2_CalebFontenot_clion b1e68aaee7799e43
|
||||
0 367 1709704460530286122 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||
367 423 1709704460584287836 MP2_CalebFontenot_clion b1e68aaee7799e43
|
||||
0 385 1709704576044976334 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||
385 432 1709704576089977781 MP2_CalebFontenot_clion b1e68aaee7799e43
|
||||
1 376 1709704712826400106 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||
376 431 1709704712881401895 MP2_CalebFontenot_clion b1e68aaee7799e43
|
||||
1 371 1709704731305001505 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||
372 430 1709704731362003361 MP2_CalebFontenot_clion b1e68aaee7799e43
|
||||
1 398 1709704841528604451 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||
398 452 1709704841580606157 MP2_CalebFontenot_clion b1e68aaee7799e43
|
||||
1 385 1709776397897671852 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||
385 436 1709776397947672742 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||
1 486 1709776909610255954 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||
486 540 1709776909662256789 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||
1 391 1709777002952746019 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||
392 444 1709777003003746829 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||
1 434 1709777403803008881 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||
1 497 1709777403866009853 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||
497 547 1709777403915010609 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||
1 462 1709778672519150590 CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o 8c11d8cca87b33c8
|
||||
1 487 1709778672544151092 CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o 8cba3aec4cecc88c
|
||||
487 565 1709778672621152637 MP2_CalebFontenot_clion 2529c2e4cc438c09
|
||||
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.
@ -61,6 +61,12 @@ build CMakeFiles/MP2_CalebFontenot_clion.dir/rockPaperScissors.cpp.o: CXX_COMPIL
|
||||
OBJECT_DIR = CMakeFiles/MP2_CalebFontenot_clion.dir
|
||||
OBJECT_FILE_DIR = CMakeFiles/MP2_CalebFontenot_clion.dir
|
||||
|
||||
build CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o: CXX_COMPILER__MP2_CalebFontenot_clion_unscanned_Debug /home/caleb/ASDV-Cpp/Assignments/MP2_CalebFontenot_clion/2DArrayOperations.cpp || cmake_object_order_depends_target_MP2_CalebFontenot_clion
|
||||
DEP_FILE = CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o.d
|
||||
FLAGS = -lncurses -Wno-write-strings -g -std=gnu++23 -fdiagnostics-color=always
|
||||
OBJECT_DIR = CMakeFiles/MP2_CalebFontenot_clion.dir
|
||||
OBJECT_FILE_DIR = CMakeFiles/MP2_CalebFontenot_clion.dir
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Link build statements for EXECUTABLE target MP2_CalebFontenot_clion
|
||||
@ -69,7 +75,7 @@ build CMakeFiles/MP2_CalebFontenot_clion.dir/rockPaperScissors.cpp.o: CXX_COMPIL
|
||||
#############################################
|
||||
# Link the executable MP2_CalebFontenot_clion
|
||||
|
||||
build MP2_CalebFontenot_clion: CXX_EXECUTABLE_LINKER__MP2_CalebFontenot_clion_Debug CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o CMakeFiles/MP2_CalebFontenot_clion.dir/rockPaperScissors.cpp.o
|
||||
build MP2_CalebFontenot_clion: CXX_EXECUTABLE_LINKER__MP2_CalebFontenot_clion_Debug CMakeFiles/MP2_CalebFontenot_clion.dir/main.cpp.o CMakeFiles/MP2_CalebFontenot_clion.dir/rockPaperScissors.cpp.o CMakeFiles/MP2_CalebFontenot_clion.dir/2DArrayOperations.cpp.o
|
||||
FLAGS = -lncurses -Wno-write-strings -g
|
||||
LINK_FLAGS = -rdynamic
|
||||
OBJECT_DIR = CMakeFiles/MP2_CalebFontenot_clion.dir
|
||||
|
@ -12,12 +12,22 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <ncurses.h>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
#include "rockPaperScissors.h"
|
||||
#include "main.h"
|
||||
#include "2DArrayOperations.h"
|
||||
|
||||
int main(){
|
||||
|
||||
std::vector<std::vector<int>> vector = {
|
||||
{1, 2, 3, 4},
|
||||
{5, 6, 7, 8},
|
||||
{9, 10, 11, 12},
|
||||
{13, 14, 15, 16}
|
||||
};
|
||||
|
||||
int ch;
|
||||
static int selection = 0;
|
||||
static int * selectionPointer = &selection;
|
||||
@ -45,8 +55,23 @@ int main(){
|
||||
gameLoop();
|
||||
break;
|
||||
case 1:
|
||||
cout << "\033[2J\033[1;1H"; // Clear screen unicode sequence
|
||||
printf("2D Vector:\n%s\n", printVector(vector).c_str());
|
||||
printf("getTotal: %i\n", getTotal(vector));
|
||||
printf("getAverage: %i\n", getAverage(vector));
|
||||
printf("getRowTotal 0: %i\n", getRowTotal(vector, 0));
|
||||
printf("getColumnTotal 0: %i\n", getColumnTotal(vector, 0));
|
||||
printf("getHighestInRow 0: %i\n", getHighestInRow(vector, 0));
|
||||
printf("getHighestInColumn 0: %i\n", getHighestInColumn(vector, 0));
|
||||
printf("getLowestInRow 3: %i\n", getLowestInRow(vector, 3));
|
||||
printf("getLowestInColumn 3: %i\n", getLowestInColumn(vector, 3));
|
||||
cout << "Press Enter to Continue";
|
||||
getchar();
|
||||
break;
|
||||
case 2:
|
||||
cout << "\033[2J\033[1;1H"; // Clear screen unicode sequence
|
||||
cout << "Press Enter to Continue";
|
||||
getchar();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user