E-Learning Platform
Part of the Object Oriented Programming section of Coddy's C++ journey — lesson 103 of 104.
Challenge
EasyLet's build an E-Learning Platform that brings together all the OOP concepts you've mastered throughout this course. You'll create a system that manages courses, different types of lessons, and tracks student progress — demonstrating inheritance hierarchies, polymorphism, smart pointers, and design patterns working in harmony.
You'll organize your code across six files:
User.h: Create a user hierarchy with a baseUserclass and two derived classes:StudentandInstructor.Your base
Usershould have a name and ID, with a virtualgetRole()method that returns the user type as a string, and agetInfo()method that returns"[name] ([id]) - [role]".The
Studentclass tracks enrolled course IDs (use a vector of strings) and completed lesson counts. Add methodsenrollInCourse(const std::string& courseId),completedLesson()to increment the count, andgetCompletedCount().The
Instructorclass stores a specialty string and tracks course IDs they teach. AddaddCourse(const std::string& courseId)andgetSpecialty().Lesson.h: Build a lesson hierarchy using an abstract base class.Your
Lessonbase class should have a title and duration (in minutes), with a pure virtualcomplete()method that returns a completion message, and agetType()method returning the lesson type.Create three derived classes:
VideoLesson: Has a video URL. Itscomplete()returns"Watched video: [title]"QuizLesson: Has a number of questions. Itscomplete()returns"Completed quiz: [title] ([questions] questions)"TextLesson: Has a word count. Itscomplete()returns"Read article: [title]"
Each should override
getType()to return"Video","Quiz", or"Text"respectively.Course.h: Create aCourseclass that owns its lessons using smart pointers.A course has a title, ID, and instructor ID. Store lessons as
std::vector<std::unique_ptr<Lesson>>since the course owns its lessons exclusively.Add methods:
addLesson(std::unique_ptr<Lesson> lesson)— transfers ownership of the lesson to the coursegetLessonCount()— returns the number of lessonsgetLesson(size_t index)— returns a pointer to the lesson at that index (or nullptr if invalid)displayCurriculum()— prints each lesson's type and title in format"[index]. [Type]: [title]"
LessonFactory.h: Implement the Factory pattern to create different lesson types.Create a
LessonFactoryclass with a static methodcreateLesson(const std::string& type, const std::string& title, int duration, const std::string& extra)that returns astd::unique_ptr<Lesson>.The
typeparameter determines which lesson to create ("video","quiz", or"text"). Theextraparameter contains type-specific data: URL for video, question count for quiz (parse as int), or word count for text (parse as int).Platform.h: Build the centralPlatformclass that coordinates everything.Store courses as
std::vector<std::shared_ptr<Course>>and users asstd::vector<std::shared_ptr<User>>.Implement:
addCourse(std::shared_ptr<Course> course)addUser(std::shared_ptr<User> user)findCourse(const std::string& id)— returns shared_ptr or nullptrfindUser(const std::string& id)— returns shared_ptr or nullptrenrollStudent(const std::string& studentId, const std::string& courseId)— finds both, enrolls the student, prints"Enrolled [name] in [course title]"or"Enrollment failed"completeLesson(const std::string& studentId, const std::string& courseId, size_t lessonIndex)— finds the student and course, calls the lesson's complete() method, increments student's completed count, prints the completion message or"Could not complete lesson"
main.cpp: Bring everything together to demonstrate your platform.Read four inputs:
- Platform name
- Course details (format:
title,courseId,instructorId) - Student details (format:
name,studentId) - Lesson to add (format:
type,title,duration,extra)
Create the platform and display
"Welcome to [platform name]!". Create the course and student, add them to the platform. Use the LessonFactory to create the lesson and add it to the course. Display the course curriculum. Enroll the student in the course. Complete the first lesson (index 0) for that student. Finally, print the student's info and their completed lesson count as"Completed lessons: [count]".
For example, with inputs CodeAcademy, C++ Mastery,CPP101,I001, Alice,S001, and video,Introduction to OOP,30,https://example.com/oop:
Welcome to CodeAcademy!
1. Video: Introduction to OOP
Enrolled Alice in C++ Mastery
Watched video: Introduction to OOP
Alice (S001) - Student
Completed lessons: 1With inputs LearnHub, Python Basics,PY100,I002, Bob,S002, and quiz,Variables Quiz,15,10:
Welcome to LearnHub!
1. Quiz: Variables Quiz
Enrolled Bob in Python Basics
Completed quiz: Variables Quiz (10 questions)
Bob (S002) - Student
Completed lessons: 1This challenge demonstrates how real e-learning platforms are structured — with clear separation between users, content, and the platform that coordinates them. The Factory pattern makes lesson creation flexible, smart pointers ensure safe memory management, and polymorphism lets you treat all lesson types uniformly while each behaves uniquely.
Try it yourself
#include <iostream>
#include <string>
#include <sstream>
#include <memory>
#include "User.h"
#include "Lesson.h"
#include "Course.h"
#include "LessonFactory.h"
#include "Platform.h"
int main() {
// Read inputs
std::string platformName;
std::getline(std::cin, platformName);
std::string courseDetails; // format: title,courseId,instructorId
std::getline(std::cin, courseDetails);
std::string studentDetails; // format: name,studentId
std::getline(std::cin, studentDetails);
std::string lessonDetails; // format: type,title,duration,extra
std::getline(std::cin, lessonDetails);
// TODO: Parse courseDetails to extract title, courseId, instructorId
// TODO: Parse studentDetails to extract name, studentId
// TODO: Parse lessonDetails to extract type, title, duration, extra
// TODO: Create the platform and display "Welcome to [platform name]!"
// TODO: Create the course and student, add them to the platform
// TODO: Use LessonFactory to create the lesson and add it to the course
// TODO: Display the course curriculum
// TODO: Enroll the student in the course
// TODO: Complete the first lesson (index 0) for the student
// TODO: Print the student's info and completed lesson count
// Format: "Completed lessons: [count]"
return 0;
}
All lessons in Object Oriented Programming
1Fundamentals of OOP
External FilesC++ Build & CompilationHeader Files & Source FilesNamespaces & ScopeIntroduction to OOP in C++Classes vs ObjectsThe 'this' PointerMethods (Member Functions)Attributes (Data Members)Ctors & Dtors BasicsRecap - Simple Calculator4Class Properties
Instance vs Static MembersGetters and SettersConst Member FunctionsMutable KeywordStatic Methods and VariablesFriend Functions & ClassesRecap - Bank Account Manager7Inheritance
Basic InheritanceInheritance Access LevelsCtor & Dtor Call OrderMethod OverridingVirtual Functions & VTableMultiple InheritanceVirtual InheritanceRecap - Employee Hierarchy2Memory Management
Stack vs Heap MemoryPointers and ReferencesDynamic Memory (new/delete)Smart Pointers in C++RAII in C++Recap - Dynamic Array Manager5Encapsulation
Access Specifiers in C++Access Specifiers In DepthInformation HidingStruct vs ClassNested & Inner ClassesRecap - Student Records System8Polymorphism
Compile vs Runtime PolymorphFunction OverloadingVirtual Functions RevisitedPure Virtual FunctionsAbstract ClassesInterface Design in C++Dynamic Casting & RTTIRecap - Shape Calculator3Constructors & Destructors
Default ConstructorParameterized ConstructorCopy ConstructorMove ConstructorConstructor Init ListsDelegating ConstructorsDestructor Deep DiveRule of Three / Five / ZeroRecap - String Class6Operator Overloading
Intro to Operator OverloadArithmetic Operator OverloadComparison Operator OverloadStream OperatorsAssignment Operator Overload[] and () Operator OverloadType Conversion OperatorsRecap - Matrix Class9Templates
Function TemplatesClass TemplatesTemplate SpecializationVariadic TemplatesSFINAE & Type Traits BasicsRecap - Generic Container