Question: Need this code to read information from file. courseInformation.txt #include #include #include #include / / Define a structure for Course details struct Course { std::string

Need this code to read information from file. courseInformation.txt
#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 loadCourses(std::unordered_map& courses){
courses["CSC100"]={"Introduction to Computer Science", {}};
courses["CSCI101"]={"Introduction to Programming in C++",{}};
courses["CSCI200"]={"Data Structures", {"CSCI101"}};
courses["CSC1301"]={"Advanced Programming in C++",{"CSCI101"}};
courses["CSC1300"]={"Introduction to Algorithms", {"CSCI200"}};
courses["CSC1350"]={"Operating Systems", {"CSCI200"}};
courses["CSC1400"]={"Large Software Development", {"CSCI301", "CSCI350"}};
courses["MATH201"]={"Discrete Mathematics", {}};
std::cout << "Data structure loaded successfully." << std::endl;
}
// Function to print the list of courses
void printCourseList(const std::unordered_map& 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 printCourse(const std::unordered_map& courses){
std::string courseId;
std::cout << "What course do you want to know about? ";
std::cin >> courseId;
auto it = courses.find(courseId);
if (it != courses.end()){
std::cout << it->first <<","<< it->second.name << std::endl;
if (!it->second.prerequisites.empty()){
std::cout << "Prerequisites: ";
for (const std::string& prereq : it->second.prerequisites){
std::cout << prereq <<"";
}
std::cout << std::endl;
}
} else {
std::cout << "Course not found." << std::endl;
}
}
int main(){
std::unordered_map courses;
int choice;
while (true){
std::cout << "Welcome to the course planner." << std::endl;
std::cout <<"1. Load Data Structure." << std::endl;
std::cout <<"2. Print Course List." << std::endl;
std::cout <<"3. Print Course." << std::endl;
std::cout <<"9. Exit" << std::endl;
std::cout << "What would you like to do?";
std::cin >> choice;
switch (choice){
case 1:
loadCourses(courses);
break;
case 2:
printCourseList(courses);
break;
case 3:
printCourse(courses);
break;
case 9:
std::cout << "Thank you for using the course planner." << std::endl;
return 0;
default:
std::cout << choice <<" is not a valid option." << std::endl;
}
}
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!