Homework 2

The purpose of this assignment is to declare and initialize variables of different data types, use arithmetic assignment operators, and understand the difference between initialized vs uninitialized. Also, to have knowledge of each data type's byte size with use of sizeof().

What to complete for this assignment

Write a program and label the source code 'hw2.cpp'. Declare variables of the following data types with out initializing them:
int, float, double, bool, char.
Output each variable in the following format:
cout << "<dataType>: " << <varName> << endl;
cout << "int: " << myInt << endl;

Next, prompt the user for a value for each data type and read in the value (cin) to the corresponding variable.

Enter an integer value:  1 [entered]
Enter a floating point value:  2.2 [entered]
Enter a double floating point value:  3.33 [entered]
Enter a boolean value:  0 [entered]
Enter a character value:  A [entered]

Then output each variable using the format below.

int: 1
float: 2.2
double: 3.33
bool: 0
char: A

Perform the addition assignment operator ( += ) to each variable add 1. Output each variable's value with one cout statment and all on one line.

Variable Values: 2, 3.2, 4.33, 1, B
Take notice to what happened to the character and boolean variables.

Finally, using the sizeof() function discussed in class, output the size for each data type: int, float, double, bool, char. Your output should look like so:

The size of an int is 4 bytes
The size of a float is 4 bytes
The size of a double is 8 bytes
The size of a bool is 1 byte
The size of a char is 1 byte

Once completed, make sure your hw2.cpp file is within /2010_F18/wk2/hw2.cpp.

That's it, congratulations, and you're done. If you have any questions, feel free to ask me during office hours, before class, after class, email me, call me, or find me and I'd be happy to help. Also, there's the walk-in lab (SCI III rm 324) where there are tutors there to help if you cannot reach me.