COMP 150 WEEK 3 DISCUSSION 2024 LATEST SPRING-
SUMMER SESSION
Write an expression that evaluates to true if and only if the integer x is greater than
the integer y. - ANSWER: x>y
Given an int variable grossPay, write an expression that evaluates to true if and only
if the value of grossPay is less than 10,000. - ANSWER: grossPay < 10000
Write an expression that evaluates to true if and only if the value of the integer
variable x is equal to zero. - ANSWER: x==0
Write an expression that evaluates to true if and only if the variables profits and
losses are exactly equal . - ANSWER: profits==losses
Given the char variable c, write an expression that is true if and only if the value of c
is not the space character . - ANSWER: c!=' '
Write an expression that evaluates to true if the value of index is greater than the
value of lastIndex. - ANSWER: index > lastIndex
Working overtime is defined as having worked more than 40 hours during the week.
Given the variable hoursWorked, write an expression that evaluates to true if the
employee worked overtime. - ANSWER: hoursWorked > 40
Write an expression that evaluates to true if the value x is greater than or equal to y.
- ANSWER: x>=y
Given the variables numberOfMen and numberOfWomen, write an expression that
evaluates to true if the number of men is greater than or equal to the number of
women. - ANSWER: numberOfMen>=numberOfWomen
Given a double variable called average, write an expression that is true if and only if
the variable 's value is less than 60.0. - ANSWER: average<60
Write an expression that evaluates to true if the value of the integer variable x is
divisible (with no remainder) by the integer variable y. (Assume that y is not zero.) -
ANSWER: x % y==0
Write an expression that evaluates to true if and only if the integer variable
numberOfShares is less than 100. - ANSWER: numberOfShares < 100
Write an expression that evaluates to true if and only if the value of the boolean
variable workedOvertime is true . - ANSWER: workedOvertime==true
, Assume that a bool variable isQuadrilateral has been declared , and that an int
variable , numberOfSides has been declared and initialized . Write a statement that
assigns the value of isQuadrilateral to true if numberOfSides is exactly 4 and false
otherwise. - ANSWER: isQuadrilateral = numberOfSides==4;
Assume that a bool variable workedOvertime has been declared , and that an int
variable hoursWorked has been declared and initialized . Write a statement that
assigns the value of workedOvertime to true if hoursWorked is greater than 40 and
false otherwise. - ANSWER: workedOvertime= hoursWorked > 40;
Write an expression that evaluates to true if the value of the integer variable
numberOfPrizes is divisible (with no remainder) by the integer variable
numberOfParticipants. (Assume that numberOfParticipants is not zero.) - ANSWER:
numberOfPrizes%numberOfParticipants==0
Write a conditional that assigns 10,000 to the variable bonus if the value of the
variable goodsSold is greater than 500,000. - ANSWER: if(goodsSold>500000)
bonus=10000;
Write a conditional that decreases the variable shelfLife by 4 if the variable
outsideTemperature is greater than 90. - ANSWER: if(outsideTemperature>90)
shelfLife-=4;
Assume that the variables gpa, deansList and studentName, have been declared and
initialized . Write a statement that both adds 1 to deansList and prints studentName
to standard out if gpa exceeds 3.5. - ANSWER: if (gpa > 3.5)
{
deansList++;
cout << studentName;
}
Assume that isIsosceles is a bool variable , and that the variables isoCount,
triangleCount, and polygonCount have all been declared and initialized . Write a
statement that adds 1 to each of these count variables (isoCount, triangleCount, and
polygonCount) if isIsosceles is true . - ANSWER: if (isIsosceles == true)
{
isoCount += 1;
triangleCount += 1;
polygonCount += 1;
}
Write an if/else statement that compares the variable age with 65, adds 1 to the
variable seniorCitizens if age is greater than or equal to 65, and adds 1 to the
variable nonSeniors otherwise. - ANSWER: if (age>=65)
seniorCitizens++;
else
nonSeniors++;
SUMMER SESSION
Write an expression that evaluates to true if and only if the integer x is greater than
the integer y. - ANSWER: x>y
Given an int variable grossPay, write an expression that evaluates to true if and only
if the value of grossPay is less than 10,000. - ANSWER: grossPay < 10000
Write an expression that evaluates to true if and only if the value of the integer
variable x is equal to zero. - ANSWER: x==0
Write an expression that evaluates to true if and only if the variables profits and
losses are exactly equal . - ANSWER: profits==losses
Given the char variable c, write an expression that is true if and only if the value of c
is not the space character . - ANSWER: c!=' '
Write an expression that evaluates to true if the value of index is greater than the
value of lastIndex. - ANSWER: index > lastIndex
Working overtime is defined as having worked more than 40 hours during the week.
Given the variable hoursWorked, write an expression that evaluates to true if the
employee worked overtime. - ANSWER: hoursWorked > 40
Write an expression that evaluates to true if the value x is greater than or equal to y.
- ANSWER: x>=y
Given the variables numberOfMen and numberOfWomen, write an expression that
evaluates to true if the number of men is greater than or equal to the number of
women. - ANSWER: numberOfMen>=numberOfWomen
Given a double variable called average, write an expression that is true if and only if
the variable 's value is less than 60.0. - ANSWER: average<60
Write an expression that evaluates to true if the value of the integer variable x is
divisible (with no remainder) by the integer variable y. (Assume that y is not zero.) -
ANSWER: x % y==0
Write an expression that evaluates to true if and only if the integer variable
numberOfShares is less than 100. - ANSWER: numberOfShares < 100
Write an expression that evaluates to true if and only if the value of the boolean
variable workedOvertime is true . - ANSWER: workedOvertime==true
, Assume that a bool variable isQuadrilateral has been declared , and that an int
variable , numberOfSides has been declared and initialized . Write a statement that
assigns the value of isQuadrilateral to true if numberOfSides is exactly 4 and false
otherwise. - ANSWER: isQuadrilateral = numberOfSides==4;
Assume that a bool variable workedOvertime has been declared , and that an int
variable hoursWorked has been declared and initialized . Write a statement that
assigns the value of workedOvertime to true if hoursWorked is greater than 40 and
false otherwise. - ANSWER: workedOvertime= hoursWorked > 40;
Write an expression that evaluates to true if the value of the integer variable
numberOfPrizes is divisible (with no remainder) by the integer variable
numberOfParticipants. (Assume that numberOfParticipants is not zero.) - ANSWER:
numberOfPrizes%numberOfParticipants==0
Write a conditional that assigns 10,000 to the variable bonus if the value of the
variable goodsSold is greater than 500,000. - ANSWER: if(goodsSold>500000)
bonus=10000;
Write a conditional that decreases the variable shelfLife by 4 if the variable
outsideTemperature is greater than 90. - ANSWER: if(outsideTemperature>90)
shelfLife-=4;
Assume that the variables gpa, deansList and studentName, have been declared and
initialized . Write a statement that both adds 1 to deansList and prints studentName
to standard out if gpa exceeds 3.5. - ANSWER: if (gpa > 3.5)
{
deansList++;
cout << studentName;
}
Assume that isIsosceles is a bool variable , and that the variables isoCount,
triangleCount, and polygonCount have all been declared and initialized . Write a
statement that adds 1 to each of these count variables (isoCount, triangleCount, and
polygonCount) if isIsosceles is true . - ANSWER: if (isIsosceles == true)
{
isoCount += 1;
triangleCount += 1;
polygonCount += 1;
}
Write an if/else statement that compares the variable age with 65, adds 1 to the
variable seniorCitizens if age is greater than or equal to 65, and adds 1 to the
variable nonSeniors otherwise. - ANSWER: if (age>=65)
seniorCitizens++;
else
nonSeniors++;