0

im doing a school project and i choosed a quizz... I decided to do it with random order so my Idea is to make every question as object which has property of correct answer, question content itself etc... and i did it. But i wanna to seperate this class, constuructor and objects into different files to have cleaner code and have the ability to rewrite questions and answers anytime i want... but i really dont know how to do it...

Im thankful for every answer :)

class QuestionsLayout
    {
       public:
           string questionName;
           char corans;
           string ans1;
           string ans2;
           string ans3;
           string ans4;
           QuestionsLayout(string questionname, char corAns, string Ans1, string Ans2, string Ans3, string Ans4)
           {
               questionName = questionname;
               corans = corAns;
               ans1 = Ans1;
               ans2 = Ans2;
               ans3 = Ans3;
               ans4 = Ans4;
           }
    
    };
    
    int main()
    {
    
    
    
        //Questions and Answers (rewritable)
        QuestionsLayout q1("What is largest in Solar System?", 'A', "A - Sun", "B - Jupiter", "C - Mercury", "D - Pluto");
        QuestionsLayout q2("What symbol has Helium?", 'C', "A - Hc", "B - Ha", "C - He", "D - H");
        QuestionsLayout q3("How many Mammal Species we know?", 'D', "A - 5256", "B - 3586", "C - 8235", "D - 5416");
    
    }
TheSillus
  • 19
  • 2
  • Start by moving the class to a header. Next create a cpp file and move your constructor to the cpp file. Note that when you define a member function outside of the class you need to prefix it with the classname and :: so `QuestionsLayout::` – drescherjm Dec 25 '20 at 20:15
  • I suggest reading: https://www.learncpp.com/cpp-tutorial/programs-with-multiple-code-files/ and at least up to and including 2.12 - Header guards – Lily Dec 25 '20 at 20:21

0 Answers0