Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu

Preview:

Citation preview

Instructor - C. BoyleInstructor - C. Boyle Fall Semester - 2015 Fall Semester - 2015 cboyle@cs.odu.educboyle@cs.odu.edu

This was an in-class exercise, and something may have changed, SO

Do not count on the accuracy of the solutions in this presentation!

Verify With Your Textbook!

Look Up The Answers Yourself!

Q#1 Question

Which of the following methods for inserting comments in a C++ program are valid?

Answer

•   \\ comments in your program

•   \* comments in your program *\

•   /* comments in your program */

•   #comments in your program

Q#1-Solution

There are two methods for inserting comments in a C++ program: a comment can begin with the characters // or a comment can begin with the characters /* and then end with the characters */

Q#2 Question

Question • True or False: The setw manipulator cannot use a

string as an argument.

Answer• True• False

Q#3 Question

Consider the following preprocessor directive:  

#include <iostream.h>The directive specifies that the statements in the file:

ANSWER • contains a constant we use in executing loops. • contains information related to the input statement used in

the program • contains info related to functions used to compute the sum of

a value. • contains a comment we use in exiting the program.

Q#4 Question

Multiple Answer Question

The main function contains two types of statements:

Answer• statements that define memory locations which will be used

in the program •   pre-processor statements that define additional code to be

inserted.•   statements that specify actions to be taken. •   post-processor statements that define additional code to

executed.

Q#5 Question

Question True or False: The if…else statement is a one-way selection structure.

Answer

• True

• False

Q#6 Question

Multiple Answer Question

//define and initialize variables

double quizscore1, quizscore3, quiz4=10, averagescore=4.0, avg, sumscores;

This statement specifies that

Answer• the program will use five variables.• the variable quiz4 should be initialized to the value of 10.0.• the variable average should be initialized to the value of 10.0.• nothing, because it should all be on one line.

Q#7 Question

Question Rules for selecting a valid identifier are:

Answer

  • An identifier cannot begin with an alphabetic character or the

underscore character.•   Alphabetic characters in an identifier must be lower case

letters. •   An identifier can be of any length. •   Alphabetic characters in an identifier can be lower case or

upper case letters.

Q#8 Question

Question The following is a valid identifier:

1_quiz

Answer

• True

• False

Q#9 Question

Question The following is a valid identifier:

max-value

Answer

• True

• False

Q#10 Question

Question The following is a valid identifier:

$uperMan

Answer

• True

• False

Q#11 Question

Question True or False: File stream variables are predefined in the fstream header file and associated with input/output sources. 

Answer

• True

• False

Q#12 Question

Question C++ is case sensitive, that is, it distinguishes upper case letters from lowercase letters.  Thus Sum, sum, and SUM represent three ways of safely working with the same variable value.

Answer

• True

• False

Q#13 Question

Question

The difference between the float, double, and long double types relates to the

Answer•   exponent (or accuracy) and length of the values represented. •   precision (or accuracy) and range of the values represented. •   exponent (short accuracy), range (long accuracy) and length

of the values represented. • precision (or accuracy) and range of the libraries included.

Q#14 Question

Question A float value will have a wider range of values for exponents than a double value.

Answer

• True

• False

Q#15 Question

Multiple Answer Question Select the true statements, concerning symbolic constants:

Answer•   The compiler will replace each occurrence of the constant

identifier with the constant value. • Constant declarations, like variable declarations, and with a

colon. (:)

•   Several symbolic constants can be declared in one statement if they have the same data type.

•   A symbolic constants is declared by prefixing a declaration with the const specifier.

Q#16 Question

Question

The assignment statements below define and initialize the variables at the same time.

double sum, total;

total = 10;

sum = total;

Answer• True• False

Q#17 Question

Question • Multiple assignments are allowed in C++, as in

the following statement, which assigns a value of zero to each of the variables x,y, and z.

 x = y = z = 0;

Answer

• True

• False

Q#18 Question

Question What is an enumeration type?

Answer•   C++’s method for allowing programmers to create

their own simple data types. •   C++’s method for allowing programmers to use

numerals to update control structures.•   One of C++’s simple integer data types, such as int.•   C++’s library of available numerical variables.

Q#19 Question

Question An expression that has operands of different data types is called a(n)

Answer

•   mixed expression

•   homogenous expression

•   simple

•   enumerated expression

Q#20 Question

Question What is the syntax for declaring single or multiple variables?

Answer•   dataType identifier, identifier, …; •   variableName dataType identifier, identifier, …; •   dataName identifierType, identifierType, …; •   identifier, identifier, …;

Q#21 Question

Question True or False: The semantic rules of a language tell you what is legal and what is not legal.

Answer

• True

• False

Q#22 Question

Question What is the syntax of the ignore function?

Answer

•   cin.ignore(intExp, chExp);

•   cout<< stringName.ignore(intExp, intExp);

•   cin>> stringName.ignore(intExp, intExp);

•   int value.stringName.ignore(intExp, intExp);

Q#23 Question

Question The header file ______________ needs to be included to use the setw function.

Answer

•   iomanip

•   iostream

•   iosetw

•   cmath

Q#24 Question

Question Which of the following would you use as a statement to format the output of decimal numbers to two decimal places?

Answer

•   cout << setprecision(2);

•   cin << setprecision(2);

•   cout << setdotwidth( );

•   cout >> setw.setprecision(2);

Q#25 Question

Question Which of the following are true?

Answer

•   The if…else statement is a two-way selection structure.

•   A unary operator takes three operands.

•   The equality operator in C++ is =

•   A relational operator allows you to make comparisons in a program.

QUESTIONS?QUESTIONS?

Assignments:Assignments:

Quiz due before class on TuesdayQuiz due before class on Tuesday

Recommended