Easy Code

Suppose your name was George Gershwin. Write a complete program that would print your last name (Gershwin), followed by a comma, followed by your first name (George). Do not print anything else (that includes blanks).

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

Write a statement that reads an integer value from standard input into val. Assume that val has already been declared as an int variable.

Write the include directive needed to allow use of the various I/O operators such as cout and cin.

Given an integer variable count, write a statement that writes the value of count to standard output.

Write a character literal representing the (upper case) letter A.

Write a declaration of a variable named count that can be used to hold numbers like 90000 and -1 and -406.

Write a declaration for an integer variable area and a variable price that can hold numbers with decimal places.

Write a statement that increments the value of the int variable total by the value of the int variable amount. That is, add the value of amount to total and assign the result to total.

Declare a character variable named c

Write a declaration of an int variable year and initialize it to 365.

Declare two integer variables named profitStartOfQuarter and cashFlowEndOfYear.

Declare an int constant MONTHS_IN_DECADE whose value is the value of the constant MONTHS_IN_YEAR (already declared) multiplied by 10. element is a more accessible alternative

Declare an int constant, MONTHS_IN_YEAR, whose value is 12. element is a more accessible alternative

Suppose your name was Alan Turing. Write a statement that would print your last name (Turing), followed by a comma and space, then your first name (Alan).

Assume that message is a string variable. Write a statement to display its value on standard output.

Write a C++ statement that writes the entire following sentence including quotes to standard output (the computer monitor): "I think, therefore I am." -Descartes

Write a C++ statement that would write the following to standard output (the computer monitor): U:CSE1502Assignments

Medium Code

Write a statement using the decrement operator to decrease the value of count (an already declared integer variable) by 1.

Write an expression that evaluates to true if the integer variable x contains an even value, and false if it contains an odd value.

Given the boolean variable isFullTimeStudent and the integer variable age, write an expression that evaluates to true if age is less than 19 or isFullTimeStudent is true.

Write an expression that evaluates to true if and only if the value of the integer variable x is equal to zero.

Given the variables temperature and humidity, write an expression that evaluates to true if and only if the temperature is greater than 90 and the humidity is less than 10.

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.

Write an if/else statement that assigns true to the variable fever if the variable temperature is greater than 98.6; otherwise it assigns false to fever.

Write a statement using the increment operator to increase the value of num_items (an already declared integer variable) by 1.

Write a complete program that declares an integer variable val, reads a value from the keyboard into that variable, and writes to standard output the square of the variable's value.

Write an if-statement that assigns true to the variable fever if the variable temperature is greater than 98.6.

Write an if/else statement that compares the double variable pH with 7. 0 and makes the following assignments to the bool variables neutral, base, and acid:

neutral base acid
pH is less than 7 false false true
pH is greater than 7 false true false
pH is equal to 7 true false false

Write an if/else statement that adds 1 to the variable minors if the variable age is less than 18, adds 1 to the variable adults if age is 18 through 64, and adds 1 to the variable seniors if age is 65 or older.

Given a int variable named yesCount and another int variable named noCount and a char variable named response, write the necessary code to read a value into into response and then carry out the following:

  • if the character typed in is a y or a Y then increment yesCount and print out "YES WAS RECORDED"
  • if the character typed in is an n or an N then increment noCount and print out "NO WAS RECORDED"
  • If the input is invalid just print the message "INVALID" and do nothing else.

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.)

Hard Code

Write a switch statement that tests the value of the char variable response and performs the following actions:

  • if response is y, the message - Your request is being processed - is displayed
  • if response is n, the message - Thank you anyway for your consideration - is displayed
  • if response is h, the message - Sorry, no help is currently available - is displayed
  • for any other value of response, the message - Invalid entry; please try again - is displayed

Assume that grade is a variable whose value is a letter grade-- any one of the following letters: 'A', 'B', 'C', 'D', 'F'. Assume further that there are the following int variables, declared and already initialized: acount, bcount, ccount, dcount, and fcount. Write a switch statement that increments the appropriate variable (acount, bcount, ccount, etc. ) depending on the value of grade. So if grade is 'A' then acount is incremented; if grade is 'B' then bcount is incremented, and so on.

Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the non-negative values into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0.

Given int variables k and total that have already been declared, use a do-while loop to compute the sum of the squares of the first 50 counting numbers, and store this value in total. Thus your code should put 1*1 + 2*2 + 3*3 +. . . + 49*49 + 50*50 into total. Use no variables other than k and total.

Write a loop that reads positive integers from standard input, printing out those values that are greater than 100, and that terminates when it reads an integer that is not positive. The values should be separated by single blank spaces. Declare any variables that are needed.

Write a loop that reads positive integers from standard input, printing out those values that are even, separating them with spaces, and that terminates when it reads an integer that is not positive. Declare any variables that are needed.

Write a loop that reads characters from standard input where the character is either d or g. The loop terminates when g is read in. After the loop, your code should print out the number of d characters that were read.

NOTE: in mathematics, the square root of a negative number is not real; in C++ therefore, passing such a value to the square root function is an error. Given a double variable named areaOfSquare write the necessary code to read in a value into areaOfSquare and print out the length of the side of that square. HOWEVER: if any value read in is not valid input, just print the message "INVALID".

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.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.