diff options
| author | Arthur Spears <[email protected]> | 2024-04-17 19:27:26 -0700 |
|---|---|---|
| committer | Arthur Spears <[email protected]> | 2024-04-17 19:27:26 -0700 |
| commit | 7986ee1b60dcd6bf645dfb84272b887faa0aafb8 (patch) | |
| tree | b015260b6804acb0966c9ceb393d0fa9edd5938b /CST 126/Homework 1/main.cpp | |
| parent | Added Unit Tests Project (diff) | |
| download | homework-1-arthurtspears-7986ee1b60dcd6bf645dfb84272b887faa0aafb8.tar.xz homework-1-arthurtspears-7986ee1b60dcd6bf645dfb84272b887faa0aafb8.zip | |
Added second unit tests project as example.
Diffstat (limited to 'CST 126/Homework 1/main.cpp')
| -rw-r--r-- | CST 126/Homework 1/main.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/CST 126/Homework 1/main.cpp b/CST 126/Homework 1/main.cpp index b4c91fc..f61633a 100644 --- a/CST 126/Homework 1/main.cpp +++ b/CST 126/Homework 1/main.cpp @@ -58,13 +58,31 @@ union FloatIntUnion }; int main() { - FloatIntUnion floatIntUnion {}; + + /*FloatIntUnion floatIntUnion {}; floatIntUnion.intFloat = 1.2345f; std::cout << "Float: " << floatIntUnion.intFloat << std::endl; std::cout << "Binary representation: " << std::bitset<32>(static_cast<uint32_t>(floatIntUnion.intFloat)) << std::endl; std::cout << "As Int: " << floatIntUnion.uInt << std::endl; - std::cout << "Binary representation: " << std::bitset<32>(floatIntUnion.uInt) << std::endl; + std::cout << "Binary representation: " << std::bitset<32>(floatIntUnion.uInt) << std::endl;*/ + int input; + cout << "How big you want your array? "; + cin >> input; + + + int* intArray = nullptr; + + try { + intArray = new int[input] {}; + } + catch (const std::bad_alloc& ex) { + delete[] intArray; + intArray = nullptr; + std::cerr << "Exception allocating memor for int array:" << ex.what(); + } + + delete[] intArray; return 0; } |