Write a
will require several functions:
bool isLeapYear (int year) ;
This function should return true if year is a leap year and false if it is not. Here is pseudocode to determine a leap year:
leap_year = ((year divisible by 400) or (year divisible by 4 and year not divisible by 100))
int getCenturyValue (int year) ;
This function should take the first two digits of the year (i.e., the century), divide by 4, and save the remainder. Subtract the remainder from 3 and return this value multiplied by 2. For example, the year 2008 becomes
int getYearValue (int year) ;
This function computes a value based on the years since the beginning of the century. First, extract the last two digits of the year. For example, 08 is extracted for 2008. Next, factor in leap years. Divide the value from the previous step by 4 and discard the remainder. Add the two results together and return this value. For example, from 2008 we extract 08. Then
int getMonthValue (int month, int year) ;
This function should return a value based on the following table and will require invoking the isLeapYear function:
Finally, to compute the day of the week, compute the sum of the date’s day plus the values returned by getMonthVaIue, getYearVaIue, and getCenturyVaIue. Divide the sum by 7 and compute the remainder. A remainder of 0 corresponds to Sunday, 1 corresponds to Monday, etc.—up to 6—which corresponds to Saturday. For example, the date July 4, 2008 should be computed as
Your program should allow the user to enter any date and output the corresponding day of the week in English.
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Absolute C++
Additional Engineering Textbook Solutions
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Database Concepts (8th Edition)
Concepts Of Programming Languages
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Electric Circuits. (11th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
- A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided by 1, 2, 3, and 6. Write a Boolean function named isPrime, which takes an integer as an argument and returns true if the argument is a prime number, and false otherwise. Demonstrate the function in a complete program.arrow_forwardImplement the function total_price, which takes in a list of prices of individual products and needs to find the total price. Unfortunately, any product that is priced greater than or equal to $20 has a 50 percent tax, so include that in the final price. Try to do this in one line! Cast your final answer to an integer to avoid floating point precision errors. For example, if x contains your final answer, return int(x)! def total_price(prices): Finds the total price of all products in prices including a 50% tax on products with a price greater than or equal to 20. >>> total_price ([5, 20, 30, 71) 87 total_price([8, 4, 3]) >>> total_price ([10, 100, 4]) 164 >>> 15 "*** YOUR CODE HERE ***"arrow_forwardWrite a program that will:• Select a random number between 1 and 100.• Test if the number is prime• Call a function named isPrime(). Pass the number to be tested. isPrime() should test whetherthe number has any factors other than 1 and itself. isPrime() returns either True or False.• isPrime() should use a function isDivisible(x,y) to test if y divides evenly into x. That is,isDivisible() will identify whether y is a factor of x.• Print the resultarrow_forward
- A natural number is prime if it is greater than 1 and has no divisors other than 1 and itself. Example: 8 isn't a prime number, as you can divide it by 2 and 4 (we can't use divisors equal to 1 and 8 as the definition prohibits this). On the other hand, 7 is a prime number as we can't find any legal divisors for it. Your task is to write a function checking whether a number is prime or not. in phython langauge Ques: The function: is called IsPrime() takes one argument (the value to check) returns True if the argument is a prime number, and False otherwise. Hint: try to divide the argument by all subsequent values (starting from 2) and check the remainder - if it's zero, your number cannot be a prime; think carefully about when you should stop the process. If you need to know the square root of any value you can utilize the ** operator. Remember: the square root of x is the same as x**0.5 Write a code that calculates all the prime numbers between 1 and 20. (Hint: Use a loop and…arrow_forwardA natural number is prime if it is greater than 1 and has no divisors other than 1 and itself.Example: 8 isn't a prime number, as you can divide it by 2 and 4 (we can't use divisors equal to 1 and 8 as the definition prohibits this). On the other hand, 7 is a prime number as we can't find any legal divisors for it.Your task is to write a function checking whether a number is prime or not.The function:•is called IsPrime()•takes one argument (the value to check)•returns True if the argument is a prime number, and False otherwise.Hint: try to divide the argument by all subsequent values (starting from 2) and check the remainder - if it's zero, your number cannot be a prime; think carefully about when you should stop the process.If you need to know the square root of any value you can utilize the ** operator. Remember: the square root of x is the same as x**0.5Python programming question Write a code that calculates all the prime numbers between 1 and 20. (Hint: Use a loop and call the…arrow_forwardA natural number is prime if it is greater than 1 and has no divisors other than 1 and itself. Example: 8 isn't a prime number, as you can divide it by 2 and 4 (we can't use divisors equal to 1 and 8 as the definition prohibits this). On the other hand, 7 is a prime number as we can't find any legal divisors for it. Your task is to write a function checking whether a number is prime or not. Please us phython language The function: is called IsPrime() takes one argument (the value to check) returns True if the argument is a prime number, and False otherwise. Hint: try to divide the argument by all subsequent values (starting from 2) and check the remainder - if it's zero, your number cannot be a prime; think carefully about when you should stop the process. If you need to know the square root of any value you can utilize the ** operator. Remember: the square root of x is the same as x**0.5 Write a code that calculates all the prime numbers between 1 and 20. (Hint: Use a loop and…arrow_forward
- As the algorithm performs division of numbers with high precision, it is very common to see really big numbers after the period (for example: 1200.2300001), which is not desirable because of several reasons: may cause confusion to some users when they see such big numbers; uses more memory to store a bigger number; it just does not make sense to display currency number in this format. For this reason, you are going to implement a utility function to format any number into the appropriate currency format, using 2 decimal places. For example: The number 1200.2300001 would be became: 1200.23arrow_forwardWrite a python function that takes a positive integer n as an argument. This function will return the number of positive integers less than n that are co-prime to n. Co-prime Numbers: Two numbers are coprime to each other if they don't have any common divisor except 1. Sample Input 1: 1 Sample Output 1: Reason: Since 1 is the smallest positive integer, there exists no positive integer that is less than and coprime to 1. Sample Input 2: 2 Sample Output 2: 1 Reason: Only 1 doesn't share any common divisor (except 1 itself) with 2. Also, 1 < 2. Sample Input 3: Sample Output 3: Reason: Namely, the two coprime numbers to 6 are 1 and 5. Sample Input 4: 36 Sample Output 4: 12 Reason: The numbers coprime to 36 are 1, 5, 7, 11, 13, 17, 19, 23, 25, 29, 31 and 35arrow_forwardWrite the function that returns the number of days he needs to buy the cost of his first car. Jayesh had some savings (including before the count). On the first Monday, he deposits the first deposit into his bank account. Examples Challenge.NumberOfDays (2050, 1200, 10) → 53\ In JAVA programming languagearrow_forward
- Write a program that paints the 4 areas inside the mxm square as follow: Upper left: black. RGB (0, 0, 0) Upper right: white. RGB (255, 255, 255) Lower left: red. RGB (255, 0, 0) Lower right: random colors Random colors Hint: Define a function that paints one of the four squares. Call the function 4 times to complete the painting. (painting means setting the pixels)arrow_forwardThe ceiling of a floating-point number x is the smallest integer that is still larger than or equal to x. Alternatively, the ceiling of a floating-point number x is what you get when you round x up to the nearest integer. For example, the ceiling of 2.1 is 3, the ceiling of 0.9 is 1, the ceiling of -4.5 is -4, etc. Write a function called ceiling() to compute the ceiling of a float input parameter that returns one integer value. You may not use python’s ceil() or floor() functions. Your function may use int()/float() functions, and the floor division operator (i.e., '//').arrow_forward.Prime NumbersIn this task, you will implement a program that takes as input a number n and produces alist of integers less than or equal to n that are prime. The way to think about a problem isto break it down into individual parts. Start by creating a function isPrime() that checkswhether it’s argument is prime or not. The pseudocode for checking isPrime is givenbelow, there are better ways to do it… this is just one.6Step 1: count = 2Step 2: while count < numberStep 3: if count divides the number evenly return falseStep 4: add 1 to countStep 5: Goto step 2Step 6: return truearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education