Select a random student

From Computer Science Wiki
Jump to: navigation, search
This a problem set for you to work through [1]

This is a problem set. Some of these are easy, others are far more difficult. The purpose of these problems sets are:

  1. to build your skill applying computational thinking to a problem
  2. to assess your knowledge and skills of different programming practices


What is this problem set trying to do

I am testing your current ability to think about a problem and solve it. There isn't a right or wrong here, just demonstrating what you know. In broad strokes, this problem set requires you to:

  1. REALLY understand the problem
  2. Think about how you might solve the problem
  3. Create a solution to the problem
  4. Test if your solution works (solves the problem)


The Problem

I teach 5 classes. I am interested in creating a system to randomly call on students in my classes. I would prefer not to call on the same student twice during one class. At the end of a class, I would like to know who I called and who I did not call on. Please reflect on your computational thinking skills & ask me questions which will help you designProduce a plan, simulation or model. this system.

The input

The input will be five different buttons which represent each of my five classes. For example:

  • Class 1
  • Class 2
  • Class 3
  • Class 4
  • Class 5

The output

The output of this program will be:

  1. the first name of a student from a class, randomly selected. I will provide you with a listGive a sequence of brief answers with no explanation. of first names for my students.
  2. you should store the students you have called in a listGive a sequence of brief answers with no explanation. (even though for now, you will only select only one).

A possible solution

Click the expand link to see one possible solution, but NOT before you have tried and failed!

<!-- the file below should be named random.html there is another file, below.-->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Choose a random student</title>
</head>
<body>
<form action="random.php" method="post">

    <fieldset>
        <legend>Select a class</legend>

        <input type="radio" id="classes" name="block" value="1">Block 1<br>
        <input type="radio" id="classes" name="block" value="2">Block 2<br>
        <input type="radio" id="classes" name="block" value="4">Block 4<br>
        <input type="radio" id="classes" name="block" value="5">Block 5<br>

        <button type="submit">Click here to select a student</button>
    </fieldset>

</form>
</body>
</html>
<!-- and below is the random.php file -->
<?php
session_start();

$chosenClass = $_POST['block'];

