Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Computer-Assisted Instruction: Programming Exercise: Write a program to allow th

ID: 3711648 • Letter: C

Question

Computer-Assisted Instruction: Programming Exercise: Write a program to allow the user to pick a type of arithmetic problem to study An option of 1 means addition problems only, 2 means subtraction problems only, 3 means multiplication problems only, 4 means division problems only and 5 means random mixture of all these types (Computer- Assisted Instruction) The use of computers in education is referred to as computer- assisted instruction (CAI). Write a program that will help an elementary school student learn arithmetic operations. Use a Random object to produce two positive one- digit integers. The program should then prompt the user with a question, such as How much is 6 times 7? The student then inputs the answer. Next, the program checks the student's answer. If it's correct, display the message "Very good!" and ask another multiplication question. If the answer is wrong, display the message "No. Please try again." and let the student try the same question repeatedly until the student finally gets it right. Modifying Exercise: (Computer- Assisted Instruction: Reducing Student Fatigue) One problem in CAI environments is student fatigue. This can be reduced by varying the computer's responses to hold the student's attention, so that various comments are displayed for each answer as follows: Possible responses to a correct answer: Very good! Excellent Nice work! Keep up the good work! Possible responses to an incorrect answer: No. Please try again. Wrong Try once more. Don't give up! No. Keep trying Use random- number generation to choose a number from 1 to 4 that will be used to select one of the four appropriate responses to each correct or incorrect answer. Use a switch or if statement to issue the responses Modifying Exercise (Computer- Assisted Instruction: Monitoring Student Performance) More sophisticated computer- assisted instruction systems monitor the student's performance over a period of time. Count the number of correct and incorrect responses typed by the student. After the student types 10 answers, your program should calculate the percentages that are correct. If the percentage is lower than 75%, display "Please ask your teacher for extra help.", then reset the program so another student can try it. If the percentage is 75% or higher, display "Congratulations, you are ready to go to the next level". then reset the program so another student can try it

Explanation / Answer

=======================================================================

Complete Program:

Hi I have provided 3 programs to 3 problems asked. The 3 rd solution is final one.

========================================================================

==========================================================================

1st Problem:

#!/usr/bin/perl

use strict;

use warnings;

use feature "switch"; # To use switch like conditioin

# Print the Menu to Student

print "        1. Addition Problems

        2. Substraction Problems

        3. Multiplication Problems

        4. Division Problems

        5. Any of the above types (Random Mixture)

        Please Select one choice from above: ";

# Read choice.

my $choice = <STDIN>;

# chomp remove the trailing ENTER char

chomp($choice);

# print "Choice Entered: $choice";

# Do operation based on the choice given

# Swich Case like syntax

for ($choice) {

        #Addition

   when (1)            { while(1) {

                randomfunc("+");

                                } }

        #Substraction

   when (2)         {   while(1) {

                randomfunc("-");

                                }}

        # Multiplication

   when (3)            { while(1) {

                randomfunc("*");

                                }}

        # Division

   when (4)            { while(1) {

                randomfunc("/");

                                }}

        # Mix

   when (5)            {

                        #my @types = ("added to", "minus", "times", "divided by");

                        my @types = ("+", "-", "*", "/");

                        while(1) {

                                randomfunc($types[rand @types]);

                                } }

        # Exit condition is not mentioned.

}

# random function to do operation based on the input choice sent

# It takes one argument i.e. operator symbol +,-,*,/ and generates the two numbers randomly.

sub randomfunc {

        # read the first argument

        my $type = shift;

       

        # hashmap to to generate the string based on the symbol

        my %typestr = ("+" => "added to",

                        "-" => "minus",

                        "*" => "times",

                        "/" => "divided by");

        # generate 0 to 9 , and add 1 To get only positive numbers.       

        my $var1 = int(rand(9)) + 1;

        my $var2 = int(rand(9)) + 1;

        # For substraction and division make sure first number is larger than second one.

        # For division we are not bothered about reminders

        if ($type eq "-" || $type eq "/") {

                # if first number is less than second one.

                if($var1 < $var2) {

                        # swap the numbers

                        ($var1, $var2) = ($var2, $var1);

                }

        }

       

        # evaluate the answer

        my $ans = int(eval("$var1 $type $var2"));

        # asking the student

        print "What is $var1 $typestr{$type} $var2 ? ";

        # Ask the user for answer

        my $sans = <STDIN>;

        # ask the student until he enters the correct answer.

        until($ans == $sans)

        {

                print "No. Please Try Again! ";

                print "How much is $var1 $typestr{$type} $var2 ? ";        

                $sans = <STDIN>;       

        }

       

        # Answer is correct. So print Very Good.

        print "Very Good! ";       

       

}

====================================================================================

2nd Problem:

#!/usr/bin/perl

use strict;

use warnings;

use feature "switch"; # To use switch like conditioin

# Print the Menu to Student

print "        1. Addition Problems

        2. Substraction Problems

        3. Multiplication Problems

        4. Division Problems

        5. Any of the above types (Random Mixture)

        Please Select one choice from above: ";

