- ahmad alhayek

 C++ code please

A Class for Questions (15 points) Create a class named Question in files question.h and question.cpp. Data Members Each questCreate a class named MathQuestion in files math_question.h and math_question.cpp. This class represents an addition, subtractCreate a class named MCQ in files mcq.h and mcq.cpp. This class represents a multiple-choice question (MCQ). The class must iThe second constructor is a copy constructor. A Make sure that the two constructors do a deep copy of the array of choices. IImplement a simple program in test.cpp to test the three classes you have implemented. Your program must perform the followinHow far is PSUT from Jerusalem? 0.65 km 1. 100km 2. 150km 3. 250km 65km CORRECT! How much is the distance between PSUT and JeShuffling Choices (15 points) Implement the function void shuffle (MCQ& question) that shuffles the choices in the given MCQ

Show transcribed image text

Expert Answerinformation icon

  • Anonymous's Avatar

    // C++ Program to shuffle a given array
    #include<bits/stdc++.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;

    // A utility function to swap to integers
    void swap (int *a, int *b)
    {
       int temp = *a;
       *a = *b;
       *b = temp;
    }

    // A utility function to print an array
    void printArray (int arr[], int n)
    {
       for (int i = 0; i < n; i++)
           cout << arr[i] << " ";
       cout << "\n";
    }

    // A function to generate a random
    // permutation of arr[]
    void randomize (int arr[], int n)
    {
       // Use a different seed value so that
       // we don't get same result each time
       // we run this program
       srand (time(NULL));

       // Start from the last element and swap
       // one by one. We don't need to run for
       // the first element that's why i > 0
       for (int i = n - 1; i > 0; i--)
       {
           // Pick a random index from 0 to i
           int j = rand() % (i + 1);

           // Swap arr[i] with the element
           // at random index
           swap(&arr[i], &arr[j]);
       }
    }

    // Driver Code
    int main()
    {
       int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};
       int n = sizeof(arr) / sizeof(arr[0]);
       randomize (arr, n);
       printArray(arr, n);

       return 0;
    }

    // This code is contributed by
    // rathbhupendra

    Comment 

ليست هناك تعليقات:

إرسال تعليق

ahmad alhayek تصميم ahmad alhayek جميع الحقوق محفوظة 2016

صور المظاهر بواسطة sndr. يتم التشغيل بواسطة Blogger.