Monday, February 3, 2014

Section 3.1: Numbers - Assignment




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

drivingAge = 17

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

num = 4

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

newRecord = oldRecord

40340:  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

40953:  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

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

highest = num

40501:  Given two integer variables OldRecord and NewRecord, write a statement that gives NewRecord the same value that OldRecord has.

newRecord = oldRecord

40949:  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

40950:  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

40951:  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

40952:  Write a statement to subtract tax from gross_pay and assign the result to net_pay.  (The variables have already been declared and groww_pay and tax have already been initialized.)

net_pay = gross_pay - tax




40957:  Write a statement to find the remainder remdr when num is divided by 5.  (The variables have already been declared and num has already been initialized.)

remdr = num Mod 5

40956:  Write a statement to assign to kilos the value of pounds divided by 2.2.  (The varialbes have already been declared and pounds has already been initialized.)

kilos = pounds / 2.2

40954:  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

40955:  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

40348:  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 i and j by copying their values to itemp and jtemp, respectively, and then copying itemp and jtemp to j and i respsectively.

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

40349:  Given three already declared int variables, i, j, and temp, write some code that swaps the values 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

40350:  Given two int variables, firstPlaceWinner and secondPlaceWinner, write some code that swaps their values.  Declare any variables as necessary, but do not redeclare firstPlaceWinner and secondPlaceWinner.

     dim temp as Integer
     temp = firstPlaceWinner
     firstPlaceWinner = secondPlaceWinner
     secondPlaceWinner = temp

40351:  Given two double variables, bestValue and secondBestValue, write some code that swaps their values.  Declare any additional variables as necessary.

     dim temp as Double
     temp = bestValue
     bestValue = secondBestValue
     secondBestValue = temp


1 comment: