作业要求在CourseDatabase类中实现find_course,在成员变量courses中寻找与传入的字符串course_title相同的course,返回std::optionalCourse实现main函数中利用Monadic将std::optionalCourse转化为std::stringCourse包含值则返回Found course: title,number_of_units,quarter\n否则返回Course not found.\n问题及解决and_then transform or_else的具体写法std::optionalCoursecourse;course.and_then([](constCoursecrs)-std::optionalstd::string{return...});course.transform([](constCoursecrs)-std::string{return...});course.or_else([]()-std::optionalstd::string{return...});注意各个lambda函数的传入的参数和返回值format的使用对于Found course: title,number_of_units,quarter\n这种字符串打印需求可以使用std::formatstd::format(Found course: {},{},{}\n,crs.title,crs.number_of_units,crs.quarter);main.cpp代码/* * CS106L Assignment 6: Explore Courses * Created by Haven Whitney with modifications by Jacob Roberts-Baca and Fabio * Ibanez. */#includealgorithm#includetype_traits#includevector#includeoptional#includeautograder/utils.hpp/** * A course. This should be familiar from Assignment 1! */structCourse{std::string title;std::string number_of_units;std::string quarter;/** * You dont have to ignore this anymore! Were defining the operator for * the Course struct. */booloperator(constCourseother)const{returntitleother.titlenumber_of_unitsother.number_of_unitsquarterother.quarter;}};classCourseDatabase{public:CourseDatabase(std::string filename){autolinesread_lines(filename);std::transform(lines.begin(),lines.end(),std::back_inserter(courses),[](std::string line){autopartssplit(line,,);returnCourse{parts[0],parts[1],parts[2]};});}/** * Finds a course in the database with the given title, if it exists. * param course_title The title of the course to find. * return You will need to figure this out! */std::optionalCoursefind_course(std::string course_title){for(constautoelem:courses){if(elem.titlecourse_title){returnelem;}}return{};}private:std::vectorCoursecourses;};intmain(intargc,char*argv[]){static_assert(!std::is_same_vstd::invoke_result_tdecltype(CourseDatabase::find_course),CourseDatabase,std::string,FillMeIn,You must change the return type of CourseDatabase::find_course to something other than FillMeIn.);if(argc2){CourseDatabasedb(autograder/courses.csv);autocoursedb.find_course(argv[1]);/******************************************************** STUDENT_TODO: Populate the output string with the right information to print Please pay special attention to the README here ********************************************************/std::string outputcourse.and_then([](constCoursecrs)-std::optionalstd::string{returnstd::format(Found course: {},{},{}\n,crs.title,crs.number_of_units,crs.quarter);}).or_else([]()-std::optionalstd::string{returnCourse not found.\n;}).value();/******************************************************** DO NOT MODIFY ANYTHING BELOW THIS LINE PLEASE ********************************************************/std::coutoutputstd::endl;return0;}returnrun_autograder();}