Test #1
Fri, NOV 3, 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.10: Categorize each of the following items as either hardware
or software:
- _______________ CPU
- _______________ C++ compiler
- _______________ ALU
- _______________ C++ preprocessor
- _______________ input unit
- _______________ an editor program
1.12: Fill in the blanks in each of the following statements:
- Which logical unit of the computer receives information from outside
the computer for use by the computer? _________________
- The process of instructing the computer to solve specific problems is
called _________________.
- What type of computer language uses English-like abbreviations for
machine language instructions? _________________
- Which logical unit of the computer sends information that has already
been processed by the computer to various devices so that the information
may be used outside the computer? _________________
- Which logical unit of the computer retains information? _________________
- Which logical unit of the computer performs calculations? _________________
- Which logical unit of the computer makes logical decisions? _________________
- The level of computer language most convenient to the programmer for
writing programs quickly and easily is _________________.
- The only language that a computer can directly understand is
called that computer's _________________.
- Which logical unit of the computer coordinates the activities of all the
other logical units? _________________
Part II - 2 points each
Show all work in converting the number.
Use the program in Part III to verify your answers.
- Convert the binary number 1110011 to decimal.
- Convert the decimal number 98 to binary.
Part III - 10 points
Compile and execute the following program.
Turn in the program hardcopy (printout) stapled to the above
questions (answered).
//**************************************************
// Name: John Doe/ Jane Doe
// Assignment: #1
// 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;
}
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);
}