Computer Programming

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

The simple program below has syntax errors. Your job is to state each error and how to fix it. #include "pch.h" // this line is only needed in Visual Studio Community 2017 #include <iostream> using namespace std; int main() cout << "Programming is fun!" << endl return 0; }

#include "pch.h" // this line is only needed in Visual Studio Community 2017 #include <iostream> using namespace std; int main() { // syntax error: the opening curely brace was missing cout << "Programming is fun!" << endl; // syntax error: semi colon ; was missing return 0; }

We have the following program that would display an appropriate message to the user depending on the user's score in an exam. Your job is to complete the rest of the program.. #include <iostream> using namespace std; int main() { //declare variables int score; // get the score from the user cout << "Enter score: "; cin >> score; // Decide and display an appropriate message: display message // "Excellent" when score is 90 or higher, // "Good" when score is between 80 and 89, and // "Try Harder" when score is less than 80. // .... COMPLETE THIS PART .... system("pause"); return 0; }

#include <iostream> using namespace std; int main() { //declare variables int score; // get the score from the user cout << "Enter score: "; cin >> score; // Decide and display an appropriate message: display message // "Excellent" when score is 90 or higher, // "Good" when score is between 80 and 89, and // "Try Harder" when score is less than 80. if (score >= 90) cout << "Excellent" << endl; else if (score >= 80) cout << "Good" << endl; else cout << "Try harder" << endl; system("pause"); return 0; }

In the following code, suppose the user enters input num as 10 20 5 0 -1 as loop executes. What is the output of the following code ? int sum, num; sum = 0; cin >> num; while (num != -1) { sum = sum + num; cin >> num; } cout << sum << endl;

35

What is the output of the following C++ code ? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y - x; cout << x << " " << y << " " << z << endl;

35 45 10

What is the output of the following code if variable lastInital is set to 'S'; switch (lastInitial) { case 'A': cout << "100"; break; case 'B': cout << "200"; break; case 'C': cout << "300"; break; case 'D': cout << "400"; break; default: cout << "500"; }

500

The expression 5 % 2 evaluates to A) 1 B) 2 C) 2.5 D) 5.2 E) 10

A) 1

The ________ object causes data to be input from the keyboard. A) cin B) cout C) keyboard buffer D) standard input E) dataIn

A) Cin

In the C++ statement pay = rate * hours; the * symbol is an example of A) an operator. B) an operand. C) a variable separator. D) syntax. E) none of the above.

A) an operator.

Which of the following will cause the next output to begin on a new line? A) cout << endl; B) cout << "endl"; C) cout << "/n"; D) All of the above E) A and C, but not B

A) cout << endl;

________ is used in a C++ program to mark the end of a statement, or to separate items in a list. A) A separator B Punctuation C) An operator D) A keyword E) A blank space

B) Punctuation

In a C++ program, two slash marks ( // ) indicate the beginning of A) a block of code. B) a comment. C) a variable definition. D) a program. E) none of the above.

B) a comment.

The bool data type A) can be used to store a single character. B) has only two values: true and false. C) is used to store extra-large numbers. D) is used to represent numbers in E notation. E) does none of the above.

B) has only two values: true and false.

To use the sqrt() function, or other mathematical library functions, you must #include the ________ header file in your program A) iostream B) iomanip C) cmath D) algebra E) mathlib

C) cmath

Words with a special meaning that may be used only for their intended purpose are known as A) single purpose words. B) programmer-defined identifiers. C) keywords. D) syntax words. E) none of the above.

C) keywords.

A sentinel is a special value that A) is used for data validation. B) must be Boolean. C) marks the end of a list of values. D) must be a negative number. E) is all of the above.

C) marks the end of a list of values

A(n) ________ is a set of instructions that tells the computer how to solve a problem A) compiler B) linker C) program D) perator E) variable

C) program

A(n) ________ is a set of instructions that tells the computer how to solve a problem. A) compiler B) linker C) program D) operator E) variable

C) program

Creating a program requires many steps. Three of these are A) input, processing, and output. B) keywords, operators, and punctuation. C) program design, writing source code, and testing. D) syntax, logic, and error handling. E) none of the above.

C) program design, writing source code, and testing.

The statements written by a programmer are called A) syntax. B) object code. C) source code. D) language elements. E) none of the above.

C) source code.

How many lines with "Hello" will be printed on the screen as a result of executing the following do-while loop int i = 5; do { cout << "Hello " << endl; i--; } while (i >= 0); A. 0 B. 5 C. 6 D. 7 E. infinite

C. 6

The ________ operator is used in C++ to test for equality A) = B) <> C) && D) == E) ||

D) ==

What will the following expression evaluate to? ! ( 6 > 7 ) A) 0 B) -1 C) 6 D) true E) false

D) True

Every C++ program must have A) comments. B) variables. C) literals. D) a function called main. E) all of the above.

D) a function called main.

An integrated development environment (IDE) normally includes A) a text editor. B) a compiler. C) a debugger. D) all of the above. E) none of the above.

D) all of the above

