1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Name: Arthur Spears
// Class: CST 126
// Date: 3/31/24
// Assignment: Homework 1
#include <iostream>
#include "helpers.hpp"
#include "menu.hpp"
#include <bitset>
using std::cout;
using std::endl;
struct DailyTemperature
{
int highTemp{};
int lowTemp{};
};
enum DayOfTheWeek
{
Sunday = 0,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday = 6
};
enum Month
{
January = 1,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
};
struct Date
{
Month month;
uint8_t day;
uint16_t year;
};
union FloatIntUnion
{
float intFloat;
uint32_t uInt;
};
int main() {
/*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;*/
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;
}
|