Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
16 Cards in this Set
- Front
- Back
It has been said that C++ sits at the center of the modern programming universe. Explain this
statement. |
C++ is at the center of modern programming because it was derived from C and is the parent of Java and C#. These are the four most important programming languages.
|
|
A C++ compiler produces object code that is directly executed by the computer. True or false?
|
True, a C++ compiler produces code that can be directly executed by the computer.
|
|
What are the three main principles of object-oriented programming?
|
Encapsulation, polymorphism, and inheritance are the three guiding principles of OOP.
|
|
Where do C++ programs begin execution?
|
C++ programs begin execution at main( ).
|
|
What is a header?
|
A header contains information used by the program.
|
|
What is <iostream>? What does the following code do?
#include <iostream> |
<iostream> is the header the supports I/O. The statement includes the <iostream> header in a program.
|
|
What is a namespace?
|
A namespace is a declarative region in which various program elements can be placed. Elements declared in one namespace are separate from elements declared in another.
|
|
What is a variable?
|
A variable is a named memory location. The contents of a variable can be changed during the execution of a program.
|
|
Which of the following variable names is/are invalid?
a. count b. _count c. count27 d. 67count e. if |
The invalid variables are d and e. Variable names cannot begin with a digit or be the same as a C++ keyword.
|
|
How do you create a single-line comment? How do you create a multiline comment?
|
A single-line comment begins with // and ends at the end of the line. A multiline comment begins with /* and ends with */.
|
|
Show the general form of the if statement. Show the general form of the for loop.
|
The general form of the if:
if(condition) statement; The general form of the for: for(initialization; condition; increment) statement; |
|
How do you create a block of code?
|
A block of code is started with a { and ended with a }.
|
|
The moon’s gravity is about 17 percent that of Earth’s. Write a program that displays a table that shows Earth pounds and their equivalent moon weight. Have the table run from 1 to 100 pounds. Output a newline every 25 pounds.
|
// Show a table of Earth to Moon weights.
#include <iostream> using namespace std; int main() { double earthweight; // weight on earth double moonweight; // weight on moon int counter; counter = 0; for(earthweight = 1.0; earthweight <= 100.0; earthweight++) { moonweight = earthweight * 0.17; cout << earthweight << " earth-pounds is equivalent to " << moonweight << " moon-pounds.\n"; counter++ if(counter == 25) { cout << "\n"; counter = 0; } } return 0; } |
|
A year on Jupiter (the time it takes for Jupiter to make one full circuit around the Sun) takes about 12 Earth years. Write a program that converts Jovian years to Earth years. Have the user specify the number of Jovian years. Allow fractional years.
|
// Convert Jovian years to Earth years.
#include <iostream> using namespace std; int main() { double e_years; // earth years double j_years; // Jovian years cout << "Enter number of Jovian years: "; cin >> j_years; e_years = j_years * 12.0; cout << "Equivalent Earth years: " << e_years; return 0; } |
|
When a function is called, what happens to program control?
|
When a function is called, program control transfers to that function.
|
|
Write a program that averages the absolute value of five values entered by the user. Display the result.
|
// Average the absolute values of 5 numbers.
#include <iostream> #include <cstdlib> using namespace std; int main() { int i; double avg, val; avg = 0.0; for(i=0; i<5; i++) { cout << "Enter a value: "; cin >> val; avg = avg + abs(val); } avg = avg / 5; cout << "Average of absolute values: " << avg; return 0; } |