Problem Solving and Programming
1) [4 points] Given the variable declarations, evaluate the following compound conditions. Indicate with YES or NO next to each of the six numbers whether that simple condition will be evaluated. Also, indicate the value of the compound condition.
int d = 7;
int e = 2;
1 2 3 4 5 6
Simple conditions ®
1)
2)
3)
4)
5)
6)
Compound condition value: __________
1 2 3 4 5 6
Simple conditions ®
1)
2)
3)
4)
5)
6)
Compound condition value: __________
2) [3 points] The most common logical operators are AND, OR, and NOT, but there are other ones. Research and complete truth tables for the following operators:
“xor” operator truth table |
||
Left side |
Right side |
Result |
|
|
|
“implication” operator truth table |
||
Left side |
Right side |
Result |
|
|
|
“biconditional” operator truth table |
||
Left side |
Right side |
Result |
|
|
|
3) [6 points] Prompt for and read a single upper-case element symbol into char variable sym. Print the corresponding element and atomic number. Print an error message if any other character is entered. Write both if statement and switch statement versions.
Element |
Symbol |
Atomic number |
Boron |
B |
5 |
Carbon |
C |
6 |
Nitrogen |
N |
7 |
Oxygen |
O |
8 |
4) [4 points] Write a validation loop that prompts for and gets from the user a string that is at least five characters in length. If the string is outside that length range, print a message including the string and prompt the user again. Declare string variable str to hold the string. Allow the user to enter spaces.
5) [7 points] Write the number of for statement loops that will be performed for each of the following:
|
Initialization |
Condition |
Update |
Loops? |
a) |
i = -4 |
i <= 4 |
i = i + 1 |
|
b) |
i = 20 |
i < 30 |
i = i + 4 |
|
c) |
i = 7 |
i <= 7 |
i = i – 1 |
|
d) |
i = 15 |
i > 16 |
i = i * 2 |
|
e) |
i = 0 |
i < 50 |
i = i – 3 |
|
f) |
i = 24 |
i > 12 |
i = i – 2 |
|
g) |
i = 17 |
i != 8 |
i = i – 2 |
|
6) [1 point] Why should the continue statement rarely be used?
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of