CSCI 151

Lab 3 Session B

Skill set for this LAB:

Lab Practice

Problem 1

There is a treasure chest with 1 million dollars. The chest has a 5-digit combination lock that opens under the following conditions: the first digit should be equal to the fifth digit, the second digit should be odd, and the product of the third and forth digits should be divisible by 7. Write a program that reads one 5-digit positive integer and checks whether the input number opens the chest or not. The output should be YES, if the chest opens, and NO otherwise.


Problem 2:

In most cases, buy in bulk option is cheaper than buying packaged food, but not always. Write a program that reads price of the item per pound in the bulk session, size of the package (float, could be half pound package, for example), and the price of the package. The program finds and prints which option is cheaper, or notify user that both options offer the same price per pound.

For example, organic quinoa in bulk sesion cost 5.99 per pound, and the package of 2.5 pounds cost $12.9. In this case, it is cheaper to buy the package, since the price per pound in packaged version will be $5.2 which is less than $5.99 in bulk session.

For example: almonds in bulk session cost 7.99 per pound, and the package of 3/4 of the pound cost 6.99. In this case it is cheaper to buy in bulk, since the pound of packaged almonds will cost $9.32

For example: the pound of ham cost 10 dollars, and the 2 pound package cost 20 dollars, in this case both options have equal value.

Pay attention, when you test your program, to test the third option, input whole numbers to avoid issues with floating point numbers rounding.

Problem 3

Write a program that calculates the insurance points for speeding on the highway and the monthly insurance payments for the next insurance term after receiving the points. The program reads the upper speed limit on the highway, the current speed of the car, and the current insurance cost per year. You can assume that all inputs are integers. The program must print the following information: number of points, or message explaining the status (no points/ lincense suspended), the percent of insurance increase, the new yearly insurance premium, and the new monthly payment. Use the following table:

Speeding Points Table and Yearly Insurance Rate Increase

Points/Status : Number of mph above the speed limit insurance rate increase
The license suspended for a year : over 25 mph above the limit no need to buy insurance
4 points : 20 - 24 mph above the limit 20% increase
3 points : 15 - 19 mph above the limit 15% increase
2 points : 10 - 14 mph 10% increase
1 point : 1 - 9 mph above the limit 5% increase
NO POINTS : speed limit or less 0% increase

Problem 4 :

Write a program that calculates the insurance points that two different people will receive for speeding on highway. The upper speed limit on the highway is 65 mph. You can assume that speed is integer number. Use the following table:

Speeding Points Table

4 points: over 90 mph
3 points: 89 - 80
2 points: 79 - 70
1 point: 69 - 66
NO POINTS:65 and less

Problem 5 :

Write a program that finds the final score in the song competition. There are 4 judges in the competition.

Problem 6 :

Write a program that calculates the total cost of amusement park tickets for a family of 4 people. The input: full price of the ticket (integer), age of each family member (integer), tax (integer). Output: Total price after all discount and taxes are taken in account.

Problem 7 :

A company wants to transmit data over the telephone line, but they are concerned that their lines are tapped. All of their data is transmitted as four-digit integers. They decided to encrypt a four-digit number as follows: (1) they will replace each digit by ((digit + 7) mod 10); (2) they will then swap the first digit with the third digit and the second digit with the fourth. The resulting four-digit number is the encrypted number. To decrypt the number, the reverse procedure should be applied (you need to figure out the algorithm). Write a program that can do either encryption or decryption. The program must take two inputs. The first input must be either 1 or 2, with 1 signaling encryption and 2 signaling decryption. The second input is a positive integer less than 10,000 which will be either encrypted or decrypted depending on the first input.

Problem 8 :

Write a program that prompts the user to enter three integers, reads input numbers into variables num1, num2, and num3 of type int. The program will sort the input numbers and print the input numbers in the increasing order. You can assume that the input numbers are different.
For example if the input was 4, -9 and 8 the program should output: -9, 4, 8
For example , if the input was 1, 0, -90 the program should output: -90, 0, 1 Try to find a most efficient solution.