Jump to content

I am working on a quiz for my school coursework and i cantI can't seem to figure out how to get this class iI have made to work with this form.

I am making a quiz and when you start the quiz you are brought to a screen that will say what topic number you are on and what the name of the topic is: Pic of topic page (The create user button is a placeholder) but i want the topic to be random each time and the topic number to increment each time you get to the topic page as after you finish on topic it will go back to that page and do the selection again. so far i have this as a class

namespace ChemistryQuizMock
{
    public class ChooseTopic
    {

        //init variables
        private string topic_name;
        private int topic_count;
        private int random_topic_number;
        //init topics
        private string[] topic_list = new string[]
        {
            "Chemical Calculations",
            "Acids And Bases",
            "Bonding",
            "Rates Of Reactions",
            "Metal Extraction",
            "Exothermic And Endothermic Reactions",
            "The Periodic Table"
        };

        //get set variables
        public string TopicName { get; set; }
        public int TopicCount { get; set; }
        public int RandomTopicNumber { get; set; }
        public string[] TopicList { get; set; }

        //constructor
        public ChooseTopic(string TopicName, int TopicCount,int RandomTopicNumber,string[] TopicList)
        {
            TopicName = topic_name;
            TopicCount = 1;
            RandomTopicNumber = random_topic_number;
            TopicList = topic_list;
        }
       

        //pick a random topic from the list
        public void PickRandomTopic()
        {
            Random rTopic = new Random();
            RandomTopicNumber = rTopic.Next(0,TopicList.Length);
        }       

        //turn to list remove item and return to array
        public void RemoveTopicFromList()
        {
            var list = new List<string>(TopicList);
            list.RemoveAt(RandomTopicNumber);
            list.ToArray();
        }

        //increase topic count
        public void IncreaseTopicCount()
        {
            TopicCount++;
        }
    }
}

and this is the form cod

namespace ChemistryQuizMock
{
    public partial class TopicPage : Form
    {   
            public TopicPage()
            {
                InitializeComponent();
                CenterToScreen();
                
            }
    }
}

 

I'm very new to c# and don't know how to make it so i can use this class in the form and all i really know is it has to be a class because the array of topics has to be in a class as topics are removed after they have been done..

any help??

Link to comment
https://linustechtips.com/topic/862719-help-with-c-class/
Share on other sites

Link to post
Share on other sites

2 hours ago, KianFitz said:

I'd love to help but I don't quite understand the wording.

 

You want a random topic number and then you want to increment a number after the question has been answered?

after you click start on the start quiz screen you go to the topic screen. on the topic screen there is "topic number: x" (In this case because its the first time on this screen x would be 1 as this is the 1st topic) and there is also "Topic name"(which is replaced with the name of the first topic).

 

the random selector would work by when that form is loaded  it should select a topic from my TopicList array and set the "Topic name" to be the string stored in that array. it should then remove that topic from the array as we dont want to do the topic again. after the topic has been set the player can click and it will go to the first form of questions from that topic.

 

When the last question from that topic is finished you return to the topic page. the topic number will increment by 1(so it will say "Topic: 2" this time) and the name of the topic will be chosen at random from the list again...

 

i want it to work this way so that every time the quiz is played the topics are asked in a different order.

 

sorry about my previous wording hopefully this enplanes it a bit better.

Link to comment
https://linustechtips.com/topic/862719-help-with-c-class/#findComment-10726799
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×