if($chosenClass==1){

    if(ISSET($_SESSION['block1Students'])){

        $block1Students = $_SESSION['block1Students'];
        $randomStudent = array_rand($block1Students);
        echo "We are choosing <strong>$block1Students[$randomStudent]</strong>";
        unset($block1Students[$randomStudent]);
        $_SESSION['block1Students'] = $block1Students;
        $countOfStudents = count($block1Students);
        echo "<br><br>";
        echo "There are $countOfStudents left to choose.";

        if ($countOfStudents == 0) {

            echo"<br>You have chosen all your students<br>";
            $block1Students=  ["Cesur","Maciej","Tarik","Emily","Cameron","Michael","Vera","Avi","Jaegeun","Lucia","Andrea","Aleksandra","John","Changseok","Alex","Sua","Harry"];
            $_SESSION['block1Students'] = $block1Students;
        }

        echo "<br><br> <a href=\"random.html\">Click here to choose another student</a>";

    } else {

        $block1Students=  ["Cesur","Maciej","Tarik","Emily","Cameron","Michael","Vera","Avi","Jaegeun","Lucia","Andrea","Aleksandra","John","Changseok","Alex","Sua","Harry"];
        echo "This is the first time, we are going to create the array<br>";
        $_SESSION['block1Students'] = $block1Students;
        $block1Students = $_SESSION['block1Students'];
        $randomStudent = array_rand($block1Students);
        echo "We are choosing <strong>$block1Students[$randomStudent]</strong>";
        unset($block1Students[$randomStudent]);
        $_SESSION['block1Students'] = $block1Students;
        $countOfStudents = count($block1Students);
        echo "<br><br>";
        echo "There are $countOfStudents left to choose.";

        if ($countOfStudents == 0) {

            echo"<br>You have chosen all your students<br>";
            $block1Students=  ["Cesur","Maciej","Tarik","Emily","Cameron","Michael","Vera","Avi","Jaegeun","Lucia","Andrea","Aleksandra","John","Changseok","Alex","Sua","Harry"];
            $_SESSION['block1Students'] = $block1Students;
        }
        echo "<br><br> <a href=\"random.html\">Click here to choose another student</a>";


    }
} elseif($chosenClass==2) {

    if(ISSET($_SESSION['block2Students'])){

        $block2Students = $_SESSION['block2Students'];
        $randomStudent = array_rand($block2Students);
        echo "We are choosing <strong>$block2Students[$randomStudent]</strong>";
        unset($block2Students[$randomStudent]);
        $_SESSION['block2Students'] = $block2Students;
        $countOfStudents = count($block2Students);
        echo "<br><br>";
        echo "There are $countOfStudents left to choose.";

        if ($countOfStudents == 0) {

            echo "<br>You have chosen all your students<br>";
            $block2Students = ["Dominik", "QingYu", "David", "Przemyslaw", "Stanislaw", "Sven", "Marcin", "Jan", "Siddharth", "Wojciech", "Mikolaj", "Yoon", "Chan Woo", "Maksymilian"];
            $_SESSION['block2Students'] = $block2Students;
        }
        echo "<br><br> <a href=\"random.html\">Click here to choose another student</a>";

        } else {

        $block2Students = ["Dominik","QingYu","David","Przemyslaw","Stanislaw","Sven","Marcin","Jan","Siddharth","Wojciech","Mikolaj","Yoon","Chan Woo","Maksymilian"];
        echo "This is the first time, we are going to create the array<br>";
        $_SESSION['block2Students'] = $block2Students;
        $block2Students = $_SESSION['block2Students'];
        $randomStudent = array_rand($block2Students);
        echo "We are choosing <strong>$block2Students[$randomStudent]</strong>";
        unset($block2Students[$randomStudent]);
        $_SESSION['block2Students'] = $block2Students;
        $countOfStudents = count($block2Students);
        echo "<br><br>";
        echo "There are $countOfStudents left to choose.";

            if ($countOfStudents == 0) {

                echo "<br>You have chosen all your students<br>";
                $block2Students = ["Dominik", "QingYu", "David", "Przemyslaw", "Stanislaw", "Sven", "Marcin", "Jan", "Siddharth", "Wojciech", "Mikolaj", "Yoon", "Chan Woo", "Maksymilian"];
                $_SESSION['block2Students'] = $block2Students;
            }
        echo "<br><br> <a href=\"random.html\">Click here to choose another student</a>";

    }

} elseif($chosenClass==4) {

    if(ISSET($_SESSION['block4Students'])){

        $block4Students = $_SESSION['block4Students'];
        $randomStudent = array_rand($block4Students);
        echo "We are choosing <strong>$block4Students[$randomStudent]</strong>";
        unset($block4Students[$randomStudent]);
        $_SESSION['block4Students'] = $block4Students;
        $countOfStudents = count($block4Students);
        echo "<br><br>";
        echo "There are $countOfStudents left to choose.";
            if ($countOfStudents == 0) {

                echo "<br>You have chosen all your students<br>";
                $block4Students = ["Emre", "Zofia", "Sheevankit", "Zofia", "Nguyen", "Mahmood", "Felix", "Siddharth", "Maximo", "Jasper", "Alexander", "Franciszek", "Seung Won", "Gabriele", "Annie"];
                $_SESSION['block4Students'] = $block4Students;
            }
        echo "<br><br> <a href=\"random.html\">Click here to choose another student</a>";

            } else {

        $block4Students = ["Emre", "Zofia", "Sheevankit", "Zofia", "Nguyen", "Mahmood", "Felix", "Siddharth", "Maximo", "Jasper", "Alexander", "Franciszek", "Seung Won", "Gabriele", "Annie"];
        echo "This is the first time, we are going to create the array<br>";
        $_SESSION['block4Students'] = $block4Students;
        $block4Students = $_SESSION['block4Students'];
        $randomStudent = array_rand($block4Students);
        echo "We are choosing <strong>$block4Students[$randomStudent]</strong>";
        unset($block4Students[$randomStudent]);
        $_SESSION['block4Students'] = $block4Students;
        $countOfStudents = count($block4Students);
        echo "<br><br>";
        echo "There are $countOfStudents left to choose.";
            if ($countOfStudents == 0) {

                echo "<br>You have chosen all your students<br>";
                $block4Students = ["Emre", "Zofia", "Sheevankit", "Zofia", "Nguyen", "Mahmood", "Felix", "Siddharth", "Maximo", "Jasper", "Alexander", "Franciszek", "Seung Won", "Gabriele", "Annie"];
                $_SESSION['block4Students'] = $block4Students;
            }
        echo "<br><br> <a href=\"random.html\">Click here to choose another student</a>";

    }

} elseif($chosenClass==5) {

    if(ISSET($_SESSION['block5Students'])){

        $block5Students = $_SESSION['block5Students'];
        $randomStudent = array_rand($block5Students);
        echo "We are choosing <strong>$block5Students[$randomStudent]</strong>";
        unset($block5Students[$randomStudent]);
        $_SESSION['block5Students'] = $block5Students;
        $countOfStudents = count($block5Students);
        echo "<br><br>";
        echo "There are $countOfStudents left to choose.";
        if ($countOfStudents == 0) {

            echo "<br>You have chosen all your students<br>";
            $block5Students = ["Taylor", "Andrew", "Marta", "Aron", "Tomasz", "Cameron", "Tomasz", "Taekyung", "David", "Filip", "Juwon", "Maximilian", "Haruka", "Norval", "Aleksander", "Maxwell", "Ian", "Yilin"];
            $_SESSION['block5Students'] = $block5Students;
        }
        echo "<br><br> <a href=\"random.html\">Click here to choose another student</a>";

        } else {

        $block5Students = ["Taylor", "Andrew", "Marta", "Aron", "Tomasz", "Cameron", "Tomasz", "Taekyung", "David", "Filip", "Juwon", "Maximilian", "Haruka", "Norval", "Aleksander", "Maxwell", "Ian", "Yilin"];
        echo "This is the first time, we are going to create the array<br>";
        $_SESSION['block5Students'] = $block5Students;
        $block5Students = $_SESSION['block5Students'];
        $randomStudent = array_rand($block5Students);
        echo "We are choosing <strong>$block5Students[$randomStudent]</strong>";
        unset($block5Students[$randomStudent]);
        $_SESSION['block5Students'] = $block5Students;
        $countOfStudents = count($block5Students);
        echo "<br><br>";
        echo "There are $countOfStudents left to choose.";
        if ($countOfStudents == 0) {

            echo "<br>You have chosen all your students<br>";
            $block5Students = ["Taylor", "Andrew", "Marta", "Aron", "Tomasz", "Cameron", "Tomasz", "Taekyung", "David", "Filip", "Juwon", "Maximilian", "Haruka", "Norval", "Aleksander", "Maxwell", "Ian", "Yilin"];
            $_SESSION['block5Students'] = $block5Students;
        }
        echo "<br><br> <a href=\"random.html\">Click here to choose another student</a>";

    }

} else {

    echo "ERROR: invalid class!!!!! How are you here?!?! ";
}

