C++ basic madlibs generator

Just finished coding a basic madlibs generator with 6 possible scenario. My stories are kinda trash but the code is there. Any feedback is welcome.

#include <iostream>
#include <string>
#include <stdlib.h>
#include <cstdlib>
#include <ctime>
class A {
    protected:
        std::string a, b, c;
    public:
        void form() {
        std::cout << "Hello " << a;
        std::cout << " You and " << b;
        std::cout << " have been chosen to go on a top secret mission based in " << c << ". " << std::endl;
        std::cout << "Good luck" << a;
        }
};
class C {
    protected:
        std::string a, b, c;
    public:
        void form1() {
        std::cout << "Sir " << a;
        std::cout << " Your presance has been requested by the great " << b;
        std::cout << " You have to go to the great lands of " << c << ". ";
        std::cout << " Get thier ASAP" << ". " << std::endl;
        std::cout << "Best of luck " << a;
        }
};
class D {
    protected:
        std::string a, b, c;
    public:
        void form2() {
        std::cout << "The great " << a << ". ";
        std::cout << " Me and my colleges are here to notify you that your grand skills of guitar ";
        std::cout << " Have not gone unnoticed and we are inviting you a dinner held in the centre of " << c << ". ";
        std::cout << " We would like you to preform for me and my colleges when you get here" << ". " << std::endl;
        std::cout << "Hope to see you soon " << a << " From " << b;
        }
};
class E {
    protected:
        std::string a, b, c;
    public:
        void form3() {
        std::cout << a << " and his friend " << b;
        std::cout << " went downtown. ";
        std::cout << "knowing the crime rates of " << c;
        std::cout << " They decided to say home and watch a movie.";
        }
};
class F {
    protected:
        std::string a, b, c;
    public:
        void form4() {
        std::cout << b;
        std::cout << " hated " << a;
        std::cout << " Becuuse " << a;
        std::cout << " hide his violin somewhere in " << c;
        }
};
class G {
    protected:
        std::string a, b, c;
    public:
        void form5() {
        std::cout << c;
        std::cout << " has a crime problem and " << a << " and " << b;
        std::cout << " were going to stop it";
        }
};
class B : A {
    public:
        void base() {
            std::cout << "Enter name: ";
            std::cin >> a;
            std::cout << "Enter name of friend: ";
            std::cin >> b;
            std::cout << "Enter city: ";
            std::cin >> c;
            form();
        }
};
class B1 : C {
    public:
        void base1() {
            std::cout << "Enter name: ";
            std::cin >> a;
            std::cout << "Enter name of friend: ";
            std::cin >> b;
            std::cout << "Enter city: ";
            std::cin >> c;
            form1();
        }
};
class B2 : D {
    public:
        void base2() {
            std::cout << "Enter name: ";
            std::cin >> a;
            std::cout << "Enter name of friend: ";
            std::cin >> b;
            std::cout << "Enter city: ";
            std::cin >> c;
            form2();
        }
};
class B3 : E {
    public:
        void base3() {
            std::cout << "Enter name: ";
            std::cin >> a;
            std::cout << "Enter name of friend: ";
            std::cin >> b;
            std::cout << "Enter city: ";
            std::cin >> c;
            form3();
        }
};
class B4 : F {
    public:
        void base4() {
            std::cout << "Enter name: ";
            std::cin >> a;
            std::cout << "Enter name of friend: ";
            std::cin >> b;
            std::cout << "Enter city: ";
            std::cin >> c;
            form4();
        }
};
class B5 : G {
    public:
        void base5() {
            std::cout << "Enter name: ";
            std::cin >> a;
            std::cout << "Enter name of friend: ";
            std::cin >> b;
            std::cout << "Enter city: ";
            std::cin >> c;
            form5();
        }
};
int main() {
    std::string a;
    std::cout << "To start madlibs generator type generate" << std::endl;
    std::cin >> a;
    system("clear");
    if (a == "generate") {
        srand(time(0));
        int a;
        a = 1+(rand()%6);
        if (a == 1) {
            B object1;
            object1.base();
        }
        if (a == 2) {
            B1 object2;
            object2.base1();
        }
        if (a == 3) {
            B2 object3;
            object3.base2();
        }
        if (a == 4) {
            B3 object4;
            object4.base3();
        }
        if (a == 5) {
            B4 object5;
            object5.base4();
        }
        if (a == 6) {
            B5 object6;
            object6.base5();
        }
    }
return 0;
}

Cool!

It does seem to work, but you need to deal with spaces in input :slight_smile: Great work all the same!

1 Like

I just noticed the randomizer! Nice touch.

1 Like

Do you have any other project ideas?