HELLO,

i have an project(c++) on quiz(menu based) and im in 11(cbse)

i would like to have the source code with the following
1.admin menu
1.1add more ques
1.2 remove a ques
1.3 modify the ques
1.4 search for a ques
1.5 return to main menu
2.user menu
2.1 instructions
2.2 start the quiz
2.3 return to main menu
3.exit

i would also like to have structure,functions,switch case ........

i would like it to be completed by friday 16/12/2016 afternoon.

its urgent

Dani AI

Generated

A focused, in-memory approach that satisfies the "structures + functions, no files" constraint and implements admin/user flows is shown below. The snippet is a compact, runnable skeleton: it uses a Question struct, a std::vector to hold questions, separate functions for add/remove/modify/search, and switch-case menus for admin/user. Because data is kept only in memory, the question bank will be lost when the program exits — persistence can be added later if allowed.

#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <cctype>

struct Question {
    std::string text;
    std::vector<std::string> options;
    int correct; // 0-based index
};

std::string toLower(const std::string &s) {
    std::string r = s;
    for (size_t i = 0; i < r.size(); ++i) r[i] = std::tolower((unsigned char)r[i]);
    return r;
}

int readInt() {
    std::string line;
    std::getline(std::cin, line);
    return std::atoi(line.c_str());
}

void listQuestions(const std::vector<Question> &bank) {
    for (size_t i = 0; i < bank.size(); ++i)
        std::cout << (i+1) << ") " << bank[i].text << "\n";
}

void addQuestion(std::vector<Question> &bank) {
    Question q;
    std::cout << "Enter question:\n";
    std::getline(std::cin, q.text);
    q.options.resize(4);
    for (int i = 0; i < 4; ++i) {
        std::cout << "Option " << (i+1) << ": ";
        std::getline(std::cin, q.options[i]);
    }
    std::cout << "Correct option number (1-4): ";
    q.correct = readInt() - 1;
    if (q.correct < 0 || q.correct > 3) q.correct = 0;
    bank.push_back(q);
}

void removeQuestion(std::vector<Question> &bank) {
    if (bank.empty()) { std::cout << "No questions.\n"; return; }
    listQuestions(bank);
    std::cout << "Enter number to remove: ";
    int idx = readInt() - 1;
    if (idx >= 0 && idx < (int)bank.size()) bank.erase(bank.begin() + idx);
    else std::cout << "Invalid index\n";
}

void modifyQuestion(std::vector<Question> &bank) {
    if (bank.empty()) { std::cout << "No questions.\n"; return; }
    listQuestions(bank);
    std::cout << "Enter number to modify: ";
    int idx = readInt() - 1;
    if (idx < 0 || idx >= (int)bank.size()) { std::cout << "Invalid.\n"; return; }
    Question &q = bank[idx];
    std::cout << "New text (blank to keep): ";
    std::string tmp; std::getline(std::cin, tmp);
    if (!tmp.empty()) q.text = tmp;
    for (size_t i = 0; i < q.options.size(); ++i) {
        std::cout << "Option " << (i+1) << " (blank to keep): ";
        std::getline(std::cin, tmp);
        if (!tmp.empty()) q.options[i] = tmp;
    }
    std::cout << "Correct option number (1-4, 0 to keep): ";
    int c = readInt();
    if (c >= 1 && c <= 4) q.correct = c - 1;
}

int searchQuestion(const std::vector<Question> &bank, const std::string &key) {
    std::string k = toLower(key);
    for (size_t i = 0; i < bank.size(); ++i)
        if (toLower(bank[i].text).find(k) != std::string::npos) return (int)i;
    return -1;
}

void takeQuiz(const std::vector<Question> &bank) {
    if (bank.empty()) { std::cout << "No questions.\n"; return; }
    int score = 0;
    for (size_t i = 0; i < bank.size(); ++i) {
        const Question &q = bank[i];
        std::cout << q.text << "\n";
        for (size_t j = 0; j < q.options.size(); ++j)
            std::cout << " " << (j+1) << ". " << q.options[j] << "\n";
        std::cout << "Your answer: ";
        int ans = readInt() - 1;
        if (ans == q.correct) ++score;
    }
    std::cout << "Score: " << score << "/" << bank.size() << "\n";
}

