Introduction to Programming with C++, Third 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.

Many questions in this edition have been updated in the new edition. Please check with the publisher on the newest edition.

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

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 __________.
A. megabytes
B. gigabytes
C. megahertz
D. gigahertz

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  ____________ 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.7  ____________ are instructions to the computer.
A. Hardware
B. Software
C. Programs
D. Keyboards

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

1.9  ___________ 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.10  ____________ is an operating system.
A. Java
B. C++
C. Windows XP
D. Visual Basic
E. Ada

1.11  _____________ 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

Section1.5 History of C++
1.12  ________ is an object-oriented programming language.
A. Java
B. C++
C. C
D. C#
E. Python

Section 1.6 A Simple C++ Program
1.13  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.14  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.15  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.16  A preprocessor directive begins with a symbol __________.
A. <
B. >
C. @
D. #
E. *

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

1.18  Suppose you define a C++ as follows:

int main()
{

}

The source code should be stored in a file named
A. Test.cpp
B. Test.doc
C. Test.txt
D. Test.java
E. Any name with extension .cpp

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

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

1.21  Which of the following lines is not a C++ comment?
A. /** comments */
B. // comments
C. -- comments
D. /* comments */
E. ** comments **

1.22  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.23  ___________ 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.24  A block is enclosed inside __________.
A. Parentheses
B. Braces
C. Brackets
D. Quotes

1.25  The following program displays __________.

 #include <iostream>
 using namespace std;

 int main()
 {
   cout << 1 + 2 << endl;

   return 0;
 }
A. 1 + 2
B. 2
C. 12
D. 3
E. 1

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.8 Programming Style and Documentation
1.27  Programming style is important, because ______________.
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

1.28  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.29  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

Section 1.9 Programming Errors
1.30  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