HW4: Exploring Data Types

If we really want to gain a better understanding of how computers actually work. We have to know how all of our data is represented, and the limits on values we can use for those data.

You should have the basic idea that all of your data ends up in that thing we call memory somewhere. The question you probably never gave much thought to is exactly how is it stored there, and what does it look like?

We will explore that in more detail in class. For this homework assignment, I want you to explore the basic data types supported by the language we will be using to build out simulator. That language is C++.

The C++ language is defined in a precise way by a standards committee so everyone can be sure they are using the same language, no matter what system and compiler you use. Here is a copy of the latest standard document for C++ (specifically, C++14):

What To Do

You will build a simple single-file C++ program for this homework. You can do this any way you want, as long as the source code file ends up in your Homework repository in a folder named “homework/hw4”.

There are several “Fundamental Data Types” specified in the standard:

  • character types
  • signed integer types
  • unsigned integer types
  • boolean types
  • floating point types
  • void type
  • null-pointer type

Many of these types are available in different sizes, for example “short”, “double”, etc.

Step1: Create Each Type

For all of the defined data types for the Gnu C++ compiler we will be using, create a line of code that sets up a simple variable that can hold one of those types and gives it an initial value.

Step2: Explore the Range of Values

Next, we want to explore the range of values each of those data types supports. What is the largest value, and the smallest value that can be represented in each one. It surprises many beginners that computers don’t do math the same way humans do math, and this is something you really need to understand as a developer.

There is a standard tool to assist with this:

* :ref:`std::numeric_limits

Warning

You might get your first look at a C++ feature called templates in this. The example code you see on the reference web page should show you all you need to know to do this assignment.

If you cannot get one of the not-so-common data types set up, just ignore that one and move on.

Submitting Your Work

As usual, this homework needs to show up in a folder in your project repository. Make sure you can see it in your web browser on GitHub