Introduction to C++ Programming and Data Structures, Fifth Edition, Y. Daniel Liang

This quiz is for students to practice. A large number of additional quiz is available for instructors using Quiz Generator from the Instructor's Resource Website. Videos for Java, Python, and C++ can be found at https://yongdanielliang.github.io/revelvideos.html.

Chapter 1 Introduction to Computers, Programs, and C++


Section 1.2 What is a Computer?
1.1  ________ is the physical aspect of the computer that can be seen.
A. Hardware
B. Software
C. Operating system
D. Application program

Section 1.2.1 What is a Computer?
1.2  __________ is the brain of a computer.
A. Hardware
B. CPU
C. Memory
D. Disk

1.3  The speed of the CPU may be measured in __________. Please select all that apply.
A. megabytes
B. gigabytes
C. megahertz
D. gigahertz

Section 1.2.2 Bits and Bytes
1.4  Why do computers use zeros and ones?
A. because combinations of zeros and ones can represent any numbers and characters.
B. because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.
C. because binary numbers are simplest.
D. because binary numbers are the bases upon which all other number systems are built.

1.5  One byte has ________ bits.
A. 4
B. 8
C. 12
D. 16

1.6  One gigabyte is approximately ________ bytes.
A. 1 million
B. 10 million
C. 1 billion
D. 1 trillion

Section 1.2.3 Memory
1.7  A program and its data must be moved into the computer's _______ before they can be executed by the CPU.
A. memory
B. hard disk
C. CPU
D. CD-ROM

Section 1.2.4 Storage Devices
1.8  A computer's _______ is volatile; that is, any information stored in it is lost when the system's power is turned off.
A. memory
B. hard disk
C. flash stick
D. CD-ROM

1.9  Which of the following are storage devices? Please select all that apply.
A. portable disk
B. hard disk
C. flash stick
D. CD-ROM

Section 1.2.5 Input and Output Devices
1.10  The ____________ specifies the number of pixels in horizontal and vertical dimensions of the display device.
A. screen resolution
B. pixel
C. dot pitch
D. monitor

Section 1.2.6 Communications Devices
1.11  ____________ is a device to connect a computer to a local area network (LAN).
A. Regular modem
B. DSL
C. Cable modem
D. NIC

Section 1.3 Programming Languages
1.12  ____________ are instructions to the computer. Please select all that apply.
A. Hardware
B. Software
C. Programs
D. Keyboards

1.13  Computer can execute the code in ____________.
A. machine language
B. assembly language
C. high-level language
D. none of the above

1.14  ___________ translates high-level language program into machine language program.
A. An assembler
B. A compiler
C. CPU
D. The operating system

Section 1.4 Operating Systems
1.15  ____________ is an operating system.
A. Java
B. C++
C. Windows
D. Visual Basic
E. Ada

1.16  _____________ is a program that runs on a computer to manage and control a computer's activities.
A. Operating system
B. C++
C. Modem
D. Interpreter
E. Compiler

Section 1.5 History of C++
1.17  ________ is not an object-oriented programming language.
A. Java
B. C++
C. C
D. C#
E. Python

Section 1.6 A Simple C++ Program
1.18  Every statement in C++ ends with ________, which is called a statement terminator.
A. a semicolon (;)
B. a comma (,)
C. a period (.)
D. an asterisk (*)

1.19  ___________ is called a stream insertion operator for sending output to the console.
A. a semicolon (;)
B. a comma (,)
C. a period (.)
D. an asterisk (*)
E. <<

1.20  What is the output of the following code?

  cout << "1 + 2 + 3" << endl;
  cout << 1 + 2 + 3 << endl;
A. 1 + 2 + 3 followed by 6
B. "6" followed by 6
C. 1 + 2 + 3 followed by 1 + 2 + 3
D. 6 followed by 6