void adminMenu(std::vector<Question> &bank) {
    for (;;) {
        std::cout << "Admin menu - 1)add 2)remove 3)modify 4)search 5)return\nChoice: ";
        int ch = readInt();
        switch (ch) {
            case 1: addQuestion(bank); break;
            case 2: removeQuestion(bank); break;
            case 3: modifyQuestion(bank); break;
            case 4: {
                std::cout << "Search term: ";
                std::string k; std::getline(std::cin, k);
                int idx = searchQuestion(bank, k);
                if (idx >= 0) std::cout << "Found at " << (idx+1) << ": " << bank[idx].text << "\n";
                else std::cout << "Not found\n";
            } break;
            case 5: return;
            default: std::cout << "Bad choice\n";
        }
    }
}

void userMenu(const std::vector<Question> &bank) {
    for (;;) {
        std::cout << "User menu - 1)instructions 2)start 3)return\nChoice: ";
        int ch = readInt();
        if (ch == 1) std::cout << "Answer by entering option number. Score is shown at end.\n";
        else if (ch == 2) takeQuiz(bank);
        else if (ch == 3) return;
        else std::cout << "Bad choice\n";
    }
}

int main() {
    std::vector<Question> bank;
    for (;;) {
        std::cout << "Main - 1)admin 2)user 3)exit\nChoice: ";
        int ch = readInt();
        if (ch == 1) adminMenu(bank);
        else if (ch == 2) userMenu(bank);
        else if (ch == 3) break;
    }
    return 0;
}

Notes and quick troubleshooting:

  • Use std::getline everywhere to avoid input mixing; numeric input is parsed with atoi for simplicity.
  • Removing uses vector::erase, which shifts subsequent items; present indexes to the admin before delete.
  • Modifying accepts a blank line to keep the current value, which makes small edits easier.
  • Search shown is case-insensitive substring matching.
  • Because the program keeps data in memory only, add a few sample questions in code during testing or add simple import/export later if persistence is permitted.

Context: the OP () said the admin section was the sticking point; this skeleton isolates that area. As and suggested, it is small enough to compile and iterate on so any specific compile errors or runtime behavior can be diagnosed from the concrete code rather than vague descriptions.

Recommended Answers

All 7 Replies

Would you like anything else doing ? Cup of tea? Clean your room? Massage?

Is this the approach you take to everything, that someone else can do it for you?

How about you show us how far you have got on your own so far, and where you are getting stuck? How about you then ask for specific help with that part of your assignment, wthout demanding it by a set date?

commented: I think you need to add these to your profile. Always like a good cup. +11
commented: I'd prefer a cuppa coffee. A massage would be nice. :-) +14

I'm happy to write you a program that you can compile and run. It will compile and run with no errors. I want no money for this. This is your lucky day since you need not put any effort into this at all. In fact, it works best if you don't look at the code at all and don't try to figure out how it works.

Please note this program will only work if you run it as Admin/root, plus it needs to download a few things so turn off your firewall. And we don't want anyone else in on this. The rest of the class needs to struggle with their own homework, but clearly you're special, so I'm going to give this to you and only you, but you need to promise that you'll only run it on your computer. We don't want anyone else stealing your A+. Deal?

Heh heh.

PS - This doesn't violate Daniweb's anti-malware rule, does it? Err I mean this doesn't violate Daniweb's "No help without effort" rule, does it?

commented: Ah, the "How stupid is this dude?" test! +14

IM SORRY HAPPYGREEK

ACTUALLY IM NOT ABLE TO DO THE ADMIN MENU PART FULL

ACTUALLY MY TEACHER WANT ME TO USE STRUCTURES,AND FUNCTIONS WITHOUT USING FILES

WHY ARE YOU YELLING?

It is now past 17:30 EST ... and you will need to ask for an extension if you still need help with your school project ...

In the future ...

if you wish help at this very willing to help, help site,

please firstly supply us with the code you have tried already ...

and indicate where you are having issues ...

and we will then see what we might do to help you on your way.

Shalom shalom,
David

I'M SORRY HAPPYGREEK

δεκτή η συγγνώμη

:-)

The greek text says(thanks to google translate) appologies accepted
Now lets all drink some ouzo and throw the empty glasses over our back while dancing the sirtaki. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.