Question:
In programming, how would you output information in the format of a timetable?
anonymous
2017-02-16 12:45:07 UTC
Say you want to create a timetable from Monday to Sunday which uses information from the database such as Subject, Time, Classroom, etc. How can you output the information to be structured in a grid format, sort of like the following image:
http://www.parishceschool.com/uploads/asset_image/2_164.png

The reason I'm not sure is because there is not a class for every time slot. One whole timetable grid could only have two or three classes. So it's not as simple as just outputting everything into a grid in order.

I'm not asking for the actual code, just a general explanation / pseudo-code. The code uses SQL and C#, although I don't think this matters in the explanation.
Three answers:
husoski
2017-02-16 16:00:40 UTC
There seem to be two questions here...how to structure the data and how to get that kind of output format.



For that specific table, with a fixed number of columns and "ragged" column lengths, I'd probably use a list or array of columns at the major data structure, then have each entry in that list be a list of entries in that column. "Probably", because it might turn out to be more convenient to use whatever data model is required by the API I'll be using to display the table; and also the data my already be sorted by an SQL query, so that the display code may not have to worry about sorting columns.



For output, there are two general approaches commonly used. One is to use a GUI for onscreen display. With C# (or VB.NET), that would be either a WPF application or an older Windows Forms application. Java, Python and others each have different options.



Another strategy, is to produce the output in the form of a spreadsheet or word processor document (usually MS Excel or Word formats) for "offline" viewing, printing, manual markup for discussion, conversion to PDF, etc. MS provides some developer tools for WInAPI and .NET languages, and there are third party packages for Python and the Apache POI libraries for Java for more portable solutions.
bruh
2017-02-16 14:23:57 UTC
use english
Chris
2017-02-16 13:26:27 UTC
The table you posted is basically a collection of unrelated columns, so first you create a 2D array for the entire table, then you loop over the columns, read the respective events for that day from the DB, then use an inner loop to add them to the table.

If you initialize all grid cells to empty, you can fill them as necessary, then just print the entire table.



If this were a schedule I had to use, I'd make the rows consistent though, exactly like Google calendar for instance.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...