Concept explainers
Write a
Enter time in 24-hour notation: 13:07 That is the same as 1:07 PM Again?(y/n) y Enter time in 24-hour notation: 10:15 That is the same as 10:15 AM Again?(y/n) y Enter time in 24-hour notation: 10:65 There is no such time as 10:65 Try again: Enter time in 24-hour notation: 16:05 That is the same as 4:05 PM Again?(y/n) n End of program |
You will define an exception class called TimeFormatMistake. If the user enters an illegal time, like 10:65 or even gibberish like 8&*68, then your program will throw and catch a TimeFormatMistake.
Trending nowThis is a popular solution!
Chapter 16 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Modern Database Management
Absolute Java (6th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out With Visual Basic (8th Edition)
Starting Out with C++: Early Objects (9th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
- Write a program that calculates the equivalent resistance of a circuit. n electrical resistors with resistance values R1, R2,.., Rn are said to be connected in parallel if the same voltage is applied across each. Their equivalent resistance Reg is related to the values R1, R2, ..., Rn by: 1 1 1 1 + +...+ R R R, R. "eq Write a program that prompts the user to enter the resistance of n resistors. The user should be prompted continuously by using a while loop until a zero or negative value is entered (the program should count the number of resistors n entered by the user and store the values in an array). Use another separate loop to print the resistance values entered by the user and the equivalent resistance Reg. Test your program with R1= 1 kn, R2= 2 kn, R3= 4 kQ and R4= 8 kQ.arrow_forwardWrite a program that asks users when their birthday is. Use information provided to give them their astrological sign. Each of the twelve signs should display a different horoscope. Use the following dates for each sign, keeping in mind that both month and day must be evaluated for an accurate result. Aries: March 21–April 20 Taurus: April 21–May 21 Gemini: May 22–June 21 Cancer: June 22–July 22 Leo: July 23–August 22 Virgo: August 23–September 23 Libra: September 24–October 23 Scorpio: October 24–November 22 Sagittarius: November 23–December 21 Capricorn: December 22–January 20 Aquarius: January 21–February 19 Pisces: February 20–March 20arrow_forwardWrite a program that takes in an integer in the range 11-100 as input. The output is a countdown starting from the integer, and stopping when both output digits are identical. Ex: If the input is: 93 the output is: 93 92 91 90 89 88 Ex: If the input is: 11 the output is: 11 Ex: If the input is: 9 or any value not between 11 and 100 (inclusive), the output is: Input must be 11-100 this is what i have n = int(input())if n > 100 or n < 11:print('Input must be 11-100')exit(0)while True:print(n, end=" ")first_digit = n // 10second_digit = n % 10 if first_digit == second_digit:break n = n-1 my output is 93 92 91 90 89 88 but it needs to be 93 92 91 90 89 88arrow_forward
- Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. For division, if the denominator is zero, output an appropriate message. Limit the supported operations to + -/ *and write an error message if the operator is not one of the supported operations. Here is some example output: 3 + 4 = 7 13 * 5 = 65 C++arrow_forwardWrite a program that reads the employee's name and base salary and then calculates the tax and net amount Salary where: Net salary = Basic salary If the basic salary is less than 500 (no tax) Net salary = basic salary - tax value So that the tax amount is 5% of the basic salary Then it prints the employee's name and net salary %3D 2:40 PM /arrow_forwardPython Write a program that calculates and prints the value according to the given formula: Q = Square root of [(2 * C * D)/H] The fixed values of C and H: C is 50. H is 30. D is the variable whose values should be input to your program in a comma-separated sequence. Example: If the input is: “100, 150, 180.” The output of the program should be: “18, 22, 24.”arrow_forward
- Write a program that generates a random two-digit integer. The program prompts the user to predict the generated number by entering a two- digit integer, and then determines the accuracy of the user’s prediction according to the following rules:If the user’s prediction matches the generated number exactly, the accuracy is 100%. If one digit in the user’s predicted number matches a digit in the gener- ated number, the accuracy is 50%. If none of the digits in user’s predicted number matches with the generated number, the accuracy is 0%.arrow_forwarduse c languagre program.arrow_forwardTask 9 Write Python code of a program that reads an integer, and prints the integer if it is a multiple of NEITHER 2 NOR 5. For example, 1, 3, 7, 9, 11, 13, 17, 19, 21, 23, 27, 29, 31, 33, 37, 39 ... hint(1): use the modulus (%) operator for checking the divisibility hint(2): You can consider the number to be an integer !%3%===== Example01: Input: 3 Output: 3arrow_forward
- Write a program that defines variables a, b, c, d as float and Num2 as integer. Solve the following expression on notebook by supposing some values of each variable, then execute your program for the same values and see the difference if any.a * (b - c / d) + ++ Num2 where a, b, c and d are float type variables.b) Write a program that defines variables Num1, Num2, Num3, and Num, as integer Solve the following expression on notebook by supposing some values of each variable, then execute your program for the same values and see the difference if any.Result= Num1 + Num2 / Num3 + Num + Num2++ where Num1, Num2 and Num3 are all integer type variablesc) Write a program that defines variables m, n, p, and amount, as integer Solve the following expression on notebook by supposing some values of each variable, then execute your program for the same values and see the difference if any.(m + n) / (p + amountarrow_forwardA supermarket is doing a sales promotion for soft drinks. If one day you buy soft drinks and bring the empty bottles the next day, they exchange each set of K empty bottles for a full one. A customer wants to make the most of this offer and therefore bought several bottles on the first day of the promotion. Now he wants to know how many bottles he will have at the end of the second day of the promotion if he use it to the fullest. Make a program to calculate this. Input The first input line contains integer T (1 ≤ T ≤ 10000), which indicates the number of test cases. In each of the following T lines come two integers N and K (1 ≤ K, N ≤ 10000), respectively the number of soft drinks bought and the number of empty bottles to gain a full. Output For each test case print the number of bottles that the customer will have on the second day, if he makes the most of the offer.arrow_forwardWrite a program that accepts the names of three political parties and the number of votes each received in the last mayoral election. Display the percentage of the vote each party received. An example of the program is shown below: Enter name for first party >> Pool Party Enter votes received >> 87 Enter name for second party >> House Party Enter votes received >> 54 Enter name for third party >> Surprise Party Enter votes received >> 111 The Pool Party party got 34.523809523809526 percent of the vote The House Party party got 21.428571428571427 percent of the vote The Surprise Party party got 44.047619047619044 percent of the votearrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning