M programs/program2/program2.c => programs/program2/program2.c +7 -0
@@ 2,6 2,7 @@
#include "parse_csv.h"
#include "print_course.h"
#include "search_course.h"
+#include "weekday_graph.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ 26,6 27,7 @@ int main(void) {
"n - print class given course id\n"
"d - print all classes given day of week combo\n"
"s - print all classes under certain # seats\n"
+ "w - print # classes per weekday\n"
"q - quit\n");
pchoice:
@@ 59,6 61,11 @@ int main(void) {
search_course_upper_bound_seats(max_course, courses, sseats);
break;
}
+ case 'w': {
+ printf("\n"); // Formatting
+ weekday_graph(max_course, courses);
+ break;
+ }
// HACK Shoddy way of handling newlines
// Also handles first pass using labels and manual jumping
case '\n':
A programs/program2/weekday_graph.c => programs/program2/weekday_graph.c +58 -0
@@ 0,0 1,58 @@
+#include "course.h"
+#include <stdio.h>
+
+// Prints a basic table showing the frequency of classes on each day
+void weekday_graph(unsigned int max_course, course_t courses[]) {
+ // Counts of each day
+ unsigned int c_sunday = 0, c_monday = 0, c_tuesday = 0, c_wednesday = 0,
+ c_thursday = 0, c_friday = 0, c_saturday = 0;
+
+ printf(" U | M | T | W | R | F | S \n"); // Header row
+
+ for (unsigned int i = 0; i < max_course; i++) {
+ int j = 0; // Index for the weekday string iterator
+ char sread = 26; // Currently read character w/ dummy value
+
+ // Cycle through weekday string, incrementing trackers
+ while (sread != '\0') {
+ sread = courses[i].weekdays[j]; // Perform the read
+ j += 1; // Increment string index
+
+ // Increment correct weekday tracker
+ switch (sread) {
+ case 'U': {
+ c_sunday += 1;
+ break;
+ }
+ case 'M': {
+ c_monday += 1;
+ break;
+ }
+ case 'T': {
+ c_tuesday += 1;
+ break;
+ }
+ case 'W': {
+ c_wednesday += 1;
+ break;
+ }
+ case 'R': {
+ c_thursday += 1;
+ break;
+ }
+ case 'F': {
+ c_friday += 1;
+ break;
+ }
+ case 'S': {
+ c_saturday += 1;
+ break;
+ }
+ }
+ }
+ }
+
+ // Print output
+ printf("%3u|%3u|%3u|%3u|%3u|%3u|%3u\n\n", c_sunday, c_monday, c_tuesday,
+ c_wednesday, c_thursday, c_friday, c_saturday);
+}
A programs/program2/weekday_graph.h => programs/program2/weekday_graph.h +8 -0
@@ 0,0 1,8 @@
+#ifndef weekday_graph_h
+#define weekday_graph_h
+
+#include "course.h"
+
+void weekday_graph(unsigned int max_course, course_t courses[]);
+
+#endif