// Converted easily to html with the excellent export feature of Dev-C++

//Madlib.cpp
//Brian LeBaron
//Originally written October 4, 1999. Revised April 12, 2003

#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>
using namespace std;

//Function prototypes
void printmenu();
int getchoice();
void getwords(string word[], const int NumberofWords);
void madlib1();
void madlib2();
void madlib3();
void madlib4();
void partsofspeech();


int main()
{
    int choice = 0;

    system("cls");

    do
    {
        printmenu();
        choice = getchoice();
    } while (choice != 6);

    return 0;
}

//Function to print main menu
void printmenu()
{
    cout << "Welcome to U.S. Historical Mad Libs!" << endl;
    cout << "by Brian LeBaron" << endl;
    cout << "-------------------------------------------------------" << endl;
    cout << "\nThis program will ask you for several nouns," << endl;
    cout << "verbs, adjectives, adverbs, names, or any other type of" << endl;
    cout << "word to be placed in certain locations in some document." << endl;
    cout << "The result is usually a humorous adaptation." << endl;
    cout << "The more colourful you make your words, the more colourful" << endl;
    cout << "the new document will be." << endl;
    cout << "\t\t\nYou may choose one of the following: " << endl;
    cout << "\n\t1 - Mad Lib #1: Constitution Pollution" << endl;
    cout << "\t2 - Mad Lib #2: Gettysburg Addression Regression" << endl;
    cout << "\t3 - Mad Lib #3: Declaration Consternation" << endl;
    cout << "\t4 - Mad Lib #4: Amendment Unendment" << endl;
    cout << "\t5 - Help on Parts of Speech" << endl;
    cout << "\t6 - Exit Program" << endl;
}

//Function to deal with the menu choice you choose
int getchoice()
{
    int choice;

    cout << "Please enter the number of your choice: ";
    cin >> choice;

    system("cls");

    switch (choice)
    {
        case 1:
            madlib1();
            break;
        case 2:
            madlib2();
            break;
        case 3:
            madlib3();
            break;
        case 4:
            madlib4();
            break;
        case 5:
            partsofspeech();
            break;
        case 6:
            break;
        default:
            cout << "Invalid choice, try again." << endl;
    }
    system("cls");
    return choice;
}

void getwords(string word[], const int NumberofWords)
{
    bool used[NumberofWords];
    int i, iRnd;

    // manually initialize used array to appease compiler
    for (i = 0; i < NumberofWords; i++)
        used[i] = false ;

    srand(time(NULL));   // seed the random number generator

    cout << "\nEnter a(n): " << endl;
        // ask for words in random order
    for (i = 1; i <= NumberofWords; i++)
    {
            // select a random word between 0 and NumberofWords
        iRnd = rand() % NumberofWords;

        if (!used[iRnd])  // if not already used, ask for the appropriate word
        {
            cout << i << ". ";
                // An extra space to line up one and two digit numbers
                if (i < 10)
                    cout << " ";
            cout << word[iRnd] << ": ";
            getline(cin, word[iRnd]);
            used[iRnd] = true;
        }
        else    // if already used, another iteration is needed
        {
            i--;
        }
    }
}

void madlib1()
{
    const int NumberofWords = 11;

    //Variables
    string word[NumberofWords] = { "Plural Noun", "Place", "Adjective",
                                   "Adjective", "Noun", "Noun", "Verb",
                                   "Noun", "Noun", "Verb", "Noun" };

    //Introduction
    cout << "\n-----------Mad Lib #1: Constitution Pollution------------" << endl;
    cout << "\nTime to enter the eleven words..." << endl;
    cin.ignore();

    //Input words
    getwords(word, NumberofWords);


    //Actual Mad-Lib
    cout << "\nHere is your completed Mad Lib ...\n" << endl;

    system("pause");

    cout << "\nWe the [" << word[0] << "] of the [" << word[1] << "], in order to form a" << endl;
    cout <<"more [" << word[2] << "] union, establish justice, insure [" << word[3] << "]" << endl;
    cout <<"tranquility, provide for the common [" << word[4] << "], promote" << endl;
    cout <<"the general [" << word[5] << "], and [" << word[6] << "] the blessings of [" << word[7] << "]" << endl;
    cout <<"to ourselves and our [" << word[8] << "], do [" << word[9] << "] and establish" << endl;
    cout <<"this [" << word[10] << "] for the [" << word[1] << "].\n" << endl;

    system("pause");
}

