From 7986ee1b60dcd6bf645dfb84272b887faa0aafb8 Mon Sep 17 00:00:00 2001 From: Arthur Spears Date: Wed, 17 Apr 2024 19:27:26 -0700 Subject: Added second unit tests project as example. --- CST 126/Homework 1/main.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'CST 126/Homework 1/main.cpp') 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(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; } -- cgit v1.2.3