Test #2

Fri Nov 10, 2000

Part I - one point each

From: C++ How to Program, by H. M. Deitel and P. J. Deitel

Teacher: Dr. B.J. Shrestha

Answer the following questions from your book:

1.11: Fill in the blanks in each of the following statements:

  1. Computers process data under the control of sets of instructions called computer _________________.

  1. The six key logical units of the computer are the __________, __________, __________, __________, __________, and __________.

  1. All programs can be written in terms of three types of control structures: __________, __________, and __________.

  1. The __________ selection structure is used to execute one action when a condition is true and another action when that condition is false




Part II - 10 points

Correct the following program.

//**************************************************
//  Name:         John Doe/ Jane Doe
//  Professor:    Dr. B. J. Shrestha
//**************************************************
// This program converts a Base 10 number into
// its equivalent Base 2 number.
//**************************************************
#include <iostream.h>

int main() 

   // Storage for conversion
   int base10, bdigits[16];
   int tmpbase10, numdigits, i;

   // Input Base 10 number
   cout << "Enter base 10 number < 32000: "
   cin  >> base10;

   // Convert to Base 2
   tmpbase10 = base10;
   for ( i = 0; i < 16 && tmpbase10 != 0; i++ ) {
      bdigits[i] = tmpbase10 % 2;
      tmpbase10 /= 2.0;
   }
   numdigits = i;

   // Display conversion
   cout << base10 << " Base 10 is ";
   for ( i = numdigits - 1; i >= 0; i-- ) {
      cout << bdigits[i];
   }
   cout << " Base 2\n";

   return(0);