Question(1) Assume that a bool variable isQuadrilatera l has been declared , and
ID: 3855547 • Letter: Q
Question
Question(1)
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.
Instructor Notes:
Hint: The result of evaluating a conditional expression is true/false, and can be assigned to bool variable, e.g.,
bool x = y == z;
Note == is the relational equality operator and = is the assignment operator. This statement will compare y and z to see if they are equal, which is either true or false. Then the true/false value will be assigned to Boolean variable x.
=========
Question (2)
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
=========
Question(3)
Write an if/else statement that compares the value of the variables soldYesterday and soldToday, and based upon that comparison assigns salesTrend the value -1 or 1.
-1 represents the case where soldYesterday is greater than soldToday; 1 represents the case where soldYesterday is not greater than soldToday.
=========
Question(4)
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 letter.
=========
Question(5)
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 alphanumeric , that is either a letter or a decimal digit
=========
Question(6)
Assume that c is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if c is a space character
=========
Question(7)
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 NOT a upper-case letter
=========
Question(8)
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 NOT a letter.
=========
Question(9)
Assume that s is a string . Write an expression whose value is true if and only if the value of s would come between "mortgage" and "mortuary" in the dictionary.
Explanation / Answer
Note: Function available in c add header file #include <ctype.h>
Question(1)
bool isQuadrilateral = false
int numberOfSides =4
if (numberOfSides ==4)
isQuadrilateral = true
else
isQuadrilateral = false
Question (2)
bool workedOvertime = false
int hoursWorked =40
if(hoursWorked > 40)
workedOvertime =true
else
workedOvertime =false
Question(3)
int salesTrend =0
if(soldYesterday > soldToday)
salesTrend =-1
else
salesTrend =1
Question(4)
char x ='b'
bool trueChar=false
trueChar=true
else
trueChar=false
Question(5)
char x ='2'
bool alphNum=false
if(isalpha(x))
alphNum=true
else
alphNum =false
Question(6)
char c= ' '
bool charSpace=false
if(isspace(c))
charSpace=true
else
charSpace=false
Question(7)
if not uppercase should be lowercase
char x ='m'
bool lowCase=false
if(islower(x))
lowCase=true
else
lowCase=false
Question(8)
if is is not a letter x should be digit
char x ='2'
bool Num=false
if(isdigit(x))
Num=true
else
Num= false
Question(9)
we declare two string comparing the strings
string s;
string str1="mortgage"
string str2="mortuary"
boo betweenStr1N2=false
if(strstr(str1,s) && strstr(str2,s)) //strstr(str1,str2) checks for str2 in str1
betweenStr1N2=true
else
betweenStr1N2=false
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.