How you will be assessed

Your solution will be graded using the following axis:


Scope

  • To what extentConsider the merits or otherwise of an argument or concept. Opinions and conclusions should be presented clearly and supported with appropriate evidence and sound argument. does your code implement the features required by our specification?
  • To what extentConsider the merits or otherwise of an argument or concept. Opinions and conclusions should be presented clearly and supported with appropriate evidence and sound argument. is there evidence of effort?

Correctness

  • To what extentConsider the merits or otherwise of an argument or concept. Opinions and conclusions should be presented clearly and supported with appropriate evidence and sound argument. did your code meet specifications?
  • To what extentConsider the merits or otherwise of an argument or concept. Opinions and conclusions should be presented clearly and supported with appropriate evidence and sound argument. did your code meet unit tests?
  • To what extentConsider the merits or otherwise of an argument or concept. Opinions and conclusions should be presented clearly and supported with appropriate evidence and sound argument. is your code free of bugs?

DesignProduce a plan, simulation or model.

  • To what extentConsider the merits or otherwise of an argument or concept. Opinions and conclusions should be presented clearly and supported with appropriate evidence and sound argument. is your code written well (i.e. clearly, efficiently, elegantly, and/or logically)?
  • To what extentConsider the merits or otherwise of an argument or concept. Opinions and conclusions should be presented clearly and supported with appropriate evidence and sound argument. is your code eliminating repetition?
  • To what extentConsider the merits or otherwise of an argument or concept. Opinions and conclusions should be presented clearly and supported with appropriate evidence and sound argument. is your code using functions appropriately?

Style

  • To what extentConsider the merits or otherwise of an argument or concept. Opinions and conclusions should be presented clearly and supported with appropriate evidence and sound argument. is your code readable?
  • To what extentConsider the merits or otherwise of an argument or concept. Opinions and conclusions should be presented clearly and supported with appropriate evidence and sound argument. is your code commented?
  • To what extentConsider the merits or otherwise of an argument or concept. Opinions and conclusions should be presented clearly and supported with appropriate evidence and sound argument. are your variables well named?


References