Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CSC 110 - Homework 5 - Working with Files Given the following file that stores the number of Computer Science graduates from the years 1970
CSC 110 - Homework 5 - Working with Files Given the following file that stores the number of Computer Science graduates from the years 1970 to 2011: Cs-grads.csv https://drive.google.com/file/d/1PSv7hFU-qPO1Vd3mMFUYbDr06uIPGC4Y/view write a program that reads in the file and finds the percent change in the number of male students, female students and all students for any two given years. Percent change is computed with the following formula: (grads2-grads 1)/grads1 where grads2 is the number of grads year 1, grads2 is the number of grads in year2, and year 1 occurred before year2. Specifically, the program will: . 1. Ask the user to enter the name of the data file. 2. Read the data from the file into four lists: Year, Total #CS Grads, #Male CS Grads, #Female CS Grads 3. Get two years from the user. 4. Compute the percent change for all three values. 5. Print the results Here are a few things to note when working on this program: 1. The data file, cs-grads.csv is in Comma Separated Value (csv) format. If you try to open it by double-clicking, it will likely open in Excel. You can also open it as a text file by using "Open with..." Viewing it as a text file is the better way to look at the data. 2. Your program should have at least these functions: getData - read data from the data file getYears - ask the user to enter 2 years with the second being later than the first computePercentChange - computes the percent change for all grads, male grads and female grads printResults - print the results of the computation main - calls the other functions You may need other functions as well to handle exceptions. 2. Be sure to test that the file entered by the user exists and catch the error with exception handling. 3. Be sure to test that the years entered by the user are valid years in the range in the file and that the first year entered is earlier than the second year entered. Your output will look something like this: >>> main() Please the name of the data file: csgrads.csv Invalid file name try again ... Please the name of the data file: cs-grads.csv Enter a year: 1987a Invalid entry, try again... Enter a year: 1987 Enter a year: 1997 Percent change overall: -36.07% Percent change male: -28.64 % Percent change female: -50.05% 2) Using the same data file, add a function to the program above that creates a new data file containing the year and the percent change in number of female graduates from the previous year. Note that your data should start with 1972 since there is no previous year for 1971. The output file that your program will create looks like this: 1972,0.4228395061728395 1973, 0.3882863340563991 1974,0.21875 1975, 0.22179487179487178 1976, 0.1731374606505771 1977,0.3694096601073345 1978, 0.20966688438928804 1979,0.3212742980561555 1980, 0.3780138945647732 1981, 0.4587781731909846 1982,0.43301484041471844 1983, 0.2659951766207973 1984,0.3472658000896459 1985,0.19637361723363553 1986, 0.051793659621802005 1987,-0.08751404587216603 1988,-0. 18601955813111193 1989,-0.16196493726083475 1990,-0.1305086545609005 1991,-0.09770395701025891 1992,-0.03410936654033568 1993,-0.03125 1994,0.012440329813395053 1995, 0.007715387912558937 1996,-0.04310222600311924 1997, 0.021632834493999113 1998, 0.08150833937635968 1999, 0.10808636180769747 2000, 0.2831901246520634 2001,0. 15240969536923513 2002,0.13781815205826992 2003, 0.11364453715025534 2004,-0.03746044048311051 2005, -0.195732402871905 2006,-0.18446520941097946 2007,-0.19918158567774935 2008,-0.1336228921819111 2009,-0.0004423473901503981 2010, 0.05900575306092344 2011,0.057807494079955425
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