In: Computer Science
Visual Basic
This assessment will cover the Programming fundamentals of the Integrated Development Environment(IDE) found in Chapters 1-7 of the assigned text. In this assignment, you will demonstrate the use of tools explored so far within the course. It is the High Totals Game activity found in the Case Projects section of your book. Requirements: Copy/paste the VB code into a Microsoft Word document. You are also required to submit enough screenshots of the output to show that all work has been completed.
Create an application that can be used to practice adding, subtracting, multiplying, and dividing numbers. The application should display a math problem on the screen and then allow the student to enter the answer and also verify that the answer is correct. The application should give the student as many chances as necessary to answer the problem correctly. The math problems should use random integers from 1 through 20, inclusive. The subtraction problems should never ask the student to subtract a larger number from a smaller one. The division problems should never ask the student to divide a smaller number by a larger number. Also, the answer to the division problems should always result in a whole number. The application should keep track of the number of correct and incorrect responses made by the student. The interface should include a button that allows the user to reset the counters for a different student.
The High Total game requires two players. The application’s interface should allow the user to enter each player’s name. When the user clicks a button, the button’s Click event procedure should generate two random numbers for player 1 and two random numbers for player 2. The random numbers should be in the range of 1 through 20, inclusive. The procedure should display the four numbers in the interface. It should also total the numbers for each player and then display both totals in the interface. If both totals are the same, the application should display the message “Tie”. If player 1’s total is greater than player 2’s total, it should display the message “player 1’s name won”. If player 2’s total is greater than player 1’s total, it should display the message “player 2’s name won”. The application should keep track of the number of times player 1 wins, the number of times player 2 wins, and the number of ties. The interface should also include a button that allows the user to reset the counters and interface for a new game.
int sub(int a, int b)
{
return a + flipSign(b);
}
int mul(int a, int b)
{
if (a < b)
return mul(b, a);
int sum = 0;
for (int i = abs(b); i > 0; i--)
sum += a;
if (b < 0)
sum = flipSign(sum);
return sum;
}
int division(int a, int b)
{
if (b == 0)
throw(b);
int quotient = 0, dividend;
int divisor = flipSign(abs(b));
for (dividend = abs(a); dividend >= abs(divisor);
dividend += divisor)
quotient++;
if (areDifferentSign(a, b))
quotient = flipSign(quotient);
return quotient;
}
int main()
{
cout << "Subtraction is " << sub(4, -2) <<
endl;
cout << "Product is " << mul(-9, 6) <<
endl;
try
{
cout << "Division is " << division(8, 2);
}
catch (int k)
{
cout << " Exception :- Divide by 0";
}
return 0;
}