PROGRAMMING FINAL EXAM

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What symbol is used as a modulo, and what does it do?

% and it returns remainder

What is the output of the following code? for(int i = 0; i < 100; i+= 15) { cout << i << endl; }

0, 15, 30, 45, 60, 75, 90

What will the following program segment display? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10; serious = 10; } else { funny = 1; serious = 1; } cout << funny << " " << serious << endl;

1 1

What is the value of x after the following code executes? int x=10; if(x++ >10) { x =13; } a. 9 b. 11 c. 13 d. 10

11

What is the output of the following segment of code if the value 4 is input by the user when asked to enter a number? int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 4: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout << total << endl;

13

After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time? cin >> input_value; if (input_value > 5) input_value = input_value + 5; else if (input_value > 2) input_value = input_value + 10; else input_value = input_value + 15;

15

What will be the value of result after the following code has been executed? int a = 60; int b = 15; int result = 10; if (a = b) result *= 2;

20

What is the output of the following code? int i = 30; while(i > 15) { i -= 3; cout << i << endl; }

27, 24, 21, 18, 15

Given the following code segment, what is output after "result = "? int x = 1, y = 1, z = 1; y = y + z; x = x + y; cout << "result = " << (x < y ? y : x) << endl;

3

What is the output of the following code? (assume the user enters 2 characters, A and L separated by a space: A L) char myChar; cin >> myChar; cout << myChar;

A

What is the difference between a while loop and a do....while loop?

A do while loop will run at least one

What is an algorithm?

A set of well-defined logical steps that must be taken to perform a task.

Who was the programmer for Charles Babbage's analytical engine?

Ada Lovelace

The stages in the software design life cycle are (in oder)

Analysis, design, implementation, testing, maintenance, and obsolescence

Input values should always be checked for:

Appropriate range, reasonableness, and division by zero, if division is taking place.

Who developed C++?

Bjarne Stroustrup

Which of the following is not a legal way to declare an enumeration type? a. enum Number {FIRST, SECOND, THIRD, FOURTH}; b. enum Number{FIRST = 3, SECOND = 4, THIRD = 77, FOURTH = 88}; c. enum Number{1 = FIRST, 2 = SECOND, 3 = THIRD, 4 = FOURTH}; d. enum Number{FIRST = 3, SECOND = 4, THIRD, FOURTH};

C

The most recent standardized version of C++ is called:

C++ 11

What will the following segment of code output if the value 11 is entered at the keyboard? int number; cin >> number; if (number > 0) cout << "C++"; else cout << "Soccer"; cout << " is "; cout << "fun" << endl;

C++ is fun

The anagram CPU stands for

Central Processing Unit

T or F: The compiler will catch all your programming mistakes

False

If you place a semicolon after the statement: if (x < y)

The compiler will interpret the semicolon as a null statement.

What does the following line of code display to the screen? cout << "This is the computer\n programming book\n";

This is the computer programming book

The purpose of the statement: using namespace std; is:

To tell the compiler to use the keywords in the standard way

T or F: Object Oriented programming means breaking down a program into classes which interact with each other as objects

True

T or F: The following code will format a double to 2 decimal places: cout.setf(ios::fixed); cout.seft(ios::showpoint); cout.precision(2);

True

What will the following segment of code output? Assume the user enters a grade of 90 from the keyboard. cout << "Enter a test score: "; cin >> test_score; if (test_score < 60); cout << "You failed the test!" << endl; if (test_score > 60) cout << "You passed the test!" << endl; else cout << "You need to study for the next test!";

You failed the test! You passed the test!

Given the following code fragment and the input value of 2.0, what output is generated? float tax; float total; cout << "enter the cost of the item\n"; cin >> total; if ( total >= 3.0) { tax = 0.10; cout << total + (total * tax) << endl; } else { cout << total << endl; } a. 2.0 b. 3.1 c. 2.2 d. 4.4

a

Given the following enumerated data type definition, what is the value of SAT? enum myType{SUN=3,MON=1,TUE=3,WED,THUR,FRI,SAT,NumDays}; a. 7 b. 6 c. 5 d. unknown e. 8

a

If you want a loop to quit iterating if x < 10 and y > 3, what would be the proper loop condition test? a. (x>=10 || y<=3) b. (x>10 || y<3) c. (x>=10 && y<=3) d. (x < 10 && y > 3)

a

What is the output of the following code? for(int i = 0; i < 10; i++) { cout << i; } a. 0123456789 b. This is an inf loop c. 123456789 d. there is no output

a

What is the value of x after the following code executes? int x=10; if(++x >10) { x =13; } a. 13 b. 9 c. 11 d. 10

