Revised: February 3, 2007
By Richard G. Baldwin
File Pfsg00150.htm
Practice Text Index
The practice tests in this series were written specifically for the benefit of my students in COSC 1315, Fundamentals of Programming. They consists of questions, answers, and explanations. The questions are based on the material covered in my series of online lecture notes for the course. Each practice test is keyed to a specific lecture. This practice test is keyed to lecture #150 titled Data Types.
150-2. True or False. All programming languages are type-sensitive languages.
150-3. True or False. For every different type of data used with a particular programming language, there is a specification somewhere that defines three important characteristics of the type:
150-4. True or False. An instance of a type is the physical manifestation of the plans or the specifications for the type.
150-5. True or False. Assuming that the short type is maintained as a 16-bit two's complement entity, the set of all possible values that you can store in an instance of the short type is the set of all the whole numbers ranging from -65,536 to +65,535.
150-6. True or False. Assuming that the unsigned short type is maintained as a 16-bit entity, the set of all possible values that you can store in an instance of the unsigned short type is the set of all the whole numbers ranging from 0 to +65,535.
150-7. True or False. Assuming that the short type is maintained as a 16-bit two's complement entity, you can store the value 32,768 in an instance of the type short.
150-8. True or False. Assume that you have two instances of the type short in a program. C++ allows you to perform the following operations involving one or both of those instances:
150-9. True or False. C++ data types can be subdivided into the following major categories:
150-10. True or False. C++ is an extensible programming language.
150-11. True or False. C++ primitive types can be subdivided into four categories.
150-12. True or False. Whole-number types, often called integer types, can be used to represent data with fractional parts.
150-13. True or False. If you were writing a program dealing with quantities of applesauce and hamburger, it might make sense to:
150-14. True or False. In C++, there are at least four different basic whole-number types, and there are both signed and unsigned variations on each of the basic types:
150-15. True or False. The four basic integer data types differ primarily in terms of their names and the amount of computer memory required to store instances of the types.
150-16. True or False. The value 623.57185 can be represented in any of the ways shown in Listing 150-16.
Listing 150-16.
.62357185*10000 6.2357185*1000 62.357185*100 623.57185*10 6235.7185*1 62357.185*0.1 623571.85*0.01 6235718.5*0.001 62357185.*0.0001 |
150-17. True or False. As shown by the example in Listing 150-17, a value (such as 623.57185) can be represented as a mantissa (such as 62357185) multiplied by a factor (such as 0.00001) where the purpose of the factor is to represent a left or right shift in the position of the decimal point.
Listing 150-17.
62357185.*0.00001 |
150-18. True or False. If we allow the following symbol (^) to represent exponentiation (raising to a power) and allow the following symbol (/) to represent division, then we can write the values for the factors shown in the leftmost column in Listing 150-18 in the two ways shown in the middle column and the rightmost column in Listing 150-18.
Listing 150-18.
1000 = 10^+3 = 1*10*10*10 100 = 10^+2 = 1*10*10 10 = 10^+1 = 1*10 1 = 10^+0 = 1 0.1 = 10^-1 = 1/10 0.01 = 10^-2 = 1/(10*10) 0.001 = 10^-3 = 1/(10*10*10) 0.0001 = 10^-4 = 1/(10*10*10*10) 0.00001 = 10^-5 = 1/(10*10*10*10*10) |
150-19. True or False. By definition, the value of any value raised to the zeroth power is 0.
150-20. True or False. If we allow the following symbol (^) to represent exponentiation (raising to a power), we can represent the value 62.357185 in all the ways shown in Listing 150-20.
Listing 150-20.
.62357185*10^+3 6.2357185*10^+2 62.357185*10^+1 623.57185*10^+0 6235.7185*10^-1 62357.185*10^-2 623571.85*10^-3 6235718.5*10^-4 62357185.*10^-5 |
150-21. True or False. If we allow the symbol (^) to represent exponentiation (raising to a power) and allow the symbol (E) to represent the expression (*10^), we can represent the value 623.57185 in all the ways shown in Listing 150-21.
Listing 150-21.
.62357185E+3 6.2357185E+2 62.357185E+1 623.57185E+0 6235.7185E-1 62357.185E-2 623571.85E-3 6235718.5E-4 62357185.E-5 |
150-22. True or False. Floating point types represent values as a mantissa containing a decimal point along with an exponent value that tells how many places to shift the decimal point to the left or to the right in order to determine the true value.
Positive exponent values mean that the decimal point should be shifted to the left. Negative exponent values mean that the decimal point should be shifted to the right.
150-23. True or False. One advantage of floating-point types is that they can be used to maintain fractional parts in data values.
150-24. True or False. A disadvantage of floating-point types is that a large range of values cannot be represented by floating-point types.
150-25. True or False. C++ supports at least three different floating point types:
These three types differ primarily in terms of the range of values that they can support and the amount of memory required to store an instance of the type.
Values of any of the three types can be either positive or negative as indicated by the ± character.
150-26. True or False. There are at least two character types in C++:
150-27. True or False. Computers deal only in numeric values. They don't know how to deal directly with the letters of the alphabet and punctuation characters.
Therefore, the values actually stored as instances of character types are numeric values that represent characters.
150-28. True or False. The char type has two purposes. One purpose is to represent whole numbers in the range from -32768 to +32767 or 0 to 65535.
The second purpose is to represent characters as eight-bit numeric values in order to make it possible to represent the following internally in the computer:
This is accomplished by assigning a numeric value to each character, much as you may have done to create secret codes when you were a child.
150-29. True or False. The wchar_t type is a wide character type. This type is designed as a type to store international characters of a two-byte (16-bit) character set.
150-30. True or False. Insofar as keyboard characters are concerned, you usually represent a character to the program by surrounding it with apostrophes as follows: 'A'. Programming tools know how to cross reference that specific character symbol against a character table to obtain the corresponding numeric value.
150-31. True or False. The bool type can have only three values:
150-32. True or False. As is the case with C# and Java, it is not possible to perform arithmetic operations on variables of type bool.
150-33. True or False. The string type has become part of the core C++ language and can be used much the same way primitive types are used provided that the string header file is included in the program. The purpose of the string type is to store strings of characters
150-34. True or False. One of the ways that individual programmers can extend the C++ language is to create new types. When creating a new type, the user must define:
150-35. True or False. New types are created by combining instances of primitive types and instances of previously defined user-defined types.
150-36. True or False. As a student in COSC 1315, the most important thing for you to know about user-defined types is that they are possible for you to create and use as you move into more advanced programming courses.
150-37. True or False. One specific C++ mechanism that makes it possible for you to define new types is a mechanism known as the class definition.
150-38. What output is produced by the program shown in Listing 150-38?
/*File: Types01b.cpp Revised 02/01/07 ************************************************/ #include <iostream> using namespace std; class Types01b{ public: static void classMain(){ Types01b* ptrToObject = new Types01b(); ptrToObject -> doSomething(); }//End classMain function //-------------------------------------------// void doSomething(){ char numCharVar = 242; cout << "numCharVar = " << numCharVar << endl; }//end doSomething function };//End Types01b class //---------------------------------------------// int main(){ Types01b::classMain(); return 0; }//end main |
150-39. What output is produced by the program shown in Listing 150-39?
/*File: Types01c.cpp Revised 02/02/07 ************************************************/ #include <iostream> using namespace std; class Types01c{ public: static void classMain(){ Types01c* ptrToObject = new Types01c(); ptrToObject -> doSomething(); }//End classMain function //-------------------------------------------// void doSomething(){ long var = 2147483647; cout << (var + 1) << endl; }//end doSomething function };//End Types01c class //---------------------------------------------// int main(){ Types01c::classMain(); return 0; }//end main |
150-40. What output is produced by the program shown in Listing 150-40?
/*File: Types01d.cpp Revised 02/02/07 ************************************************/ #include <iostream> using namespace std; class Types01d{ public: static void classMain(){ Types01d* ptrToObject = new Types01d(); ptrToObject -> doSomething(); }//End classMain function //-------------------------------------------// void doSomething(){ wchar_t wideChVar = 'B'; cout << "wideChVar = " << wideChVar << endl; }//end doSomething function };//End Types01d class //---------------------------------------------// int main(){ Types01d::classMain(); return 0; }//end main |
150-41. What output is produced by the program shown in Listing 150-41?
floatVar= 6.66667 doubleVar= 66.666666667 longDblVar= 666.66666666667
/*File: Types01e.cpp Revised 02/02/07 ************************************************/ #include <iostream> using namespace std; class Types01e{ public: static void classMain(){ Types01e* ptrToObject = new Types01e(); ptrToObject -> doSomething(); }//End classMain function //-------------------------------------------// void doSomething(){ float floatVar = 20/3.0; double doubleVar = 200/3.0; long double longDblVar = 2000/3.0; cout << "floatVar= " << floatVar << endl; cout << "doubleVar= " << doubleVar << endl; cout << "longDblVar= " << longDblVar << endl; }//end doSomething function };//End Types01e class //---------------------------------------------// int main(){ Types01e::classMain(); return 0; }//end main |
150-42. What output is produced by the program shown in Listing 150-42?
/*File: Types01f.cpp Revised 02/02/07 ************************************************/ #include <iostream> using namespace std; class Types01f{ public: static void classMain(){ Types01f* ptrToObject = new Types01f(); ptrToObject -> doSomething(); }//End classMain function //-------------------------------------------// void doSomething(){ bool boolVar = true; cout << boolVar << endl; }//end doSomething function };//End Types01f class //---------------------------------------------// int main(){ Types01f::classMain(); return 0; }//end main |
150-43. What output is produced by the program shown in Listing 150-43?
#include <iostream> using namespace std; class Types01g{ public: static void classMain(){ Types01g* ptrToObject = new Types01g(); ptrToObject -> doSomething(); }//End classMain function //-------------------------------------------// void doSomething(){ char charVar = 'A'; charVar = charVar + 5; cout << "charVar = " << charVar << endl; }//end doSomething function };//End Types01g class //---------------------------------------------// int main(){ Types01g::classMain(); return 0; }//end main |
150-44. What output is produced by the program shown in Listing 150-44?
/*File: Types01h.cpp Revised 02/02/07 ************************************************/ #include <iostream> using namespace std; class Types01h{ public: static void classMain(){ Types01h* ptrToObject = new Types01h(); ptrToObject -> doSomething(); }//End classMain function //-------------------------------------------// void doSomething(){ bool boolVar = true; cout << "boolVar*2 = " << boolVar*2 << endl; }//end doSomething function };//End Types01h class //---------------------------------------------// int main(){ Types01h::classMain(); return 0; }//end main |
150-45. True or False. Some data types involve whole numbers only (no fractional parts are allowed).
Richard has participated in numerous consulting projects involving Java, XML, or a combination of the two. He frequently provides onsite Java and/or XML training at the high-tech companies located in and around Austin, Texas. He is the author of Baldwin's Java Programming Tutorials, which has gained a worldwide following among experienced and aspiring Java programmers. He has also published articles on Java Programming in Java Pro magazine.
Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.
When you use the insertion operator along with cout to display the value of a variable of type bool, the result is either 1 or 0, and is not true or false as you might expect.
When the insertion operator is used along with cout to display any of the three floating point types, the number of significant digits that is displayed is the same as type float even though types double and long double maintain more significant digits than type float in their internal representation.
When the insertion operator is used with cout to display a variable of the wide character type wchar_t, it is the numeric value and not the character that is displayed.
The output is: numCharVar = ≥
It is not necessary to define the header file.
The bool type cannot be used to represent undecided.
Numeric range is incorrect.
Right and left were reversed.
The values of the exponents are not correct.
The multipliers are incorrect.
Whole-number types, often called integer types, can be used to represent data without fractional parts.
Note that the String type is not strictly a primitive type, although it has become a core part of the C++ programming language. Rather, it is constructed from a class.
There is no operator that allows you to raise one of the instances to a power..
You can store the set of all the whole numbers ranging from -32,768 to +32,767.
You can store the set of all the whole numbers ranging from -32,768 to +32,767.
The physical appearance is not included in the type specification.
Richard has participated in numerous consulting projects involving Java, XML, or a combination of the two. He frequently provides onsite Java and/or XML training at the high-tech companies located in and around Austin, Texas. He is the author of Baldwin's Java Programming Tutorials, which has gained a worldwide following among experienced and aspiring Java programmers. He has also published articles on Java Programming in Java Pro magazine.
Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.
-end-