2.14: Arithmetic Operators

Ace your homework & exams now with Quizwiz!

Assume that x is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if x is a upper-case letter.

(x>='A' && x<='Z')

QUESTION 1: Correct We hope you never have to encounter anything like the following expression in a program, but consider it for a moment and indicate its value: ( /* 5 + 3 */ - 9 + 6/*8*//2 ) //*+4*/ -10 3 -7 -6 5 -8

-6

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 the variables taxablePurchases and taxFreePurchases (already declared and assigned values ), write an expression corresponding to the total amount purchased.

taxablePurchases+taxFreePurchases

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;

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 difference of the variables endingTime and startingTime.

endingTime-startingTime

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 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;

Which of the following lines contains a valid, though not necessarily accurate, comment? int twoPi = 3.14159; /* holds the value of two times pi */ int twoPi = 2*3.14159; /* holds the value of two times pi //* int twoPi = 2*3.14159; / / *holds the value of 6 //* double twoPi = 2*3.14159; /* // holds the value of two time pi */ [comment] // QUESTION 2: Correct 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 //*//

int twoPi = 3.14159; /* holds the value of two times pi */ /* This is a //*// First Rate Program //*//

QUESTION 1: Correct 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

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;

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 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=cost*3;

given the variable pricePerCase, write an expression corresponding to the price of a dozen cases.

pricePerCase*12

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 find the remainder rem when num is divided by 5. (The variables have already been declared and num has already been initialized .)

rem=num%5;

Write an expression that computes the sum of the two variables verbalScore and mathScore (already declared and assigned values ).

verbalScore+mathScore

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;

Assume that an int variable x has already been declared ,. Write an expression whose value is the last (rightmost) digit of x.

x%10

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


Related study sets

ADN5 Chap. 48 Child With an Alteration in Metabolism/Endocrine Disorder

View Set

CompTIA A+ Cert Master 5.4 Hardware and Network Troubleshooting Study

View Set

Perceptron + MLE/MAP + Naive Bayes + Logistic/linear Regression

View Set