void madlib2()
{
    const int NumberofWords = 8;

    //Variables
    string word[NumberofWords] = { "Plural Noun", "Past Tense Verb",
                                   "Noun", "Noun", "Noun",
                                   "Past Tense Verb", "Plural Noun",
                                   "Adjective" };



    //Introduction
    cout << "\n--------Mad Lib #2: Gettysburg Addression Regression--------" << endl;
    cout << "\nTime to enter the eight words..." << endl;
    cin.ignore();

    // Input words
    getwords(word, NumberofWords);

    //Actual Mad-Lib
    cout << "\nHere is your completed Mad Lib ..." << endl;

    system("pause");

    cout<< "\nFourscore and seven [" << word[0] << "] ago our fathers [" << word[1] << "]" << endl;
    cout<< "forth on this [" << word[2] <<"], a new [" << word[3] << "], conceived in" << endl;
    cout<< "[" << word[4] << "], and [" << word[5] << "] to the proposition that all" << endl;
    cout<< "[" << word[6] << "] are created [" << word[7] << "].\n" << endl;

    system("pause");
}

void madlib3()
{
    const int NumberofWords = 13; // count of words to be used

    //Variables
    string word[NumberofWords] = { "Plural Noun", "Adjective",
                                   "Verb", "Adjective", "Past Tense Verb",
                                   "Verb", "Plural Noun", "Adjective",
                                   "Plural Noun", "Adjective",
                                   "Person or Group of People",
                                   "Verb", "Noun" };

    //Introduction
    cout << "\n--------Mad Lib #3: Declaration Consternation--------" << endl;
    cout << "\nTime to enter the thirteen words..." << endl;
    cin.ignore();

    //Input words
    getwords(word, NumberofWords);


    //Actual Mad-Lib
    cout << "\nHere is your completed Mad Lib ..." << endl;

    system("pause");

    cout << "\nWhen in the Course of human [" << word[0] << "], it becomes" << endl;
    cout << "[" << word[1] << "] for one people to [" << word[2] << "] the [" << word[3] << "]" << endl;
    cout << "bands which have [" << word[4] << "] them with another, and" << endl;
    cout << "to [" << word[5] << "] among the [" << word[6] << "] of the earth, the" << endl;
    cout << "separate and [" << word[7] << "] station to which the [" << word[8] << "] of" << endl;
    cout << "Nature and of Nature's God entitle them, a [" << word[9] << "]" << endl;
    cout << "respect to the opinions of [" << word[10] << "] requires that" << endl;
    cout << "they should [" << word[11] << "] the causes which impel them to" << endl;
    cout << "the [" << word[12] << "].\n" << endl;

    system("pause");
}

void madlib4()
{
    const int NumberofWords = 11;   // count of words to be used

    //Variables
    string word[NumberofWords] = { "Adjective", "Noun", "Unit of Currency",
                                   "Noun","Past Tense Verb", "Noun", "Adverb",
                                   "Noun", "Place", "Noun", "Adjective" };


    //Introduction
    cout << "\n--------Mad Lib #4: Amendment Unendment--------" << endl;
    cout << "\nIt is time to enter the eleven words..." << endl;
    cin.ignore();

    //Input words
    getwords(word, NumberofWords);

    //Actual Mad-Lib
    cout << "\nHere is your completed Mad Lib ..." << endl;

    system("pause");

    cout << "\nIn suits at [" << word[0] << "] law, where the [" << word[1] << "] in controversy" << endl;
    cout << "shall exceed twenty [" << word[2] << "], the right of [" << word[3] << "] by jury" << endl;
    cout << "shall not be [" << word[4] << "], and no [" << word[5] << "] tried by a jury shall be" << endl;
    cout << "[" << word[6] << "] reexamined in any [" << word[7] << "] of the [" << word[8] << "]," << endl;
    cout << "than according to the [" << word[9] << "] of the [" << word[10] << "] law.\n" << endl;

    system("pause");
}

void partsofspeech()
{
    cout << "Short Glossary of Parts of Speech" << endl;
    cout << "-------------------------------------------------------" << endl;
    cout << "\tNoun - A person, place or thing" << endl;
    cout << "\t\tExamples: mailman, tennis court, tree" << endl;
    cout << "\tProper Noun - A specific noun or the name of something" << endl;
    cout << "\t\tExamples: Bob, Jill, Big Ben" << endl;
    cout << "\tVerb - an action word, what something is doing" << endl;
    cout << "\t\tExamples: run, jump, emancipate" << endl;
    cout << "\tAdjective - A word that describes a noun" << endl;
    cout << "\t\tExamples: red, cool, effervescent" << endl;
    cout << "\tAdverb - A word that describes a verb (Usually ends in -ly)" << endl;
    cout << "\t\tExamples: joyfully, courageously, voraciously" << endl;
    cout << "\tPlural - a noun that includes more than one (Usually just add s)" << endl;
    cout << "\t\tExamples: geese, sheep, deer, spaghetti, Nachschlagen" << endl;
    cout << "\tTense - the form of a verb that tells when something will happen" << endl;
    cout << "\t\t(Past, Present, Future)" << endl;
    cout << "\t\tExamples: galloped (past), gallops (present)," << endl;
    cout << "\t\t\twill gallop (future)\n" << endl;
    cout << "\tDefault to present tense verbs and singular nouns and" << endl;
    cout << "\tyour new historical document should have correct grammar.\n" << endl;

    system("pause");
}
Hosted by www.Geocities.ws

1