1.21  The main function header is written as:
A. public static void main(string[] args)
B. public int main(String[] args)
C. int main()
D. public static main(String[] args)
E. public void main(String[] args)

1.22  Which of the following statements is correct to display Welcome to C++ on the console?
A. cout << "Welcome to C++";
B. cout >> "Welcome to C++";
C. cout < "Welcome to C++";
D. cout << 'Welcome to C++';
E. System.out.print("Welcome to C++");

1.23  Which of the following statements is correct?
A. Every line in a program must end with a semicolon.
B. Every statement in a program must end with a semicolon.
C. Every comment line must end with a semicolon;
D. Every function must end with a semicolon;
E. Every preprocessor directive must end with a semicolon;

1.24  Which of the following lines is not a C++ comment? Please select all that apply.
A. /** comments */
B. // comments
C. -- comments
D. /* comments */
E. ** comments **

1.25  A block is enclosed inside __________.
A. Parentheses
B. Braces
C. Brackets
D. Quotes

1.26  The following program displays __________.

 #include <iostream>
 using namespace std;

 int main()
 {
   cout << "A";
   cout << "B";

   return 0;
 }
A. A B
B. AB
C. B A
D. BA

Section 1.7 C++ Program-Development Cycle
1.27  A preprocessor directive begins with a symbol __________.
A. <
B. >
C. @
D. #
E. *

1.28  Which of the following preprocessor directive is correct?
A. import iostream
B. #include <iostream>
C. include <iostream>
D. #include iostream

1.29  Suppose you create a C++ as follows, the source code should be stored in a file named ___________.

int main()
{

}
A. Test.c
B. Test.doc
C. Test.txt
D. Test.java
E. Any name with extension .cpp

1.30  The extension name of a C++ object file on Windows is
A. .java
B. .obj
C. .class
D. .exe

1.31  The extension name of a C++ source code file is
A. .java
B. .obj
C. .class
D. .exe
E. .cpp

1.32  C++ compiler translates C++ source code into _________.
A. Java code
B. machine code
C. C code
D. another high-level language code

Section 1.8 Programming Style and Documentation
1.33  Analyze the following code.

  I:
  #include <iostream>
  using namespace std;

  int main()
  {
    cout << "Welcome to C++" << endl;
    return 0;
  }

  II:
  #include <iostream>
  using namespace std;

  int main() { cout << "Welcome to C++" << endl; return 0; }
A. Both I and II can compile and run and display Welcome to C++, but the code in II has a better style than I.
B. Only the code in I can compile and run and display Welcome to C++.
C. Only the code in II can compile and run and display Welcome to C++.
D. Both I and II can compile and run and display Welcome to C++, but the code in I has a better style than II.

1.34  Which of the following code has the best style?

  I:
  #include <iostream>
  using namespace std;

  int main()
  {
       cout << "Welcome to C++" << endl;
    return 0;
  }

  II:
  #include <iostream>
  using namespace std;

  int main()
  {
  cout << "Welcome to C++" << endl;
  return 0;
  }

  III:
  #include <iostream>
  using namespace std;

  int main()
  { cout << "Welcome to C++" << endl;
    return 0;
  }

  IV:
  #include <iostream>
  using namespace std;

  int main()
  {
    cout << "Welcome to C++" << endl;
    return 0;
  }
A. I
B. II
C. III
D. IV

1.35  Programming style is important, because ______________. Please select all that apply.
A. a program may not compile if it has a bad style
B. good programming style can make a program run faster
C. good programming style makes a program more readable
D. good programming style helps reduce programming errors

Section 1.9 Programming Errors
1.36  If a program compiles fine, but it produces incorrect result, then the program suffers __________.
A. a compilation error
B. a runtime error
C. a logic error

1.37  The following code has __________.

  #include <iostream>
  using namespace std;

  int main()
  {
    cout << "Welcome to C++ << endl;
    return 0;
  }
A. a compile error
B. a runtime error
C. a logic error