# Read choice.

my $choice = <STDIN>;

# chomp remove the trailing ENTER char

chomp($choice);

# print "Choice Entered: $choice";

# Do operation based on the choice given

# Swich Case like syntax

for ($choice) {

        #Addition

   when (1)            { while(1) {

                randomfunc("+");

                                } }

        #Substraction

   when (2)         {   while(1) {

                randomfunc("-");

                                }}

        # Multiplication

   when (3)            { while(1) {

                randomfunc("*");

                                }}

        # Division

   when (4)            { while(1) {

                randomfunc("/");

                                }}

        # Mix

   when (5)            {

                        #my @types = ("added to", "minus", "times", "divided by");

                        my @types = ("+", "-", "*", "/");

                        while(1) {

                                randomfunc($types[rand @types]);

                                } }

        # Exit condition is not mentioned.

}

# random function to do operation based on the input choice sent

# It takes one argument i.e. operator symbol +,-,*,/ and generates the two numbers randomly.

sub randomfunc {

        # read the first argument

       

        my $type = shift;

       

        # hashmap to to generate the string based on the symbol

        my %typestr = ("+" => "added to",

                        "-" => "minus",

                        "*" => "times",

                        "/" => "divided by");

        # random strings for stopping student fatigue.

        my @correctstr = ('Very Good!',

                        'Excellent!',

                        'Nice Work!',

                       'Keep up the good work!');

        my @wrongstr = ('No. Please try again.',

                        'Wrong.',

                        'Try one more. Don't give up!',

                        'No. Keep trying.'

                        );

        # generate 0 to 9 , and add 1 To get only positive numbers.       

        my $var1 = int(rand(9)) + 1;

        my $var2 = int(rand(9)) + 1;

        # For substraction and division make sure first number is larger than second one.

        # For division we are not bothered about reminders

        if ($type eq "-" || $type eq "/") {

                # if first number is less than second one.

                if($var1 < $var2) {

                        # swap the numbers

                        ($var1, $var2) = ($var2, $var1);

                }

        }

       

        # evaluate the answer

        my $ans = int(eval("$var1 $type $var2"));

        # asking the student

        print "What is $var1 $typestr{$type} $var2: ";

        # Ask the user for answer

        my $sans = <STDIN>;

       

        # ask the student until he enters the correct answer.

        until($ans == $sans)

        {

                #int(rand(3)+1)

                #print "No. Please Try Again! ";

                # generate random wrong string index from 0 to 3

                my $rwstr = int(rand(4)) ;

                print "$wrongstr[$rwstr] ";

                print "How much is $var1 $typestr{$type} $var2 ? ";       

                $sans = <STDIN>;       

        }

       

        # Answer is correct. So print Very Good.

        # generate random correct string index from 0 to 3

        my $rcstr = int(rand(4));

        print "$correctstr[$rcstr] ";

        #print "Very Good! ";       

       

}

=============================================================================

Final Problem:

#!/usr/bin/perl

use strict;

use warnings;

use feature "switch"; # To use switch like conditioin

# global variable to count the number of attempts

my $questioncount = 0;

my $corretcount = 0;

my $wrongcount = 0;

while(1) {

        # Print the Menu to Student

        print "

                #############################################      

                1. Addition Problems

                2. Substraction Problems

                3. Multiplication Problems

                4. Division Problems

                5. All types of Problems (Random Mixture)

                6. Exit

                #############################################

                Please Select one choice from above: ";

        # Read choice.

        my $choice = <STDIN>;

        # chomp remove the trailing ENTER char

        chomp($choice);

        # print "Choice Entered: $choice";

        # Do operation based on the choice given

        # Swich Case like syntax

        for ($choice) {

                #Addition

                when (1)            { while(1) {

                                                randomfunc("+");

                                                # If $questioncount is 0 then count was reset in the randomfunc

                                                last if($questioncount == 0);    # Break out of the loop

                                                } }

                        #Substraction

                when (2)         {   while(1) {

                                                randomfunc("-");

                                                # If $questioncount is 0 then count was reset in the randomfunc

                                                last if($questioncount == 0);    # Break out of the loop

                                              }}

                        # Multiplication

                when (3)            { while(1) {

                                                randomfunc("*");

                                                # If $questioncount is 0 then count was reset in the randomfunc

                                                last if($questioncount == 0);    # Break out of the loop

                                                }}

                        # Division

                when (4)            { while(1) {

                                                randomfunc("/");

                                                # If $questioncount is 0 then count was reset in the randomfunc

                                                last if($questioncount == 0);    # Break out of the loop

                                                }}

                        # Mix

                when (5)            {

                                        #my @types = ("added to", "minus", "times", "divided by");

                                        my @types = ("+", "-", "*", "/");

                                        while(1) {

                                                randomfunc($types[rand @types]);

                                                # If $questioncount is 0 then count was reset in the randomfunc

                                                last if($questioncount == 0);    # Break out of the loop

                                                } }

                        # Exit condition is not mentioned.

                when (6)        {

                                        exit 0;

                                }

       

        }

}

