Task 1 :

Write a program that determines if a year is a leap year or a common year. The program will display a message which will prompt the user to introduce a year between 1500 and 4000. If the user introduces a number less than 1500 or greater than 4000, the program will display a warning message that the number is less than 1500 or greater than 4000 respectively (see sample runs below) and will prompt the user to introduce another valid number. Please not that the program will not end, instead it will keep asking the user to introduce a number until a valid number (year) will be entered.

The rule to determine if a year is a leap year is as follows: if the year is divisible by 4 then the year is a leap year, otherwise the year is a common year. However, there is an exception to the rule: years that are evenly divisible by 100 are not leap years, unless they are also evenly divisible by 400, in which case they are leap years (e.g. 1600 and 2000 were leap years, but 1700, 1800 and 1900 were not). Either way, the program will display an appropriate message.

Sample Run 1 (the text in red represents the user input):

Please introduce a year (between 1500 and 4000)

1200

The year is not valid. The year must be greater than 1500

Please introduce a year (between 1500 and 4000)

4701

The year is not valid. The year must be less than 4000

Please introduce a year (between 1500 and 4000)

2008

The year is a leap year.

Sample Run 2 (the text in red represents the user input):

Please introduce a year (between 1500 and 4000)

2007

The year is not a leap year. Project #1 CSC 2000

Task 2 (100 points)

The State Highway Traffic Violations Bureau wants you to write a program to compute the amount for a speeding violation. The program will prompt the user to enter the driver’s name (both first name and last name, separated by a space) and the illegal speed in miles per hour at which the person was driving. Calculate the fine as follows: if the illegal speed was less than 70 miles per hour, the fine is $50 plus $5 for each mile per hour over the legal limit of 55. If the illegal speed was greater than 70 miles per hour, the fine is $125 plus $10 for each mile per hour over 70. The fine should be formatted as fixed decimal having two decimal places. (50 points)

Modify the previous program so that the names and the speeds are being read from a file called speeds.txt and generates a file with the name fines.txt. (50 points)

Sample content for files speeds.txt and fines.txt:

speeds.txt
FirstNameA LastNameA 68
FirstNameB LastNameB 72 / fines.txt
Speeding fine for FirstNameA LastNameA: $115.00 / 68 MPH
Speeding fine for FirstNameB LastNameB: $145.00 / 72 MPH

Task 3

Design a game which will prompt the user to guess a number n between 0 and 100 (n is generated randomly by the program at each execution). The user will be asked to enter numbers between 0 and 100 until he guesses the number generated by the computer: if the number introduced by the user is lower/greater than n then a message will be displayed saying that the number the user has guessed is lower/higher than the number that has to be guessed.

The program will also keep track of the number of attempts the user made to guess the number and will display it after the number is guessed.

Sample Run (the text in red represents the user input):

Note: Computer randomly generates 78 (but it’s not displayed on the screen).

What number was generated?

40

The number is greater than 40.

What number was generated?

50

The number is greater than 50.

What number was generated?

80

The number is lower than 80.

What number was generated?

78

Congratulations you guessed the correct number in 4 attempts!!!

Task 4:

Modify the previous program so that if the user does not guess the number in less than 5 attempts, then the program will display the message “You did not guess the number in 5 attempts. The program will now exit!” and will terminate the program. The program should also keep track of the number of attempts left and display an appropriate message, like the blue message in the following example.

Sample Run 1 (the text in red represents the user input):

Note: Computer randomly generates 78 (but it’s not displayed on the screen).

What number was generated?

40

The number is greater than 40. You have 4 attempts left.

What number was generated?

50

The number is greater than 50. You have 3 attempts left.

What number was generated?

90

The number is lower than 90. You have 2 attempts left.

What number was generated?

85

The number is lower than 85. You have 1 attempt left.

What number was generated?

80

The number is lower than 80. You have 0 attempts left.

You did not guess the number in 5 attempts. The program will now exit!

Sample Run 2 (the text in red represents the user input):

Note: Computer randomly generates 78 (but it’s not displayed on the screen).

What number was generated?

40

The number is greater than 40. You have 4 attempts left.

What number was generated?

80

The number is lower than 80. You have 3 attempts left.

What number was generated?

78

Congratulations you guessed the correct number in 3 attempts!!!