Menu
Coddy logo textTech

E-Learning Platform

Part of the Object Oriented Programming section of Coddy's C++ journey — lesson 103 of 104.

challenge icon

Challenge

Easy

Let'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 base User class and two derived classes: Student and Instructor.

    Your base User should have a name and ID, with a virtual getRole() method that returns the user type as a string, and a getInfo() method that returns "[name] ([id]) - [role]".

    The Student class tracks enrolled course IDs (use a vector of strings) and completed lesson counts. Add methods enrollInCourse(const std::string& courseId), completedLesson() to increment the count, and getCompletedCount().

    The Instructor class stores a specialty string and tracks course IDs they teach. Add addCourse(const std::string& courseId) and getSpecialty().

  • Lesson.h: Build a lesson hierarchy using an abstract base class.

    Your Lesson base class should have a title and duration (in minutes), with a pure virtual complete() method that returns a completion message, and a getType() method returning the lesson type.

    Create three derived classes:

    • VideoLesson: Has a video URL. Its complete() returns "Watched video: [title]"
    • QuizLesson: Has a number of questions. Its complete() returns "Completed quiz: [title] ([questions] questions)"
    • TextLesson: Has a word count. Its complete() returns "Read article: [title]"

    Each should override getType() to return "Video", "Quiz", or "Text" respectively.

  • Course.h: Create a Course class 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 course
    • getLessonCount() — returns the number of lessons
    • getLesson(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 LessonFactory class with a static method createLesson(const std::string& type, const std::string& title, int duration, const std::string& extra) that returns a std::unique_ptr<Lesson>.

    The type parameter determines which lesson to create ("video", "quiz", or "text"). The extra parameter 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 central Platform class that coordinates everything.

    Store courses as std::vector<std::shared_ptr<Course>> and users as std::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 nullptr
    • findUser(const std::string& id) — returns shared_ptr or nullptr
    • enrollStudent(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:

    1. Platform name
    2. Course details (format: title,courseId,instructorId)
    3. Student details (format: name,studentId)
    4. 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: 1

With 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: 1

This 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