Midterm Review #1

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which one of the following code snippets compiles without errors and displays the output "hello" on the screen?

#include <iostream> using namespace std; int main() { cout << "hello" << endl; return 0; }

Which one of the following operators computes the remainder of an integer division?

%

Which one of the following code snippets compiles without errors and displays the output "Hello world" on the screen?

#include <iostream> using namespace std; int main() { cout << "Hello world" << endl; return 0; }

Which is the appropriate time to initialize a variable?

when you define it

Programs that are not running are usually stored

in secondary storage.

Which operator is used to concatenate two or more strings?

+

What is the output of the following code snippet? #include <iostream> #include <string> using namespace std; int main() { int num1 = 10; int num2 = 5; int num3 = 200; num3 = num3 % (num1 * num2); cout << num3 << endl; return 0; }

0

Evaluate the given pseudocode to calculate the payment (pmt) with the following test values: The total number of hours worked (working_hours) = 60 The rate paid for hourly work (rate) = 15 input working_hours input rate pmt = working_hours * rate if working_hours > 40 then extra_hours = working_hours - 40 extra_pmt = extra_hours * rate * 2 pmt = pmt + extra_pmt end of if output pmt

1,500

What output is produced by these statements? string city = "Rio de Janeiro"; cout << city.length();

14

What is the output of this code snippet? int sum = 22; sum = sum + 2; cout << sum++; // sum = sum + 4; cout << sum;

2425

What is the output of the following code snippet? #include <iostream> using namespace std; int main() { int value = 3; value++; cout << value << endl; return 0; }

4

What is the output of the following code snippet? #include <iostream> using namespace std; int main() { int value = 25; value = value * 2; value--; cout << value << endl; return 0; }

49

What is the value of pow(2, 3)?

8

string name = "Joan Hunt"; cout << name.length();

9

A single silicon chip made from potentially millions of transistors is called

A Central Processing Unit (CPU)

What is a logic error?

An error that occurs when a program is running because, for example, the wrong operator was used.

What name do you use for small computers that are programmed to control automobile engines and cell phones?

Embedded systems

What is the output of the following code snippet? string firstname = "William"; string lastname; cout << "First: " << firstname << endl; cout << "Last: " << lastname << endl;

First: William Last:

Which of the following are NOT types of code used by an IDE?

Native code

An if statement inside another if statement is called a

Nested if statement

Is there any error in the following code snippet, which is used for calculating the average age for a group of three students? #include <iostream> int main() { int age1 = 15; int age2 = 18; int age3 = 24; int average = (age1 + age2 + age3) / 3; cout << "The average is " << average; return 0; }

No error; the code snippet is completely accurate.

Consider the following statements about folders and your integrated development environment (IDE): I. Hierarchical folders help to organize a project II. Folders are a way to visualize the layout of a file system III. Folders make it impossible to lose or accidentally delete a file

Only I and II are correct

Which one of the following is defined as a sequence of characters?

String

Assuming that the user inputs a value of 25 for the price and 10 for the discount rate in the following code snippet, what is the output? int main() { cout << "Enter the price: "; double price; cin >> price; cout << "Enter the discount rate: "; double discount; cin >> discount; cout << "The new price is " << price - price * (discount / 100.0) << endl; return 0; }

The new price is 22.5

An example of an output device that interfaces between computers and humans is

The speaker

