C++ Ch2.1

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which of the following is NOT a legal identifier? outrageouslyAndShockinglyLongRunon _42 _ lovePotionNumber9 7thheaven

7thheaven

Which of the following IS a legal identifier? 5_And_10 Five_&_Ten ____________ LovePotion#9 "Hello World"

____________

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 set the value of area to the value of length times the value of width. (The variables have already been declared and length and width have already been initialized .)

area=length*width;

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;

Before a variable is used it must be defined declared included evaluated assigned

defined

Write a statement that declares a double variable named dosage.

double dosage;

Given an integer variable drivingAge that has already been declared , write a statement that assigns the value 17 to drivingAge.

drivingAge=17;

Declare a floating point variable named distance.

float distance;

Given two integer variables matricAge and gradAge, write a statement that gives gradAge a value that is 4 more than the value of matricAge.

gradAge=matricAge+4;

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

Given two integer variables num and highest, write a statement that gives highest the same value that num has.

highest=num;

Which of the following is NOT a C++ keyword? using int main namespace return

int

Write a statement that declares and initializes two integer variables . Call the first one age and initialize it to 15, and call the second one weight and initialize it to 90.

int age; age=15; int weight; weight=90;

Write declaration statements to declare and initialize two variables : one is an integer variable named age, initialized to 18, and the other variable , named weight, is initialized to 114.5.

int age; age=18; float weight; weight=114.5;

Write a declaration for two integer variables , age and weight.

int age; int weight;

Declare an integer variable cardsInHand and initialize it to 13.

int cardsInHand; cardsInHand=13;

Write a statement that declares an int variable named count.

int count;

Declare an integer variable named degreesCelsius.

int degreesCelsius;

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 i; i=firstPlaceWinner; firstPlaceWinner = secondPlaceWinner; secondPlaceWinner = i;

Declare two integer variables named profitStartOfQuarter and cashFlowEndOfYear.

int profitStartOfQuarter; int cashFlowEndOfYear;

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.

jtemp = j; itemp=i; j= itemp; i=jtemp;

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

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

Given two integer variables oldRecord and newRecord, write a statement that gives newRecord the same value that oldRecord has.

newRecord=oldRecord;

Write a statement to set the value of num to 4 (num is a variable that has already been declared ).

num=4;

Write a statement to set the value of price equal to three times the value of cost. (The variables have already been declared and cost has already been initialized .)

price=3*cost;

An identifier that cannot be used as a variable name is a _______ word.

reserved word.

Write a statement to add the values of x and y together, storing the result in sum . (The variables have already been declared and x and y have already been initialized .)

sum=x+y;

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;

A location in memory used for storing data and given a name in a computer program is called a _________ because the data in the location can be changed.

variable

Write a statement to assign to weight_in_pounds the value of weight_in_kilos times 2.2. (The variables have already been declared and weight_in_kilos has already been initialized .)

weight_in_pounds=weight_in_kilos*2.2;


Set pelajaran terkait

Chapter 6: Variable Costing and Segment Reporting: Tools for Management

View Set

US Constitutional Amendments 18-22

View Set

5.3- Securities Exchange Act of 1934

View Set

Chapter 2. Overview of the Data Mining Process

View Set