--Originally published at Programming Path
Well… this was a bit large but I did it. I just didn’t made the post because of partials and to be honest, I forgot that we had quiz and I did not publish it, but here I am.
The quiz had 5 problems, so I will post a lot of photos and codes.
The first problem was this:
Type in the following program and run it:
#include main() { /* PROGRAM TO PRINT OUT SPACE RESERVED FOR VARIABLES */ char c; short s; int i; unsigned int ui; unsigned long int ul; float f; double d; long double ld; cout << endl << "The storage space for each variable type is:" << endl; cout << endl << "char: \t\t\t%d bits",sizeof(c)*8; // \t means tab cout << endl << "short: \t\t\t%d bits",sizeof(s)*8; cout << endl << "int: \t\t\t%d bits",sizeof(i)*8; cout << endl << "unsigned int: \t\t%d bits",sizeof(ui)*8; cout << endl << "unsigned long int: \t%d bits",sizeof(ul)*8; cout << endl << "float: \t\t\t%d bits",sizeof(f)*8; cout << endl << "double: \t\t%d bits",sizeof(d)*8; cout << endl << "long double: \t\t%d bits",sizeof(ld)*8;
This was pretty easy. I just needed to write the same code but in c++. Here is the picture:
Second problem:
Write a program to read in a character, an integer, and a float, and print out the values, then cast to other types; so that the interaction with the user is something like the following:
Input a single character, followed by : h Input an integer, followed by : 4872 Input a float, followed by : 182.937 The character h when cast to an int gives value ????? The character h when cast to a float gives value ????? The integer 4872 when cast to a char gives value ? The integer 4872 when cast to a float gives value ????? The float 182. Continue reading "Quiz (Week 6)"