Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will manage your school course schedule. The program should

ID: 672732 • Letter: W

Question

Write a program that will manage your school course schedule. The program should allow you to enter a list of your courses and have them saved in a file. It should also allow you to read a previously created course list from a file and display it on the screen. The course information should include: Course code and name, meeting day and time, building, room number, and instructor. The program should allow the user to make repeated requests until they choose to exit. The program should have an option to print out a list that just includes Course code, Meeting day/time, Building, and Room number. The program should use at least two struct types and one enumerated type.

Explanation / Answer

#include <iostream>
#include <fstream>
#include <string>
#include <list>
#include <stdlib.h>
using namespace std;

/*
* Programme functions:
* 1. Enter the list of courses
* 2. Save the list of courses to a file.
* 3. Read a previously created course list from a file.
* 4. Display the list containing course code, Meeting day/time, Building, and Room number.
* 5. Option to exit the programme.
* Course details to capture: Course code, course name, meeting day/time, building, room number, instructor name.
*/

//Enum for weekdays
typedef enum week_day{
   Monday,
   Tuesday,
   Wednesday,
   Thursday,
   Friday,
   Saturday,
   Sunday
};

//Structure for meeting time
typedef struct meeting_time{
   week_day day;
   int hours;   //Should be entered in 24 hours format. Should be between 0 and 24.
   int minutes;//Should be between 0 and 59;
};

//Structure for course details
typedef struct course_details{
   std::string course_code;
   string course_name;
   meeting_time time;
   string building_name;
   string room_no;
   string instructor_name;
};

//container for course list
std::list<course_details> course_list;

//course list file name
string course_list_file="course_list.dat";

//function to capture course details
course_details enter_course_details()
{
   course_details course;
   cout<<"Enter course code:";
   cin>>course.course_code;
   cout<<"Enter course name:";
   cin>>course.course_name;
   cout<<"Enter meeting time day[Format:Monday=1,Tuesday=2,Wednesday=3,Thursday=4,Friday=5,Saturday=6,Sunday=7]:";
   int d;
   cin>>d;
   course.time.day=(week_day)d;
   cout<<"Enter meeting time hours[Format:between 0 and 24]:";
   cin>>course.time.hours;
   cout<<"Enter meeting time minutes[Format:between 0 and 59]:";
   cin>>course.time.minutes;
   cout<<"Enter building name:";
   cin>>course.building_name;
   cout<<"Enter room no.:";
   cin>>course.room_no;
   cout<<"Enter instructor name:";
   cin>>course.instructor_name;

   return course;
}

//function to add a course to course list
void add_course_to_list(course_details course)
{
   course_list.push_back(course);
}

//function to save course list to file
bool save_course_list(string filename, list<course_details> lst)
{
   std::ofstream file;
   file.open(filename.c_str());
   if(file.is_open())
   {
       list<course_details>::iterator i;
       for(i=lst.begin();i!=lst.end();i++)
       {
           file.write((char*)&(i),sizeof(course_details));
       }
   return true;
   }
   return false;
}

bool read_course_list(string filename)
{
   std::ifstream file;
   file.open(filename.c_str());
   if(file.is_open())
   {
   file.read((char*)&course_list,sizeof(course_details));
   return true;
   }
   return false;
}

void display_course_list()
{
   list<course_details>::iterator i;
   for(i=course_list.begin();i!=course_list.end();i++)
   {
       if(i!=NULL)
       {
           cout<<*i<<endl;
       }
   }
}
int main() {
   int option;
   while(1){
       cout<<"Available options (Press key corresponding to option no.):"<<endl;
       cout<<"1. Enter course list."<<endl;
       cout<<"2. Save course list."<<endl;
       cout<<"3. Read and display course list."<<endl;
       cout<<"4. Exit."<<endl;
       cin>>option;
       switch(option){
       case 1:
           cout<<"No. of courses in list."<<endl;
           int n;
           cin>>n;
           cout<<"Course list creation starts..."<<endl;
           for(int i=1;i<=n;i++)
           {
               cout<<"Enter course "<<i<<":";
               course_details course=enter_course_details();
               add_course_to_list(course);
           }
           cout<<"Course list creation finished!"<<endl;
           break;
       case 2:
           cout<<"Saving course list..."<<endl;
           save_course_list(course_list_file,course_list);
           cout<<"Course list saved to "<<course_list_file<<endl;
           break;
       case 3:
           cout<<"Reading file "<<course_list_file<<"..."<<endl;
           read_course_list(course_list_filename);
           cout<<"Reading file finished."<<endl;
           cout<<"Displaying list..."<<endl;
           display_course_list();
           break;
       case 4:
           exit(1);
       default:
           cout<<"Wrong option. Re-enter:"<<endl;
           break;
       }
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote