Answered step by step
Verified Expert Solution
Link Copied!

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 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_2

Step: 3

blur-text-image_3

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

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

More Books

Students also viewed these Databases questions

Question

=+11. Should changes be introduced to improve the service/product?

Answered: 1 week ago