instructor - c. boylefall semester - 2015 [email protected]
TRANSCRIPT
![Page 1: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/1.jpg)
Instructor - C. BoyleInstructor - C. Boyle Fall Semester - 2015 Fall Semester - 2015 [email protected]@cs.odu.edu
![Page 2: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/2.jpg)
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!
![Page 3: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/3.jpg)
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
![Page 4: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/4.jpg)
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 */
![Page 5: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/5.jpg)
Q#2 Question
Question • True or False: The setw manipulator cannot use a
string as an argument.
Answer• True• False
![Page 6: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/6.jpg)
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.
![Page 7: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/7.jpg)
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.
![Page 8: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/8.jpg)
Q#5 Question
Question True or False: The if…else statement is a one-way selection structure.
Answer
• True
• False
![Page 9: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/9.jpg)
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.
![Page 10: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/10.jpg)
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.
![Page 11: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/11.jpg)
Q#8 Question
Question The following is a valid identifier:
1_quiz
Answer
• True
• False
![Page 12: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/12.jpg)
Q#9 Question
Question The following is a valid identifier:
max-value
Answer
• True
• False
![Page 13: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/13.jpg)
Q#10 Question
Question The following is a valid identifier:
$uperMan
Answer
• True
• False
![Page 14: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/14.jpg)
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
![Page 15: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/15.jpg)
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
![Page 16: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/16.jpg)
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.
![Page 17: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/17.jpg)
Q#14 Question
Question A float value will have a wider range of values for exponents than a double value.
Answer
• True
• False
![Page 18: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/18.jpg)
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.
![Page 19: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/19.jpg)
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
![Page 20: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/20.jpg)
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
![Page 21: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/21.jpg)
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.
![Page 22: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/22.jpg)
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
![Page 23: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/23.jpg)
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, …;
![Page 24: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/24.jpg)
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
![Page 25: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/25.jpg)
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);
![Page 26: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/26.jpg)
Q#23 Question
Question The header file ______________ needs to be included to use the setw function.
Answer
• iomanip
• iostream
• iosetw
• cmath
![Page 27: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/27.jpg)
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);
![Page 28: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/28.jpg)
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.
![Page 29: Instructor - C. BoyleFall Semester - 2015 cboyle@cs.odu.edu](https://reader036.vdocuments.us/reader036/viewer/2022062518/56649ed35503460f94be34e2/html5/thumbnails/29.jpg)
QUESTIONS?QUESTIONS?
Assignments:Assignments:
Quiz due before class on TuesdayQuiz due before class on Tuesday