COSC 1315

Programming Fundamentals

 Practice Text #150

Data Types

Revised: February 3, 2007
By Richard G. Baldwin

File Pfsg00150.htm
Practice Text Index


Welcome

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.

Questions



150-1.  True or False.  C++, Java, and C# are type sensitive languages.

Answer and Explanation

150-2.  True or False.  All programming languages are type-sensitive languages.

Answer and Explanation

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:

  1. What is the set of all possible data values that can be stored in an instance of the type?
  2. Once you have an instance of the type, what are the operations that you can perform on that instance alone, or in combination with other instances?
  3. What is the physical appearance of data of the type when it is displayed on the computer screen?

Answer and Explanation

150-4.  True or False.  An instance of a type is the physical manifestation of the plans or the specifications for the type.

Answer and Explanation

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.

Answer and Explanation

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.

Answer and Explanation

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.

Answer and Explanation

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:

Answer and Explanation

150-9.  True or False.  C++ data types can be subdivided into the following major categories:

Answer and Explanation

150-10.  True or False.  C++ is an extensible programming language.

Answer and Explanation

150-11.  True or False.  C++ primitive types can be subdivided into four categories.

Answer and Explanation

150-12.  True or False.  Whole-number types, often called integer types, can be used to represent data with fractional parts.

Answer and Explanation

150-13.  True or False.  If you were writing a program dealing with quantities of applesauce and hamburger, it might make sense to:

Answer and Explanation

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:

Answer and Explanation

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.

Answer and Explanation

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

Answer and Explanation

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

Answer and Explanation

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)

Answer and Explanation

150-19.  True or False.  By definition, the value of any value raised to the zeroth power is 0.

Answer and Explanation

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

Answer and Explanation

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

Answer and Explanation

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.

Answer and Explanation

150-23.  True or False.  One advantage of floating-point types is that they can be used to maintain fractional parts in data values.

Answer and Explanation

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.

Answer and Explanation

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.

Answer and Explanation

150-26.  True or False.  There are at least two character types in C++:

Answer and Explanation

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.

Answer and Explanation

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.

Answer and Explanation

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.

Answer and Explanation

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.

Answer and Explanation

150-31.  True or False.  The bool type can have only three values:

Answer and Explanation

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.

Answer and Explanation

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

Answer and Explanation

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:

Answer and Explanation

150-35.  True or False.  New types are created by combining instances of primitive types and instances of previously defined user-defined types.

Answer and Explanation

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.

Answer and Explanation

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.

Answer and Explanation

150-38.  What output is produced by the program shown in Listing 150-38?

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

Answer and Explanation

150-39.  What output is produced by the program shown in Listing 150-39?

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

Answer and Explanation

150-40.  What output is produced by the program shown in Listing 150-40?

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

Answer and Explanation

150-41.  What output is produced by the program shown in Listing 150-41?

Listing 150-41.
/*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

Answer and Explanation

150-42.  What output is produced by the program shown in Listing 150-42?

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

Answer and Explanation

150-43.  What output is produced by the program shown in Listing 150-43?

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

Answer and Explanation

150-44.  What output is produced by the program shown in Listing 150-44?

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

Answer and Explanation

150-45.  True or False.  Some data types involve whole numbers only (no fractional parts are allowed). 

Answer and Explanation



Copyright 2007, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

About the author

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java and XML. In addition to the many platform-independent benefits of Java applications, he believes that a combination of Java and XML will become the primary driving force in the delivery of structured information on the Web.

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.

Baldwin@DickBaldwin.com


Answers and Explanations

Answer 45

True

Back to Question 45

Explanation 45

Answer 44

D.  None of the above.

Back to Question 44

Explanation 44

Answer 43

D.  None of the above.

Back to Question 43

Explanation 43

Answer 42

C.  1

Back to Question 42

Explanation 42

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.

Answer 41

D.  None of the above.

Back to Question 41

Explanation 41

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.

Answer 40

D.  None of the above.

Back to Question 40

Explanation 40

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.

Answer 39

C.  -2147483648

Back to Question 39

Explanation 39

Answer 38

D.  None of the above.

Back to Question 38

Explanation 38

The output is:  numCharVar = ≥

Answer 37

True

Back to Question 37

Explanation 37

Answer 36

True

Back to Question 36

Explanation 36

Answer 35

True

Back to Question 35

Explanation 35

Answer 34

False

Back to Question 34

Explanation 34

It is not necessary to define the header file.

Answer 33

True

Back to Question 33

Explanation 33

Answer 32

False

Back to Question 32

Explanation 32

Answer 31

False

Back to Question 31

Explanation 31

The bool type cannot be used to represent undecided.

Answer 30

True

Back to Question 30

Explanation 30

Answer 29

True

Back to Question 29

Explanation 29

Answer 28

False

Back to Question 28

Explanation 28

Numeric range is incorrect.

Answer 27

True

Back to Question 27

Explanation 27

Answer 26

True

Back to Question 26

Explanation 26

Answer 25

True

Back to Question 25

Explanation 25

Answer 24

False

Back to Question 24

Explanation 24

Answer 23

True

Back to Question 23

Explanation 23

Answer 22

False

Back to Question 22

Explanation 22

Right and left were reversed.

Answer 21

True

Back to Question 21

Explanation 21

Answer 20

False

Back to Question 20

Explanation 20

The values of the exponents are not correct.

Answer 19

False

Back to Question 19

Explanation 19

Answer 18

True

Back to Question 18

Explanation 18

Answer 17

True

Back to Question 17

Explanation 17

Answer 16

False

Back to Question 16

Explanation 16

The multipliers are incorrect.

Answer 15

False

Back to Question 15

Explanation 15

Answer 14

True

Back to Question 14

Explanation 14

Answer 13

True

Back to Question 13

Explanation 13

Answer 12

False

Back to Question 12

Explanation 12

Whole-number types, often called integer types, can be used to represent data without fractional parts.

Answer 11

True

Back to Question 11

Explanation 11

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.

Answer 10

True

Back to Question 10

Explanation 10

Answer 9

True

Back to Question 9

Explanation 9

Answer 8

False

Back to Question 8

Explanation 8

There is no operator that allows you to raise one of the instances to a power..

Answer 7

False

Back to Question 7

Explanation 7

You can store the set of all the whole numbers ranging from -32,768 to +32,767.

Answer 6

True

Back to Question 6

Explanation 6

Answer 5

False

Back to Question 5

Explanation 5

You can store the set of all the whole numbers ranging from -32,768 to +32,767.

Answer 4

True

Back to Question 4

Explanation 4

Answer 3

False

Back to Question 3

Explanation 3

The physical appearance is not included in the type specification.

Answer 2

False

Back to Question 2

Explanation 2

Answer 1

True

Back to Question 1

Explanation 1



Copyright 2007, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

About the author

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java and XML. In addition to the many platform-independent benefits of Java applications, he believes that a combination of Java and XML will become the primary driving force in the delivery of structured information on the Web.

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.

Baldwin@DickBaldwin.com

-end-