School timetable

School timetable

A handy reference for students.

At the beginning of the academic year students are issued with a timetable to show which lessons they have each week. In this program a school week is five days, each with six lessons, but this could easily be changed.


It is helpful for students to create their own copy of their timetable as a handy reference. This program allows the user to create, save, load and output a timetable.

Assessment


These objectives get progressively harder. Attempt as much of the program as you can in the order presented below. Remember to use a comment to describe a subpprogram, selection or iteration.

Use this boilerplate code as a starting point:

Success Criteria

Setting up and visualising the table

  • In the main program declare a 2D array called `timetable` of six lessons each of five days, with all elements initialised to be "---".

1 mark

You can visualise the initial timetable like this. Each row is a day 1-5 and each column is a lesson 1-6:

1
2
3
4
5
6
1

===

===

===

===

===

===

2

===

===

===

===

===

===

3

===

===

===

===

===

===

4

===

===

===

===

===

===

5

===

===

===

===

===

===

User menu

  • Define a subprogram called `menu` that takes the array `timetable` as a parameter.
  • Ouput five choices for the user: 1. output timetable, 2. Edit a lesson, 3. Load, 4. Save, 5. Close.
  • Ask the user to input a choice from 1-5.
  • Repeat the step above until the user makes a valid input.
  • Use a loop to repeat all the steps in this subprogram until the user chooses "5".
  • Add a call to `menu` to the main program.

6 marks

Edit a lesson

  • Define a subprogram called `edit_lesson` that takes the array `timetable` array as a parameter.
  • Prompt the user to enter the day and lesson they want to edit.
  • Prompt the user to enter the name of the subject.
  • Store the data in the timetable array.
  • Output that the lesson has been updated.
  • Return the timetable.
  • Add a call to the `edit_lesson` subprogram in the `menu` subprogram if the user chose option 2.

7 marks

Formatting the subject name

  • Define a subprogram called `subject_code` that takes the name of a subject as a parameter.
  • The subject is changed to uppercase.
  • The subject should be three characters, padded with spaces if it is less than three characters. E.g. Maths is Mat. PE is PE followed by one space.
  • Return the formatted subject.
  • Change the subprogram `edit_lesson` so that the subject code is written to the array, not the input the user entered.

5 marks

Loading a timetable from a file

  • Define a subprogram called `load` that takes the array `timetable` as a parameter.
  • Load the timetable from a CSV file called `timetable.txt` and store the data in the timetable array.
  • - Add a call to the `load` subprogram in the `menu` subprogram if the user chose option 3.

3 marks

Saving the timetable to a file

  • Define a subprogram called `save` that takes the array `timetable` as a parameter.
  • Save the timetable array to a CSV file called `timetable.txt`
  • The format of the CSV file must be compatible with the `load` subprogram so that the timetable can be loaded and saved.
  • Add a call to the `save` subprogram in the `menu` subprogram if the user chose option 4.

4 marks

Saving the timetable to a file

  • Define a subprogram called `save` that takes the array `timetable` as a parameter.
  • Save the timetable array to a CSV file called `timetable.txt`
  • The format of the CSV file must be compatible with the `load` subprogram so that the timetable can be loaded and saved.
  • Add a call to the `save` subprogram in the `menu` subprogram if the user chose option 4.

4 marks

Displaying the timetable

  • Define a subprogram called `output` that takes the array `timetable` as a parameter.
  • Output the timetable in the format shown below. Note the row and column headings plus the lesson separators.
  • Add a call to the `output` subprogram in the `menu` subprogram if the user chose option 1.

3 marks

The output should now look like this:

1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 1


|-1-||-2-||-3-||-4-||-5-||-6-|

1|===||===||===||===||===||===|

2|===||===||===||===||===||===|

3|===||===||===||===||===||===|

4|===||===||===||===||===||===|

5|===||===||===||===||===||===|


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 2


Which day do you want to edit? 1-14: 3

Which lesson do you want to edit? 1-6: 5

Enter the subject: ENG

Lesson updated.


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 1


|-1-||-2-||-3-||-4-||-5-||-6-|

1|===||===||===||===||===||===|

2|===||===||===||===||===||===|

3|===||===||===||===||ENG||===|

4|===||===||===||===||===||===|

5|===||===||===||===||===||===|


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 5

Good programming practices

  • The subprograms and main program sections are signified with comments.
  • The subprograms have a comment to describe their purpose.

2 marks

Maximum mark: 35

If you score less than 28 you need more practice at levels 1-9 before you continue to the next level.

Help

Use these resources as a reference to help you meet the success criteria.

Programming guide:

Evaluate


Run the unit tests below to check that your program has met the success criteria.


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 4


Timetable saved.


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 3


Timetable loaded.


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 1


|-1-||-2-||-3-||-4-||-5-||-6-|

1|===||===||===||===||===||===|

2|===||===||===||===||===||===|

3|===||===||===||===||===||===|

4|===||===||===||===||===||===|

5|===||===||===||===||===||===|


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 5


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 2


Which day do you want to edit? 1-5: 1

Which lesson do you want to edit? 1-6: 1

Enter the subject: ENG

Lesson updated.


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 2


Which day do you want to edit? 1-5: 1

Which lesson do you want to edit? 1-6: 2

Enter the subject: MAT

Lesson updated.


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 1


|-1-||-2-||-3-||-4-||-5-||-6-|

1|ENG||MAT||===||===||===||===|

2|===||===||===||===||===||===|

3|===||===||===||===||===||===|

4|===||===||===||===||===||===|

5|===||===||===||===||===||===|


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 5


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 2


Which day do you want to edit? 1-5: 1

Which lesson do you want to edit? 1-6: 1

Enter the subject: English

Lesson updated.


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 2


Which day do you want to edit? 1-5: 2

Which lesson do you want to edit? 1-6: 1

Enter the subject: Science

Lesson updated.


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 1


|-1-||-2-||-3-||-4-||-5-||-6-|

1|ENG||===||===||===||===||===|

2|SCI||===||===||===||===||===|

3|===||===||===||===||===||===|

4|===||===||===||===||===||===|

5|===||===||===||===||===||===|


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 5


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 2


Which day do you want to edit? 1-5: 5

Which lesson do you want to edit? 1-6: 6

Enter the subject: French

Lesson updated.


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 2


Which day do you want to edit? 1-5: 1

Which lesson do you want to edit? 1-6: 1

Enter the subject: Spanish

Lesson updated.


1. Output timetable

2. Edit a lesson

3. Load

4. Save

5. Close

Enter choice: 4


Timetable saved.


1. Output timetable