Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Pascal code Program 3: President records Input file presidents.txt contains records in the form of text lines, one per U.S. president. Each president record
In Pascal code
Program 3: President records Input file presidents.txt contains records in the form of text lines, one per U.S. president. Each president record contains: The starting year of the president's term (4 digits) The ending year of the president's term (4 digits) The president's first name The president's middle initials with periods (not all presidents have middle initials) The president's last name One or more blanks separate the years and the first and last names and middle initials. There are no blanks inside the first and last names. If a president has more than one initial, they are written together with periods but no blanks. You must assume that the presidents not sorted. Your program should not know in advance how many president records there are. The last president record is followed by a sentinel record that has -1 in place of the starting year. Read and store each president's years, first name, middle initials (if any), and last name in a Pascal record. Store all the records in an array of records that's large enough to hold 20 records. Following the dummy record, there is a list of search years terminated by -1. For each search year, find the president who was in office during that year (there may be more than one president). Input file presidents.txt 2009 2017 Barack Obama 1961 1963 John Kennedy 1981 1989 Ronald Reagan 1993 2001 Bill Clinton 1989 1993 George H.W. Bush 1977 1981 Jimmy Carter 2017 2021 Donald Trump 1963 1969 Lyndon Johnson 1969 1974 Richard Nixon 1974 1977 Gerald Ford 2001 2009 George W. Bush -1 1975 1963 1989 2019 2001 2030 2016 -1 Output Read the input file and store the presidents' data into the array of records, sort the array into ascending order by starting year, and print the presidents in sorted order. Then for each search year, search the array for the matching presidents and print the search year and the matching presidents' names. If there is no match, print "no match". Text input hints If ch is a character variable, then read (ch) will read the next character from the standard input If n is an integer variable, then read (n) will read the next integer value from the standard input A call to readln will skip the rest of the current input line. Then the next call to read will read starting on the next input line. Boolean functions eoln and eof without parameters test whether the standard input is at the end of the current line or at the end of file, respectively. (If you're typing input data into a Windows command window, a line containing only control-Z is the end-of-file marker. On Linux and the Mac, it's control-D.) Use Pascal's built-in string type. Read online how to use the string type: Program 3: President records Input file presidents.txt contains records in the form of text lines, one per U.S. president. Each president record contains: The starting year of the president's term (4 digits) The ending year of the president's term (4 digits) The president's first name The president's middle initials with periods (not all presidents have middle initials) The president's last name One or more blanks separate the years and the first and last names and middle initials. There are no blanks inside the first and last names. If a president has more than one initial, they are written together with periods but no blanks. You must assume that the presidents not sorted. Your program should not know in advance how many president records there are. The last president record is followed by a sentinel record that has -1 in place of the starting year. Read and store each president's years, first name, middle initials (if any), and last name in a Pascal record. Store all the records in an array of records that's large enough to hold 20 records. Following the dummy record, there is a list of search years terminated by -1. For each search year, find the president who was in office during that year (there may be more than one president). Input file presidents.txt 2009 2017 Barack Obama 1961 1963 John Kennedy 1981 1989 Ronald Reagan 1993 2001 Bill Clinton 1989 1993 George H.W. Bush 1977 1981 Jimmy Carter 2017 2021 Donald Trump 1963 1969 Lyndon Johnson 1969 1974 Richard Nixon 1974 1977 Gerald Ford 2001 2009 George W. Bush -1 1975 1963 1989 2019 2001 2030 2016 -1 Output Read the input file and store the presidents' data into the array of records, sort the array into ascending order by starting year, and print the presidents in sorted order. Then for each search year, search the array for the matching presidents and print the search year and the matching presidents' names. If there is no match, print "no match". Text input hints If ch is a character variable, then read (ch) will read the next character from the standard input If n is an integer variable, then read (n) will read the next integer value from the standard input A call to readln will skip the rest of the current input line. Then the next call to read will read starting on the next input line. Boolean functions eoln and eof without parameters test whether the standard input is at the end of the current line or at the end of file, respectively. (If you're typing input data into a Windows command window, a line containing only control-Z is the end-of-file marker. On Linux and the Mac, it's control-D.) Use Pascal's built-in string type. Read online how to use the string type
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started