What, if any, is the syntax error in the following statement? double result = (-(b * b - 4 * a * c) / pow(a,2);

There are unbalanced parentheses

What is the output of the following code snippet? #include <iostream> #include <string> using namespace std; int main() { int var1 = 10; int var2 = 2; int var3 = 20; var3 = var3 / (var1 % var2); cout << var3 << endl; return 0; }

There will be no output due to a run-time error.

What is the purpose of the following algorithm? num = 0 Repeat the following steps 10 times input var1 if var1 > num then num = var1 end of if end of repeat print num

To find the highest among 10 numbers

What is the purpose of the following algorithm? somenum = 0 Repeat the following steps 50 times input variable1 if variable1 > somenum then somenum = variable1 end of if end of repeat print somenum

To find the highest among 50 numbers

What is the output of the following code snippet? int main() { string str1; str1 = "I LOVE MY COUNTRY"; string str2 = str1.substr(4, 5); cout << str2 << endl; return 0; }

VE MY

Which one of the following is an assignment statement?

a = 20;

In an airline reservation system, the number of available seats in an airplane is required. Which data type should be used to store this value?

int

In an airline reservation system, the cost of an airline ticket is required. Which data type should be used to store this value?

double

The instruction "1011 0011" for a computer is an example of

machine language.

Consider the following C++ statement: string name = "Harry"; Which of the following is true?

name is a string variable.

What are the values of num1 and num2 after this snippet executes? double num1 = 4.20; double num2 = num1 * 10 + 5.0;

num1 = 4.20 and num2 = 47.0

Given the definition const double PI=3.14159; which of the following is the C++ equivalent of the mathematical expression p = 2· p·(radius)3

p = 2 * PI * pow(radius, 3);

An algorithm should be written first in:

pseudocode.

Assuming that the user enters 23 and 45 as inputs for num1 and num2, respectively, what is the output of the following code snippet? #include <iostream> #include <string> using namespace std; int main() { cout << "Enter a number: "; string num1; cin >> num1; cout << "Enter another number: "; string num2; cin >> num2; string final = num1 + num2; cout << final << endl; return 0; }

2345

What is result of evaluating the following expression? 1 + 2 * 3 - 4

3

Assuming that a user enters 10, 20, and 30 as input values one after another, separated by spaces, what is the output of the following code snippet? int main() { int num1; int num2; int num3 = 0; cout << "Enter a number: "; cin >> num1; cout << "Enter a number: "; cin >> num2; cout << "Enter a number: "; cin >> num3; if (num1 > num2) { if (num1 > num3) { cout << num1 << endl; } else { cout << num3 <<endl; } } else { if (num2 > num3) { cout << num2 << endl; } else { cout << num3 << endl; } } return 0; }

30

Assuming that the user enters 45 and 62 as inputs for n1 and n2, respectively, what is the output of the following code snippet? #include <iostream> #include <string> using namespace std; int main() { cout << "Enter a number: "; string n1; cin >> n1; cout << "Enter another number: "; string n2; cin >> n2; string result = n1 + n2; cout << result << endl; return 0; }

4562

Evaluate the given pseudocode to calculate the payment (pmt) with the following test values: The total number of hours worked (working_hours) = 50 The rate paid for hourly work (rate) = 10 input working_hours input rate pmt = working_hours * rate if working_hours > 45 then extra_hours = working_hours - 45 extra_pmt = extra_hours * rate * 2 pmt = pmt + extra_pmt end if output pmt Select one:

600

What is the output of the following code snippet? int main() { double a; a = sqrt(9.0) + sqrt(16.0); cout << a << endl; return 0; }

7.0

What type of error can you identify in the following code snippet? #include <iostream> int main { int a = 10; int b = 20; int c = a + b; return 0; }

A syntax error.

What is the difference between an editor and a compiler?

An editor allows program files to be written and stored; a compiler converts program files into an executable program

An integrated development environment (IDE) bundles tools for programming into a unified application. What kinds of tools are usually included?

An editor and a compiler

High level programming languages

Are independent of the underlying hardware

What kind of error is it when your program has a syntax error?

Compile-time error

Which one of the following translates high-level descriptions into machine code?

Compiler

Consider a situation where you are assigned to develop an algorithm to calculate the total cost of a purchase order that contains several items. The cost of each item and the tax rate is known. The standard shipping charge for the entire order is $4.95, and the special delivery charge is $19.95. In addition, there is no tax on the shipping cost. Which of the following is the correct pseudocode for the required algorithm?

For each item on the purchase order: Order cost = order cost + item cost If standard shipping Shipping cost = 4.95 Else Shipping cost = 19.95 Total purchase order cost = order cost * tax rate + shipping cost

Computer scientists have devised something that allows programmers to describe tasks in words that are closer to the syntax of the problems being solved. This is called

High level programming language

What statements about the integrated development environment (IDE) are true? I. You may run an executable program even after exiting the IDE II. The IDE contains a program called the linker, which is required to build an executable program III. Translating C++ source code into machine code is not enough to actually run the program

I, II, III

Given int apples = 5; Which line(s) of code are the equivalent of: apples += 1; I. apples = apples; II. apples = apples + 1; III. apples++;

II and III

Consider the given scenario for describing an algorithm using pseudocode. UML Supermarket has different ways of awarding discounts to its customers for each purchase they make. A 10% discount is given on the total value of the purchase. In addition, a standard loyalty discount is given if customers have a permanent customer card. Your program should indicate the amount payable by the customer after the discounts. Identify the inputs that the program requires from the given set of options. I. The discount percentage II. The total value of the purchase III. The loyalty-discount amount IV. The customer card number V. The amount payable after discount

II and IV

Consider the given scenario for describing an algorithm using pseudocode. WALMART Supermarket has different ways of awarding discounts to its customer IDs for each purchase they make. An 8% discount is given on the total value of the purchase. In addition, a standard loyalty discount is given if customers have a permanent customer ID card. Your program should indicate the amount payable by the customer after the discounts. Identify the inputs that the program requires from the given set of options. I. The discount percentage II. The total value of the purchase III. The loyalty-discount amount IV. The customer ID card number V. The amount payable after discount

II and IV

Which one of the following typically provides data persistence without electricity? I. The CPU's memory II. The hard disk III. Secondary storage

II, III

Consider the following statements about computer programs: I. Computer programs can be written by someone who has a basic knowledge of operating a computer. II. Computer programs can complete complex tasks quickly. III. Large and complex computer programs are generally written by a group of programmers. IV. Computer programs are composed of extremely primitive operations. Which one of the following options is correct?

II, III, and IV are correct statements.

What is wrong with this algorithm for sorting a deck of playing cards according to suit? Pick up the top card from the deck Put it into the pile corresponding to its suit (heart, diamond, spade, club) Repeat

It is not terminating.

What is the meaning of num = 10; in C++?

It sets the variable num to ten.

What is the meaning of x = 0; in C++?

It sets the variable x to zero.

Assuming that the user inputs "Joel" at the prompt, what is the output of the following code snippet? #include <iostream> #include <string> using namespace std; int main() { cout << "Enter your name "; string name; cin >> name; name += ", Good morning"; cout << name << endl; return 0; }

Joel, Good morning

Which one of the following programs combines the machine code with the library code to build an executable file?

Linker

What kind of error is created by the following code snippet? cout << "The sum of 8 and 12 is " << 8 * 12 << endl;

Logic error: the program does not produce the desired result

Consider the following division statements: I. 22 / 7 II. 22.0 / 7 III. 22 / 7.0 IV. 22.0 / 7.0 Which of the following options is correct?

Only I will return an integer value.

Consider the following C++ variable names: I. 1st_instance II. basic_in_$ III. _emp_name_ IV. address_line1 V. DISCOUNT Which of the following options is correct?

Only III, IV, and V are valid C++ variable names.

What is one of the benefits of using a high-level programming language like C++?

Problems solved in a high-level language are independent of the underlying computer hardware

Consider a scenario in which you develop a C++ program on a computer that has a Pentium processor and compile the program into the corresponding machine language. What step should you take to run the same program on a computer that has a different processor?

Recompile the C++ program on the computer that has a different processor.

The programmer, not the compiler, is responsible for testing a program to identify

Run-time errors

What kind of error is created by the following code snippet? coutt << "Hello, World!" << endl;

Syntax error: the program will not compile

Which one of the following errors represents a part of a program that is incorrect according to the rules of the programming language?

Syntax errors

How do programmers find exceptions and run-time errors?

Testing the compiled program with a variety of input values

Computer programming is

The act of designing and implementing a computer program

What is the problem with the following algorithm? Repeat a number of times Add sales amount to total sales.

The algorithm is ambiguous because it does not specify how many times to repeat the Add statement.

What is the error in the following code snippet, which is used for calculating the average score for a student in three subjects? #include <iostream> int main() { int subject1 = 75; int subject2 = 65; int subject3 = 70; int average = subject1 + subject2 + subject3 / 3; cout << "The average is " << average; return 0; }

The code snippet has a logic error.

What is the output of the following code snippet? int counter = 0; counter++; cout << "The initial value of the counter is " << count << endl;

The code will not compile

When a compiler finds a syntax error in a program, what happens?

The compiler continues and may report about other errors but does not produce an executable file.

What is result of evaluating the following expression? (45 / 6) % 5

The correct answer is: 2

Consider a situation where you are planning on purchasing a new cable TV dish. You are considering two cable TV dishes. These cable TV dishes have different purchase prices. Each channel service provider charges a different rate for each month that the cable TV dish is used. To determine which cable TV dish is a better buy, you need to develop an algorithm to calculate the total cost of purchasing and using each cable TV dish. What are all of the inputs that you need for this algorithm?

The cost of each cable TV dish, the rate per month for using each cable TV dish, and the number of months you would use the cable TV dish

Consider a situation where you are planning on purchasing a new cell phone. You are considering two cell phones. These cell phones have different purchase prices. Each mobile service provider charges a different rate for each minute that the cell phone is used. To determine which cell phone is the better buy, you need to develop an algorithm to calculate the total cost of purchasing and using each cell phone. What are all the inputs needed for this algorithm?

The cost of each cell phone, the rate per minute for each cell phone, and the number of minutes you would use the cell phone

Say you are writing an algorithm to arrange tiles to fill a rectangular floor with alternating black and white tiles. What would be the required inputs to the algorithm?

The length and width of the floor and of the tiles

An example of an input device that interfaces between computers and humans is

The microphone

Consider a situation where you are buying books online. The bookseller charges $19.95 as the price per book and $4.95 as the handling cost for up to three books. For every book purchased in addition to three books, there is a handling charge of $1.50. In addition, there is a 7% tax on the cost of the books but not on the handling charges. Assuming that num_books represents the number of books you are purchasing, which of the following is the correct algorithm for calculating the total cost of the books that you are purchasing?

Total charge for the books = 4.95 * num_books Tax on the books = Total charge for the books * .07 if (books <= 3) then Handling charges = 4.95 else Handling charges = 4.95 + 1.50 * (num_books - 3) Total cost of order = total charge for books + tax + handling charges

Consider a situation where you are buying videos online. The video seller charges $21.50 as the price per video and $6.75 as the handling cost for up to three videos. For every video purchased in addition to three videos, there is a handling charge of $1.50. In addition, there is a 9% tax on the cost of the videos but not on the handling charges. Assuming that num_videos represents the number of videos you are purchasing, which of the following is the correct algorithm for calculating the total cost of the videos that you are purchasing?

Total charge for the videos = 21.50 * num_videos Tax on the videos = total charge for videos * .09 if (num_videos <= 3) then Handling charges = 6.75 else Handling charges = 6.75 + 1.50 * (num_videos - 3) Total cost of order = total charge for videos + tax + handling charges

What is the output of this code snippet? double average; int grade1 = 87; int grade2 = 94; // cout << "The average is " << (grade + grade2) / 2.0 << endl; cout << "The average is " << average << endl;

Unpredictable result

Given the definition const double PI = 3.14159; which of the following is the C++ equivalent of the mathematical expression c = p·radius2

c = PI * pow(radius, 2)

A network controller is the device in a computer that

connects the computer to the internet or other network through a wire or wireless.

Which of the following statements represents a logic error, but not a compile-time error?

cout << "The sum of 5 and 6 is 10" << endl;

Which of the following statements would generate a compile-time error?

cout << eleven << endl;

Which of the following options defines a double variable?

double age;

A store applies a 15% service charge on all items with a price of at least $150. No service charge is otherwise applicable. Which of the following statements DOES NOT correctly compute the service charge?

double service_charge = 0.15 * cost; if (cost <= 150) { service_charge = 0; }

What is the difference between the float and double types in C++?

double usually takes twice as many bytes of memory storage as float.

Computers are machines that

execute programs

Which of the following options defines an integer variable?

int age;

What is the result of the following snippet? int son_age = 5; int father_age = son_age * 3 + 5;

son_age = 5 and father_age = 20

How do you compute the length of the string str?

str.length()

How do you extract first 5 characters from the string str?

str.substr(0, 5)

Characters that are grouped together between double quotes (quotation marks) in C++ are called

strings


Kaugnay na mga set ng pag-aaral

Chapter 17 Law Final Study Guide

View Set

Chapter 15 Drugs Affecting Inflammation and Infection

View Set

catherine's lines - proof scene 4

View Set

Computer Terms in TLE/Computer 6

View Set

Chapter 4 ACCT (Extra credit/Concept videos)

View Set

Chapt 15 Christianity & The Formation of Europe

View Set