Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A program is required to print a statement to say which of two dates in a particular year comes first. The program will take

 

# Problem: Compare dates # Input: first day as an integer from 1 to 31 # Input: first month as an integer from 1 to 12 # Inpu

a. i. Describe the data that is expected for the input and the output of this program. ii. What are the admissible values for  

A program is required to print a statement to say which of two dates in a particular year comes first. The program will take four integers to represent the day and month of the first date, and the day and month of the second date. For example, if the first date is 4 July, it would be represented by two integers 4 and 7 and if the second date is 20 December it would be represented by the two integers 20 and 12. You can assume that the month is represented by an integer between 1 and 12 (inclusive) and that the day is an integer that is valid for that month. The program should output a string of one of these forms: The first date is the earliest or The second date is the earliest or The two dates are the same You are given the following test data and an incomplete and error-filled program. Test Number 1 2 3 5 day_1 month_1 day_2 month_2 4 4 4 7 7 7 7 7 Table 3 Test table for Compare dates program 20 1 3 4 5 12 1 7 Expected results The first date is the earliest The second date is the earliest The second date is the earliest The two dates are the same The first date is the earliest # Problem: Compare dates # Input: first day as an integer from 1 to 31 # Input: first month as an integer from 1 to 12 # Input: second day as an integer from 1 to 31 # Input: second month as an integer from 1 to 12 day_1 = 4 month 1 = 7 day_2 = 20 month_2 = 12 # Determine earlier date based only on the month if month 1 month 2:1 answer 'The first date is the earliest' if month 2 month_1 : answer = 'The second date is the earliest' # Determine earlier date if the months are the same. if (month_1 == month_2) and (day_1 < day_2) : answer 'The first date is the earliest' if (month_1 == month_2) and (day_2> day_1) answer 'The second date is the earliest' # Determine if the dates are the same if (month_1 == month_2) and (day_2 == day_1) : answer = 'The two dates are the same print (answer) a. b. i. Describe the data that is expected for the input and the output of this program. ii. What are the admissible values for the inputs? (5 marks) i. What are the syntax errors in this program? Consider no other errors at this point. ii. Once the syntax errors are corrected, which of the above tests would the program still fail and why? Refer to test cases using their Test Number from the first column of the test data table. iii. Give an explanation for the choice of input values shown in the test table. (8 marks) i. The above program is based on the use of Pattern 4.3. Explain why Pattern 4.4 would be better at expressing the multiple cases. ii. Using Pattern 4.4, write an algorithm for the corrected version of the program above. Your algorithm must initialise the two dates to be valid dates. (6 marks) d. Produce code corresponding to the algorithm that you wrote in c.ii. Include comments. Use the test table to check your code works. You do not need to submit test outputs. Paste your completed Python code into your solution document as text and state whether it produced the expected output.

Step by Step Solution

3.44 Rating (160 Votes )

There are 3 Steps involved in it

Step: 1

ANSWER a i The data that is expected for the input of this program is four integers that represent t... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting Information Systems basic concepts and current issues

Authors: Robert Hurt

3rd edition

130855849X, 978-1308558493, 78025338, 978-0078025334

More Books

Students also viewed these Accounting questions

Question

What other publications/presentations does the person have?

Answered: 1 week ago

Question

Explain the principles of recursion and provide examples.

Answered: 1 week ago