// // main.cpp // class4 // // Created by Chad Spensky on 6/30/16. // Copyright © 2016 Chad Spensky. All rights reserved. // #include #include using namespace std; enum Year {Freshman,Sophomore,Junior,Senior}; enum class YearStrong {Freshman,Sophomore,Junior,Senior}; int main(int argc, const char * argv[]) { // Initialize a double with a value double d = 5.5; // Store that double in an integer int i = d; // Print the integer and coorespanding bits cout << "Integer: " << i << endl; cout << "Integer (bits): " << bitset<32>(i) << endl; // Print the double and the cooresponding bits cout << "Double:" << d << endl; // Copy the double into a memory buffer so that we can print it's actual contents uint64_t u; memcpy(&u, &d, sizeof(d)); cout << "Double (bits):" << bitset<64>(u) << endl; // Add a very large number to the int (2^16 to be exact) i += 65536; // Store that large nubmer in the short, which is only 16 bits total short s = i; // Print the value of the integer and its cooresponding bits cout << "Integer: " << i << endl; cout << "Integer (bits): " << bitset<32>(i) << endl; // Print the short and the cooresponding bits (It's 5 again!) cout << "Short:" << s << endl; cout << "Short (bits): " << bitset<16>(s) << endl; // Let's negate a zero, and get a one! i = 0; i = !i; // Print our result cout << "This is a !1: " << i << endl; // Use normal enumerations, which can be treated as ints Year year = Senior; // Check to see which year we are talking about? if (year == Sophomore) { cout << "Wohoo! 2nd year!" << endl; } else if (year == 3) { cout << "Um... Senior?" << endl; } else { cout << "Not sure what " << year << " is." << endl; } // Use our strong enumeration class Year year2 = Year::Sophomore; // Check to see which year we are talking about? if (year2 == Year::Sophomore) { cout << "Wohoo! 2nd year!" << endl; } else if (year2 == Year::Senior) { cout << "Um... Senior?" << endl; } else { cout << "Not sure what " << year2 << " is." << endl; } return 0; }