a

What is the value of x after the following statements? int x; x = 15 %4; a. 3 b. 15 c. 4 d. 3.75

a

Given the following code, what is the value of i? int i; i = 7/4.0; a. 1 b. 2 c. 1.75 d. 3.0

a. 1

An_______ is a set of instructions for performing a task

algorithm

Given the following code fragment, what is the final value of y? int x, y; x = -1; y = 0; while(x <= 3) { y += 2; x += 1; } a. 8 b. 10 c. 2 d. 6

b

Given the following code fragment, which of the following expressions is always true? int x; cin >> x; a. if( (x/3) > 1) b. if(x = 1) c. if(x<3) d. if(x==1)

b

Given the following enumerated data type definition, what is the value of SAT? enum myType{SUN,MON,TUE,WED,THUR,FRI,SAT,NumDays}; a. 5 b. 6 c. unknown d. 8 e. 7

b

If you need a function to get both the number of items and the cost per item from a user, which would be a good function declaration to use? a. void getData(int count, float cost); b. void getData(int& count, float& cost); c. int getData(float cost); d. int,float getData();

b

What is the output of the following code fragment if x is 15? if(x < 20) if(x <10) cout << "less than 10 "; else cout << "large\n"; a. no output, syntax error b. large c. less than 10 d. nothing

b

What is the value of the following expression? (true && (4/3 || !(6))) a. false b. true c. illegal syntax c. 0

b

What is the value of x after the following statement? float x; x = 3.0 / 4.0 + 3 + 2 / 5; a. 6.75 b. 3.75 c. 5.75 d. 1.75

b

Which of the following data types can be used in a switch controlling expression? a. double b. a, b and d c. all of the above d. a and b e. enum f. d and e g. int h. char

b

Which of the following statements is NOT legal? a. char ch='0'; b. char ch="cc"; c. char ch='b'; d. char ch=65;

b

Given the following code, what is the value of i? const double i = 3.0; i = 7/4.0; a. 1.75 b. will not compile c. 1 d. 3.0

b. will not compile

A variable that evaluated to either true of false is a_____

bool

Given the following code fragment, and an input value of 3, what is the output that is generated? int x; cout <<"Enter a value\n"; cin >> x; if(x=0) { cout << "x is zero\n"; } else { cout << "x is not zero\n"; } a. x is 3 b. unable to determine c. x is not zero d. x is zero

c

If a programming language does not use short-circuit evaluation, what is the output of the following code fragment if the value of myInt is 0? int other=3, myInt; if(myInt !=0 && other % myInt !=0) cout << "other is odd\n"; else cout << "other is even\n"; a. other is even b. 0 c. run-time error, no output d. other is odd

c

