Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 2 Lncs 13427

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124251, 978-3031124259

More Books

Students also viewed these Databases questions