# random function to do operation based on the input choice sent

# It takes one argument i.e. operator symbol +,-,*,/ and generates the two numbers randomly.

sub randomfunc {

        # read the first argument

       

        my $type = shift;

       

        # hashmap to to generate the string based on the symbol

        my %typestr = ("+" => "added to",

                        "-" => "minus",

                        "*" => "times",

                        "/" => "divided by");

        # random strings for stopping student fatigue.

        my @correctstr = ('Very Good!',

                        'Excellent!',

                        'Nice Work!',

                        'Keep up the good work!');

        my @wrongstr = ('No. Please try again.',

                        'Wrong.',

                        'Try one more. Don't give up!',

                        'No. Keep trying.'

                        );

        # generate 0 to 9 , and add 1 To get only positive numbers.       

       my $var1 = int(rand(9)) + 1;

        my $var2 = int(rand(9)) + 1;

        # For substraction and division make sure first number is larger than second one.

        # For division we are not bothered about reminders

        if ($type eq "-" || $type eq "/") {

                # if first number is less than second one.

                if($var1 < $var2) {

                        # swap the numbers

                        ($var1, $var2) = ($var2, $var1);

                }

        }

       

        # evaluate the answer

        my $ans = int(eval("$var1 $type $var2"));

        # asking the student

        print "What is $var1 $typestr{$type} $var2: ";

        # Ask the user for answer

        my $sans = <STDIN>;

        if($ans == $sans) { # If answer is correct

                # Answer is correct. So print Very Good.

                # generate random correct string index from 0 to 3

                my $rcstr = int(rand(4));

                print "$correctstr[$rcstr] ";

                #print "Very Good! ";

                $corretcount++; # Increment the correct answer count.

        }

        else { # If answer is wrong

                # ask the student until he enters the correct answer.

                until($ans == $sans)

                {

                        # generate random wrong string index from 0 to 3

                        my $rwstr = int(rand(4)) ;

                        print "$wrongstr[$rwstr] ";

                        print "How much is $var1 $typestr{$type} $var2 ? ";       

                        $sans = <STDIN>;       

                }

                 # Actually not required to count the wrongs becoz (wrong = 10-correct)

                 # In question it is explicitly mentioned to calculate.

                $wrongcount++;

        }

       

        $questioncount++; # Increment the questions count.

        # If questions count is 10

        if($questioncount == 10) {

                my $correctpercent = ($corretcount/10)*100;

                if($correctpercent >= 75) {

                        print "######################################################### ";

                        print "Congratulations, you are ready to go to the next level. ";

                        print "######################################################### ";

                       

                }

                else {

                        print "######################################################### ";

                        print "Please ask your teacher for extra help. ";

                        print "######################################################### ";

                       

                }

                # Reset the counters

                $wrongcount = 0;

                $corretcount = 0;

                $questioncount = 0;

               

        }  

       

}

===========================================================================

Program Output:

-----------------------------------------------------------------------------------------------------------

              #############################################

                1. Addition Problems

                2. Substraction Problems

                3. Multiplication Problems

                4. Division Problems

                5. All types of Problems (Random Mixture)

                6. Exit

                #############################################

                Please Select one choice from above: 1

What is 3 added to 1: 4

Excellent!

What is 6 added to 7: 13

Keep up the good work!

What is 3 added to 8: 11

Excellent!

What is 9 added to 3: 12

Nice Work!

What is 6 added to 2: 6

Wrong.

How much is 6 added to 2 ? 8

What is 3 added to 8: 11

Very Good!

What is 9 added to 4: 13

Keep up the good work!

What is 1 added to 3: 5

Wrong.

How much is 1 added to 3 ? 4

What is 7 added to 7: 14

Nice Work!

What is 3 added to 6: 9

Keep up the good work!

#########################################################

Congratulations, you are ready to go to the next level.

#########################################################

                #############################################

                1. Addition Problems

                2. Substraction Problems

                3. Multiplication Problems

                4. Division Problems

                5. All types of Problems (Random Mixture)

                6. Exit

                #############################################

                Please Select one choice from above: 5

What is 9 minus 8: 1

Nice Work!

What is 8 divided by 5: 3

Try one more. Don't give up!

How much is 8 divided by 5 ? 1

What is 5 times 5: 25

Excellent!

What is 9 minus 9: 1

Try one more. Don't give up!

How much is 9 minus 9 ? 0

What is 7 divided by 1: 3

Wrong.

How much is 7 divided by 1 ? 7

What is 3 times 2: 6

Nice Work!

What is 1 times 8: 1

Wrong.

How much is 1 times 8 ? 8

What is 6 added to 9: 15

Keep up the good work!

What is 9 divided by 1: 9

Excellent!

What is 6 minus 5: 3

Wrong.

How much is 6 minus 5 ? 1

#########################################################

Please ask your teacher for extra help.

#########################################################

                #############################################

                1. Addition Problems

                2. Substraction Problems

                3. Multiplication Problems

                4. Division Problems

                5. All types of Problems (Random Mixture)

                6. Exit

                #############################################

                Please Select one choice from above:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote