A comment starts with what characters?
//
The text of a comment

is checked by the compiler for accuracy.
must appear in the first line of the program.
is printed out when the program runs.
can be anything the programmer wants to write.

can be anything the programmer wants to write.
A preprocessor directive starts with what character or characters?
#
Preprocessor directives are carried out:

just before a program is loaded into the processor.
just before a program is executed by the central processing unit (CPU).
just before a program is processed by the compiler.
just before the program’s output is processed.

just before a program is processed by the compiler.
its the set up for your source code.
They also dont require ; at the end
Function
Can be though of as a group of one or more programming statements that collectively has a name.
{} Braces
All the statements that make up a function are enclosed in a set of braces.
Literals
“Constant” values that are assigned to variables.
can be string or integer
Which special of the following special characters does NOT need to be paired with another special character in C++?
{
;
(
;
Every C++ program must contain a ____ function.
main
Which of the following names in a program is equivalent to the name int?

Int
INT
All of the above
None of the above

None of the above
//Correct – Only int is int: case matters.
The names defined in iostream are associated with which namespace?
std
Rearrange the following code so that it forms a correct program that prints out the letter Q:

int main()
}
// A SCRAMBLED program
return 0;
#include <iostream>
cout << “Q”;
{
using namespace std;

#include <iostream>
using namespace std;
int main()
{
cout<<“Q”;
return 0;
}
The character escape sequence to force the cursor to go to the next line is:
The character escape sequence to force the cursor to advance forward to the next tab setting is:
The character escape sequence to represent a single quote is:
The character escape sequence to represent a double quote is:
The character escape sequence to represent a backslash is:
How many lines are printed out by this statement: cout ;; “abc
def ghi
jkl” ;; endl ;; endl ;; “mno
pqr
“;
6
How many spaces printed out by this statement: cout ;; “how” ;; “now” ;; “brown” ;; “cow” ;; “?”;assingned
0
Write a complete program that prints Hello World to the screen.
#include ;iostream;
using namespace std;
main()
{
cout ;;”Hello World”;
return 0;
}
Suppose your name was George Gershwin. Write a complete program that would print your last name, followed by a comma, followed by your first name. Do not print anything else (that includes blanks).
#include ;iostream;
using namespace std;
int main()
{
cout ;; “Gershwin,George ” ;;endl;

return 0;
}

Write a statement that prints the following to standard output :
i=

Just write one statement that generates the message above: do not generate any extraneous spaces. Do not declare variables , do not write a main() function, do not write a whole program .

cout ;; “i=”;
Given an integer variable count, write a statement that writes the value of count to standard output .
cout ;; count;
The word in the brackets of an include directive specifies
A. a namespace.
B. a file containing code that is copied into the program at that point.
C. a file containing definitions of input/output code.
D. the name of the program.
A file containing code that is copied into the program at that point.
Which of the following will not be recognized if iostream is not included in the program?

main
std
namespace
return
cout

cout
Write the include directive needed to allow use of the various I/O operators such as cout and cin .
#include ;iostream;
Write the include directive that allows use of the function headers in the file myFuncs.h.
#include ;myFuncs.h;
Write a literal representing the integer value zero.
0
Write a statement that declares an int variable named count.
int count;
Declare an integer variable named degreesCelsius .
int degreesCelsius;
Which of the following is NOT a legal identifier?

outrageouslyAndShockinglyLongRunon

_42

_

lovePotionNumber9

7thheaven

7thheaven
An identifier that cannot be used as a variable name is a
reserved word
Which of the following IS a legal identifier?

5_And_10

Five_;_Ten
Constant
____________

LovePotion#9

“Hello World”

____________

Rules:
First character , must be a letter or underscore character.
After first, you may use letters, numbers, or underscore.
Upper and lower case symbolize 2 diff things.

Which of the following is NOT a C++ keyword?

using
int
main
namespace
return

main
Identifier
A programmer-defined name that rep some element of a program.
Which is the best identifier for a variable to represent the amount of money your boss pays you each month?

notEnough
wages
paymentAmount
monthlyPay
money

monthlyPay
Of the following variable names, which is the best one for keeping track of whether a patient has a fever or not?

temperature
feverTest
hasFever
fever

hasFever
Of the following variable names, which is the best one for keeping track of whether an integer might be prime or not?

divisible
isPrime
mightBePrime
number

mightBePrime
Declare a variable populationChange , suitable for holding numbers like -593142 and 8930522.
int populationChange;
Declare two integer variables named profitStartOfQuarter and cashFlowEndOfYear.
int profitStartOfQuarter;
int cashFlowEndOfYear;
Write a declaration of a variable named numberOfWidgets that can be used to hold numbers like 57 and 981 and -4.
int numberOfWidgets;
Write a declaration for a variable hits that can hold the number of times a baseball player has hit the ball in a baseball game.
int hits;
Write a declaration of a variable named count that can be used to hold numbers like 90000 and -1 and -406.
int count;
Write a declaration of a variable named number_of_children that can be used to hold the number of children in a family.
int number_of_children;
Write a declaration for two integer variables , age and weight.
int age, weight;
Declare an unsigned integer variable named degreesKelvin .
unsigned int degreesKelvin;
Declare a long integer variable named grossNationalProduct.
long int grossNationalProduct;
Write a hexadecimal integer literal representing the value fifteen.
0xf
Write a literal representing the long integer value twelve million.
12000000L
Write a long integer literal that has the value thirty-seven
37L
Qualifying an integer declaration with “unsigned” essentially increases the maximum value of the variable by a factor of
2
Write a character literal representing the (upper case) letter A .
‘A’
Write a literal representing the character whose ASCII value is 65.
‘A’
Write a character literal representing the digit 1 .
‘1’
Write a literal representing the largest character value . Suppose we are using unsigned one-byte characters .
255
Declare a character variable named c.
char c;
Integer variables
Can only hold whole numbers.
-Float point holds decimals
QUESTION 1:

How many bytes are needed to store: ‘n’ ?

QUESTION 2:

How many bytes are needed to store: “n” ?

QUESTION 3:

How many bytes are needed to store: ‘
‘ ?

QUESTION 4:

How many bytes are needed to store: ”
“, ?

QUESTION 5:

How many bytes are needed to store: ”
” ?

QUESTION 6:

How many bytes are needed to store: “” ?

1. 1
2. 2
3. 1
4. 2
5. 3
6. 1
What’s the difference in UNICODE value between ‘E’ and ‘A’? (consult a table of UNICODE values):

QUESTION 2:

What’s the difference in UNICODE value between ‘e’ and ‘a’? (consult a table of UNICODE values):

QUESTION 3:

What’s the difference in UNICODE value between ‘3’ and ‘0’? (consult a table of UNICODE values):

QUESTION 4:

What’s the difference in UNICODE value between ‘6’ and ‘0’? (consult a table of UNICODE values):

1. 4
2. 4
3. 3
4. 6
Write the necessary preprocessor directive to enable the use of the C++ string class .
#include ;string;
Declare a string variable named mailingAddress.
string mailingAddress;
Declare a string variable named empty and initialize it to the empty string .
string empty=””;
Assume that message is a string variable . Write a statement to display its value on standard output .
cout ;; message;
Assume that word is a string variable . Write a statement to display the message “Today’s Word-Of-The-Day is: ” followed by the value of word on standard output .
cout ;; “Today’s Word-Of-The-Day is: “+word;
Write a literal corresponding to the value of the first 6 digits of PI (“three point one four one five nine”).
3.14159
Write a floating point literal corresponding to the value zero.
.0
Write a statement that declares a double variable named dosage.
double dosage;
Write a declaration for a variable temperature that can hold the current outdoor temperature, measured to the half degree (like 98.6 or 31.5).
float temperature;
Declare a variable x , suitable for storing values like 3.14159 and 6.02E23.
float x;
The char data type
Is used to store individual characters(1 letter) and needs to be put in ‘ ‘. These are characters are known as character literals.
Its actually an integer data type that typically uses 1 byte of memory.
Null terminator/character
Its 0. It adds a extra byte to a string to inform it that it is concluded.(so in terms of space its always +1)
Strings
Are consecutive sequences of characters that occupy consecutive bytes of memory.
String literals
Are always stored in memory with a null terminator at the end. Which marks the end of a string. Enclosed in ” “
Character literals
are enclosed in ‘ ‘
C++ string class
#include ;string; then define the string variable
Allows you to store more then one character in a variable unlike char.
Given a floating-point variable fraction, write a statement that writes the value of fraction to standard output .

Do not write anything else to standard output — just the value of fraction.

cout ;; fraction;
Two variables , num and cost have been declared and given values : num is an integer and cost is a double . Write a single statement that outputs num and cost to standard output . Print both values (num first, then cost), separated by a space on a single line that is terminated with a newline character . Do not output any thing else.
cout ;;num ;;” “;;cost;;”
“;
Given an integer variable i and a floating-point variable f, write a statement that writes both of their values to standard output in the following format: i=value -of-i f=value -of-f

Thus, if i has the value 25 and f has the value 12.34, the output would be:

i=25 f=12.34

But if i has the value 187 and f has the value 24.06, the output would be:

i=187 f=24.06

cout ;; “i=” ;; i ;; ” ” ;; “f=” ;; f;
Write a literal representing the false value in C++.
false
Write a literal representing the true value .
true
Boolean expressions
Expressions that have a true or false value.
True = 1
False = 0
Declare a variable isACustomer, suitable for representing a true or false value .
bool isACustomer;
Declare a variable hasPassedTest , and initialize it to true .
bool hasPassedTest=true;
Write an expression whose value is the number of bytes that an int variable occupies on whatever machine the expression is executed on.
sizeof(int);
Write an expression whose value is the number of bytes that an unsigned long variable occupies on whatever machine the expression is executed on.
sizeof(long);
The exercise instructions here are LONG — please read them all carefully. If you see an internal scrollbar to the right of these instructions, be sure to scroll down to read everything.

Declare and initialize the following variables :
A variable monthOfYear , initialized to the value 11
A variable companyRevenue , initialized to the value 5666777
A variable firstClassTicketPrice , initialized to the value 6000
A variable totalPopulation , initialized to the value 1222333

int monthOfYear=11;
long companyRevenue=5666777;
int firstClassTicketPrice=6000;
long totalPopulation=1222333;
Initialization
When a value is assigned to a variable as a part of a variables definition.
Operands
THe data that operators work with.
Ex: unitSold = 12
Then unitSold and 12 are operands.
Declare an integer variable cardsInHand and initialize it to 13.
int cardsInHand=13;
Declare a variable temperature and initialize it to 98.6.
float temperature=98.6;
Declare a numerical variable precise and initialize it to the value 1.09388641.
double precise=1.09388641;
Declare a string variable named str and initialize it to Hello .
string str=”Hello”;
Write a statement that declares an int variable presidentialTerm and initializes it to 4.
int presidentialTerm=4;
Write a statement to set the value of num to 4 (num is a variable that has already been declared ).
num=4;
Given two integer variables num and highest, write a statement that gives highest the same value that num has.
highest=num;
Given two double variables , bestValue and secondBestValue, write some code that swaps their values . Declare any additional variables as necessary.
double tempValue;

tempValue=bestValue;
bestValue=secondBestValue;
secondBestValue=tempValue;

Given two int variables , i and j, which have been declared and initialized , and two other int variables , itemp and jtemp, which have been declared , write some code that swaps the values in i and j by copying their values to itemp and jtemp, respectively, and then copying itemp and jtemp to j and i, respectively.
itemp=i;
jtemp=j;
i=jtemp;
j=itemp;
Given three already declared int variables , i , j , and temp , write some code that swaps the values in i and j . Use temp to hold the value of i and then assign j ‘s value to i . The original value of i , which was saved in temp , can now be assigned to j .
temp=i;
i=j;
j=temp;
Given two int variables , firstPlaceWinner and secondPlaceWinner, write some code that swaps their values .

Declare any additional variables as necessary, but do not redeclare firstPlaceWinner and secondPlaceWinner.

int temp;
temp=firstPlaceWinner;
firstPlaceWinner=secondPlaceWinner;
secondPlaceWinner=temp;
Consider Program 2-19 below. Rearrange the lines of code to fix the scope error, yielding a correct C++ program that prints the number 100.
#include <iostream>
using namespace std;

int main() {
int value = 100;
cout <<value;
return 0;
}

Assume that an int variable x that has already been declared and initialized .

Write an expression whose value is 1 more than x .

x+1
Write an expression that computes the sum of the two variables verbalScore and mathScore (already declared and assigned values ).
verbalScore + mathScore
Given the variables fullAdmissionPrice and discountAmount (already declared and assigned values ), write an expression corresponding to the price of a discount admission. (The variable discountAmount holds the actual amount discounted, not a percentage.)
fullAdmissionPrice – discountAmount
Given the variable pricePerCase , write an expression corresponding to the price of a dozen cases.
pricePerCase * 12
Given the variables costOfBusRental and maxBusRiders , write an expression corresponding to the cost per rider (assuming the bus is full).
costOfBusRental/maxBusRiders
Write an expression that computes the remainder of the variable principal when divided by the variable divisor . (Assume both are type int .)
principal % divisor
Write a statement to set the value of ans equal to the value of num plus 5. (These variables have already been declared and num has already been initialized .)
ans = num + 5;
Write a statement to subtract tax from gross_pay and assign the result to net_pay . (The variables have already been declared and gross_pay and tax have already been initialized .)
net_pay=gross_pay-tax;
Write a statement to multiply diameter by 3.14159 and assign the result to circumference. (The variables have already been declared and diameter has already been initialized .)
circumference=diameter*3.14159;
Write a statement to assign to kilos the value of pounds divided by 2.2. (The variables have already been declared and pounds has already been initialized .)
kilos = pounds/2.2;
Assume that an int variable x has already been declared ,.

Write an expression whose value is the last (rightmost) digit of x .

x % 10
A variable’s scope
Every variable has a scope. The scope of a variable is the part of the program where the variable may be used.
Which of the following lines contains a valid comment?

int twoPi = 3.14159; / holds the value of two times pi /
int twoPi = 23.14159; / holds the value of two times pi //*
int twoPi = 23.14159; / / holds the value of 6 //*
double twoPi = 23.14159; / // holds the value of two time pi */ comment //

int twoPi = 3.14159; / holds the value of two times pi /
Which of the following lines does NOT consist of (a) valid, though boastful, comment(s)?

// / This is a / First Rate Program
//*// This is a //// First Rate Program //*//
// This is a //// First Rate Program //*//
/ This is a //// First Rate Program //*//

/ This is a //// First Rate Program //*//
Which comment below is the most helpful?

int volume; // declare an int
int volume; // declare volume
int volume; // declare volume to be an int variable
int volume; // size of trunk in cubic feet

int volume; // size of trunk in cubic feet
Declare an int constant , MonthsInYear , whose value is 12 .
const int MonthsInYear = 12;
Dividing two integers
Will only result in an integer(whole #) and integer division occurs. AKA you lose the decimal place NOT rounding.
Returning float points
Even if double is declared you may still lose the decimal.
Ex: double Num
Num = 5/2 Code prints out 2 NOT 2.5
However
Num = 5.0/2
x

Hi!
I'm Niki!

Would you like to get a custom essay? How about receiving a customized one?

Check it out