A set of well-defined steps for performing a task or solving a problem is known as A) a hierarchy chart. B) a flowchart. C) a solution engine. D) an algorithm. E) software engineering.

D) an algorithm.

In C++, a value can be raised to a power by using A) the ^ operator. B) the exp operator. C) the power operator. D) the pow function. E) the square function.

D) the pow function.

The C++ ________ operator represents logical AND. A) ++ B) .AND. C) || D) & E) &&

E) &&

Which of the following keywords is/are the names of C++ data types? A) short B) long C) double D) bool E) All of the above

E) All of the above

A storage location in the computer's memory that can hold a piece of data is called A) a variable. B) a number. C) a data cell. D) a storage box. E) RAM

E) RAM.

A ________ variable can hold only one of two values: true or false. A) binary B) single precision C) T/F D) char E) bool

E) bool

What literal(s) appear in the following C++ statement? int number = 4 + 8; A) number B) 4 C) 8 D) 12 E) both B and C

E) both B and C

The statement cout << setw(4) << num4 << " "; A) outputs the value of num4 rounded to 4 decimal places. B) outputs "setw(4)" before the value in the variable num4. C) outputs the first 4 digits of the number stored in num4. D) outputs the value stored in num4 four times. E) does none of above.

E) does none of above.

A variable of the char data type can hold a set of characters like "January".

False

A variable of the char data type can hold a value that contains a set of characters like "January". T or F

False

Executable code is computer code that contains no errors.

False

Given the following variable declaration for firstName string firstName; The following C++ statement correctly assigns the name value Albert to variable firstName firstName = 'Albert';

False

If number is an int variable, both of the following statements will print out its value. cout << number; cout << "number";

False

Once a value has been stored in a variable it cannot be changed.

False

The following pair of C++ statements are legal and will together execute in a program. const double taxRate = 0.5; taxRate = 0.6; True or False

False

The following pair of C++ statements will cause 3.5 to be output. double number = 7 / 2; cout << number; True or False

False

The following two C++ statements both work and perform the same operation in a C++ program. wages = regPay + overTime; regPay + overTime = wages; True or False

False

To check if a variable has a particular value, use the = relational operator, as in the if statement below if (s = 3) { cout << "s has the value 3"; } True or False

False

True or False: The following two C++ statements perform the same operation. wages = regPay + overTime; regPay + overTime = wages;

False

Assume that childAge is an int variable. The following if condition will evaluate to true when childAge is set to 15 if (childAge >= 3 || childAge <= 12) True or False

True

Syntax involves rules that must be followed when writing a program.

True

The following code pieces has an infinite while loop int i = 0; while (i < 10) { cout << "Hello " << endl; } True or False

True

The following two expressions evaluate to the same thing. c + a * b c + (a * b)

True

True or False: C++ is a case-sensitive language

True

Which of the following expressions correctly determines that x is greater than 10 and less than 20? a. 10 < x && x < 20 b. 10 < x < 20 c. (10 < x < 20) d. 10 < x || x < 20

a. 10 < x&& x < 20

Which of the following is a repetition structure in C++? a. do...while b. while...do c. switch d. if

a. do...while

What is the initial (or initialization) statement in the following for loop? (Assume that all variables are properly declared.) int i;for (i = 1; i < 20; i++) cout << "Hello World"; cout << "!" << endl; a. i < 20; b. i++; c. i = 1; d. cout << "Hello World";

c. i = 1;

Take a look at the following program. The cout statement in this program is not complete. Your job is to complete the missing part of the cout statement (that is what to write for blank ____) so that the program prints the number as 99.12 with two digits after the decimal point. int main() { double number = 99.1234567; // complete the missing part of the cout statement below ______, so that // the number is printed with two digits after the decimal point, that is as 99.12 cout << "number is: " << __________________________________ << number << endl; system("pause"); return 0; }

cout << "number is: " <<fixed << setprecision(2) << number << endl;

Write a C++ statement to declare a variable with name sellingPrice and type double

double sellingPrice;

A professor wants to calculate the average of three exam scores. Write a detailed pseudocode algorithm for a program that inputs three exam scores and calculates and displays their average. Make sure to specify the inputs and outputs to the algorithm and also include one test case (example).

inputs: examScoreOne, examScoreTwo, examScoreThree; averageScore = (examScoreOne + examScoreTwo + examScore) Create four variables all holding double data type Use cin to get three test scores Use the average variable to add all the test scores and divide by 3 Use cout to get the average missing test case, you can see the lab solutions on how to state the test cases


Ensembles d'études connexes

Salesforce Business Analyst Certification

View Set

ANAT CH 21: LYMPHATIC AND IMMUNE SYSTEM

View Set

Salesforce Identity and Access Management Architect

View Set

Maternal-newborn Ch. 23 Conditions Occurring after Delivery

View Set

PHI -186 - Chapter 4 - The Nature of Capitalism

View Set

ENG 102 EXAM 2 Poetry Mrs. Towels

View Set

Word 2013 Using Advanced Options 1.14 review

View Set