Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need this code to read information from file. courseInformation.txt this is a hash table i am having trouble with the program reading from the file
Need this code to read information from file. courseInformation.txt this is a hash table i am having trouble with the program reading from the file please help
#include
#include
#include
#include
Define a structure for Course details
struct Course
std::string name;
std::vector prerequisites;
;
Function to load courses into the hash table
void loadCoursesstd::unorderedmap& courses
coursesCSCIntroduction to Computer Science", ;
coursesCSCIIntroduction to Programming in C;
coursesCSCIData Structures", CSCI;
coursesCSCAdvanced Programming in CCSCI;
coursesCSCIntroduction to Algorithms", CSCI;
coursesCSCOperating Systems", CSCI;
coursesCSCLarge Software Development", CSCI "CSCI;
coursesMATHDiscrete Mathematics", ;
std::cout "Data structure loaded successfully." std::endl;
Function to print the list of courses
void printCourseListconst std::unorderedmap& courses
std::cout "Here is a sample schedule:" std::endl;
for const auto& pair : courses
std::cout pair.first pair.second.name std::endl;
Function to print details of a specific course
void printCourseconst std::unorderedmap& courses
std::string courseId;
std::cout "What course do you want to know about? ;
std::cin courseId;
auto it courses.findcourseId;
if it courses.end
std::cout itfirst itsecond.name std::endl;
if itsecond.prerequisites.empty
std::cout "Prerequisites: ;
for const std::string& prereq : itsecond.prerequisites
std::cout prereq ;
std::cout std::endl;
else
std::cout "Course not found." std::endl;
int main
std::unorderedmap courses;
int choice;
while true
std::cout "Welcome to the course planner." std::endl;
std::cout Load Data Structure." std::endl;
std::cout Print Course List." std::endl;
std::cout Print Course." std::endl;
std::cout Exit" std::endl;
std::cout "What would you like to do;
std::cin choice;
switch choice
case :
loadCoursescourses;
break;
case :
printCourseListcourses;
break;
case :
printCoursecourses;
break;
case :
std::cout "Thank you for using the course planner." std::endl;
return ;
default:
std::cout choice is not a valid option." std::endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started