What would be the output of the following code? int myInt = 30; if(myInt > 20 { cout << "I have "; } if(myInt >= 30) { cout << "The power "; } else { cout << "of Greyskull "; } a. I have the greyskull b. I have the power c. I have the power of greyskull d. The power of greyskull

c

When testing a program with a loop, which of the following tests should be done? a. no iterations of the loops b. one less than the maximum number of iterations c. A, B and D d. the maximum number of iterations e. A and B f. one more than the maximum number of iterations

c

Which of the following is not a phase of the program-design process? a. Problem-solving b. Implementation c. Marketing the final program

c

Which of the following is not a valid identifier? a. total3 b. myInt c. return d. myInteger

c

If you have the following declaration in your program, const int SIZE = 34; which of the following statements are legal? a. SIZE++; b. x = SIZE--; c. cout << SIZE; d. cin >> SIZE;

c. cout << SIZE;

What type of evaluation does c++ use when checking multiple expressions joined by && or ||? a. complete evaluation b. comparative evaluation c. short circuit evaluation d. boolean evaluation

c. short circuit evaluation

Relational operators allow you to ________ numbers.

compare

Software that translates high-level languages into low-level languages is called a_______

compiler

A(n)______ is used to make a decision or end a loop. It can be evaluated to true or false

condition

Given the following code fragment, what is the final value of y? int x, y; x = -1; y = 0; while(x < 3) { y += 2; x += 1; } a. 10 b. 6 c. 2 d. 8

d

Given the following code fragment, what is the output? int x=5; if( x > 5) cout << "x is bigger than 5. "; cout <<"That is all. "; cout << "Goodbye\n"; a. x is bigger than 5 b. x is bigger than 5. That is all c. Goodbye d. That is all. Goodbye

d

Given the following code, what is the final value of i int i,j; for(i=0;i<4;i++) { for(j=0;j<3;j++) { if(i==2) break; } } a. 3 b. 5 c. 7 d. 4

d

What is the output of the following code? cout << "This is a \\" << endl; a. nothing, it is a syntax error b. This is a \ endl c. This is a d. This is a \

d

What is the output of the following function and function call? void calculateCost(int count, float& subTotal, float& taxCost); float tax = 0.0; subTotal = 0.0; calculateCost(15, subTotal,tax); cout << "The cost for 15 items is " << subTotal << ", and the tax for " << subTotal << " is " << tax << endl; //end of fragment void calculateCost(int count, float& subTotal, float& taxCost) { if ( count < 10) { subTotal = count * 0.50; } else { subTotal = count * 0.20; } taxCost = 0.1 * subTotal; } a. The cost for 15 items is 3.00, and the tax for 3.00 is 0.00; b. The cost for 15 items is 0.00, and the tax for 3.00 is 0.30; c. The cost for 15 items is 0.00, and the tax for 3.00 is 0.00; d. The cost for 15 items is 3.00, and the tax for 3.00 is 0.30;

d

What is the value of x after the following statements? float x; x = 15/4; a. 3.75 b. 4.00 c. 60 d. 3.0

d

What is the value of x after the following statements? int x; x = 15/4; a. 4 b. 15 c. 3.75 d. 3

d

Which of the following are equivalent to (!(x<15 && y>=3))? a. (x>=15 && y<3) b. (x>15 || y<3) c. (x>15 && y<=3) d. (x>=15 || y<3)

d

What is the output of the following code? int first = 10; int second = 8; cout << first % second; a. 1 b. 8 c. 10 d. 2

d. 2

Given the following code, what is the value of i? double i; I = 10/4; a. 1 b. 2 c. 3 d. 2.5

d. 2.5

What is the output of the following code? int counter = 1; int apples = 6; while(counter > 5) { cout << counter * apples << " "; } a. 6 12 18 24 b. This is an inf loop c. 1234 d. There is no output

d. There is no output

There are_____bytes in a bit a. 64 b. 8 c. 4 d. None of the above

d. none of the above

When you create and name a variable it is called a_______

declaration

Which of the following function prototypes are not valid? a. all are not valid b. void doSomething(int& x, int y); c. void doSomething( int& x, int& y); d. void doSomething( int x, int y); e. all are valid

e

Is the following expression true or false? int first = 36; int second = 28; if(first < 50 && second > 27 && second > first && first > 28)

false

T or F: A break statement in a switch stops your program

false

T or F: An algorithm is always written in C++

false

T or F: In an enumerated data type, different constants may not have the same value

false

T or F: Main memory holds its data if the computer is turned off.

false

What is the value of the following expression? true && false

false

What will be the output of the following code segment after the user enters 0 at the keyboard? int x = -1; cout << "Enter a 0 or a 1 from the keyboard: "; cin >> x; if (x) cout << "true" << endl; else cout << "false" << endl;

false

This is a variable, usually a bool or an int, that signals when a condition exists.

flag

What does the following code print to the screen? cout << "hello";

hello

C++ is an example of a

high-level language

A________directive tells the compiler to link your code with a specific library

include

Code executed multiple times is contained within a(n)_____

loop

The context or_____tells the computer how certain keywords should be used

namespace

The output of the compiler is called

object code

It is common to write_______before you write your program to clearly illustrate the design of your program as a blueprint for you to follow

pseudocode

______is the code you write

source code

__________end with semicolons and are instructions for the computer to execute

statements

Is the following expression true or false: int first = 36; int second = 1; if(first < 50 && second && second < first && first)

true

T or F: A double is double the precision of a float

true

T or F: All switch statements can be converted into nested if-else statements

true

T or F: Functions can return at most one value.

true

T or F: It is acceptable to have both call-by-value and call-by-reference parameters in the same function declaration.

true

T or F: It is considered better style to put the braces ({}) on separate lines.

true

T or F: The && would be the output of the following conditions are true

true

T or F: The body of a do-while loop always executes at least once.

true

T or F: The following is legal in a void function return;

true

T or F: You should write your program before you write the algorithm.

true

What is the value of the following expression? true || true

true

When a relational expression is false, it has the value ________.

zero


Set pelajaran terkait

Chapter 29: Origins of the Cold War

View Set

Finance 342 Chapter 9 Concept Questions

View Set

Group Fitness Instructor Exam Study Notes and Terminology Part 1

View Set

chapter 8 performance Management and appraisal

View Set

AP Psych Final, AP Psych Midterm

View Set

Infections of the Central Nervous System

View Set