Reading your input and printing out information from a text file

My program has to find the value I input and print out the information from the file that corresponds to the information. I got my program to read the entire file but still having trouble with reading individual lines and words. I need it to be coded in a class as well. If anyone can give pointers that would be great. Here are the lab requirements:

When printing out president’s information, your output must use the format below. Use the test case below for your program input, for example, for option 1 (search person’s information based on name), if your input is Reagan then the output is :
Ronald Reagan (1911 –2004) Age: 93
Presidency #40 from January 20, 1981 to January 20, 1989 Party: Rebulican

If input is Obama, the output is:
Barack Obama (1961 –Present) Age: 56
Presidency #44 from January 20, 2009 to January 20, 2017 Party: Democratic

If input is Adam, the output is:
John Adams (1735 –1826) Age: 91
Presidency #2 from March 4, 1797 to March 4, 1801 Party: Federalist

John Quincy Adams (1767 –1848) Age: 81
Presidency #6 from March 4, 1825 to March 4, 1829 Party: Democratic

For Option 2, search president information based on presidency term. Use the test case below:

If input is -10, your program will reject this output and ask user to reenter a positive number.
If the input is 40, your program will print out:

Ronald Reagan (1911 –2004) Age: 93
Presidency #40 from January 20, 1981 to January 20, 1989 Party: Rebulican

If the input is 44, your program will print out:

Barack Obama (1961 –Present) Age: 56
Presidency #44 from January 20, 2009 to January 20, 2017 Party: Democratic

This is the textfile:

1; George Washington; April 30, 1789 ; March 4, 1797 ; Independent; 1732; 1799
2; John Adams; March 4, 1797 ; March 4, 1801 ; Federalist; 1735; 1826
3; Thomas Jefferson; March 4, 1801 ; March 4, 1809 ; Democratic; 1743; 1826
4; James Madison; March 4, 1809 ; March 4, 1817 ; Democratic; 1751; 1836
5; James Monroe; March 4, 1817 ; March 4, 1825 ; Democratic; 1758; 1831
6; John Quincy Adams; March 4, 1825 ; March 4, 1829 ; Democratic; 1767; 1848
7; Andrew Jackson; March 4, 1829 ; March 4, 1837 ; Democratic; 1767; 1845
8; Martin Van Buren; March 4, 1837 ; March 4, 1841 ; Democratic; 1782; 1862
9; William Henry Harrison; March 4, 1841 ; April 4, 1841 ; Whig; 1773; 1841
10; John Tyler; April 4, 1841 ; March 4, 1845 ; Whig; 1790; 1862
11; James K. Polk; March 4, 1845 ; March 4, 1849 ; Democratic; 1795; 1849
12; Zachary Taylor; March 4, 1849 ; July 9, 1850 ; Whig; 1784; 1850
13; Millard Fillmore; July 9, 1850 ; March 4, 1853 ; Whig; 1800; 1874
14; Franklin Pierce; March 4, 1853 ; March 4, 1857 ; Democratic; 1804; 1869
15; James Buchanan; March 4, 1857 ; March 4, 1861 ; Democratic; 1791; 1838
16; Abraham Lincoln; March 4, 1861 ; April 15, 1865 ; Republican; 1809; 1865
17; Andrew Johnson; April 15, 1865 ; March 4, 1869 ; Democratic; 1808; 1875
18; Ulysses S. Grant; March 4, 1869 ; March 4, 1877 ; Republican; 1822; 1885
19; Rutherford B. Hayes; March 4, 1877 ; March 4, 1881 ; Republican; 1822; 1893
20; James A. Garfield; March 4, 1881 ; September 19, 1881 ; Republican; 1831; 1881
21; Chester A. Arthur; September 19, 1881 ; March 4, 1885 ; Republican; 1829; 1886
22; Grover Cleveland; March 4, 1885 ; March 4, 1889 ; Democratic; 1837; 1908
23; Benjamin Harrison; March 4, 1889 ; March 4, 1893 ; Republican; 1833; 1901
24; Grover Cleveland; March 4, 1893 ; March 4, 1897 ; Democratic; 1837; 1908
25; William McKinley; March 4, 1897 ; September 14, 1901 ; Republican; 1743; 1901
26; Theodore Roosevelt; September 14, 1901 ; March 4, 1909 ; Republican; 1858; 1919
27; William Howard Taft; March 4, 1909 ; March 4, 1913 ; Republican; 1857; 1930
28; Woodrow Wilson; March 4, 1913 ; March 4, 1921 ; Democratic; 1856; 1924
29; Warren G. Harding; March 4, 1921 ; August 2, 1923 ; Republican; 1865; 1923
30; Calvin Coolidge; August 2, 1923 ; March 4, 1929 ; Republican; 1872; 1933
31; Herbert Hoover; March 4, 1929 ; March 4, 1933 ; Republican; 1874; 1964
32; Franklin D. Roosevelt; March 4, 1933 ; April 12, 1945 ; Democratic; 1882; 1945
33; Harry S. Truman; April 12, 1945 ; January 20, 1953 ; Democratic; 1884; 1972
34; Dwight D. Eisenhower; January 20, 1953 ; January 20, 1961 ; Republican; 1890; 1969
35; John F. Kennedy; January 20, 1961 ; November 22, 1963 ; Democratic; 1917; 1963
36; Lyndon B. Johnson; November 22, 1963 ; January 20, 1969 ; Democratic; 1908; 1973
37; Richard Nixon; January 20, 1969 ; August 9, 1974 ; Republican; 1913; 1994
38; Gerald Ford; August 9, 1974 ; January 20, 1977 ; Republican; 1913; 2006
39; Jimmy Carter; January 20, 1977 ; January 20, 1981 ; Democratic; 1924; 0
40; Ronald Reagan; January 20, 1981 ; January 20, 1989 ; Republican; 1911; 2004
41; George H. W. Bush; January 20, 1989 ; January 20, 1993 ; Republican; 1924; 0
42; Bill Clinton; January 20, 1993 ; January 20, 2001 ; Democratic; 1946; 0
43; George W. Bush; January 20, 2001 ; January 20, 2009 ; Republican; 1946; 0
44; Barack Obama; January 20, 2009 ; January 20, 2017 ; Democratic; 1961; 0
45; Donald Trump; January 20, 2017 ; 0; Republican; 1946; 0
Last edited on
Topic archived. No new replies allowed.