Laboratory #5 Solution

$30.00

Category:

Description

NOTE:

  1. Please submit only C++ source files (*.cpp) to Blackboard.
  2. Please put your name, project description, and date on the top of your file as a comment.
  3. PLEASE WORK ALONE. If cheating is found, you will get ZERO.

 

  1. (Lastname_Lab5_p1.cpp, 20 points)

 

  1. Write a function named findParity() that accepts an integer argument and determines whether the passed integer is even or odd.
  2. Include the function findParity() in a working program. Make sure your function is called from main(). Test the function by passing various data to it.

 

  1. (Lastname_Lab5_p2.cpp, 20 points)

 

  1. Write a function named powfun() that raises an integer power and displays the result. The positive integer should be the second value passed to the function. Declare the variable used to store the result as a long-integer data type to ensure sufficient storage for the result.

 

  1. Include the function in a working program. Make sure your function is called from main(). Test the function by passing various data to it.

 

  1. (Lastname_Lab5_p3.cpp, 20 points)
    1. A second-degree polynomial in x is given by the expression ax2 + bx + c, where a, b, and c are known numbers, and a is not equal to zero. Write a C++ function named polyTwo(a,b,c,x) that computes and returns the value of a second-degree polynomial for any passed values of a, b, c, and x.

 

  1. Include the function in a working program. Make sure your function is called from main(). Test the function by passing various data to it.

 

  1. (Lastname_Lab5_p4.cpp, 20 points)

Computers are playing an increasing role in education. Write a program that will help an elementary school student learn multiplication. Use rand to produce two positive one-digit integers. It should then type a question such as:

 

How much is 6 times 7?

 

The student then types the answer. Your program checks the student’s answer. If it is correct, print “Very good!” and then ask another multiplication question. If the answer is wrong, print “No. Please try again.” and then let the student try the same question again repeatedly until the student finally gets it right. Terminate the program when the student has 10 right answers.

 

  1. (Lastname_Lab5_p5.cpp, 20 points)

Write a program that plays the game of “guess the number” as follows: Your program chooses the number to be guessed by selecting an integer at random in the range 1 to 100. The program then types:

 

I have a number between 1 and 100.

Can you guess my number?

 

Please type your first guess.

 

The player then types a first guess. The program responds with one of the following:

 

  1. Excellent! You guessed the number!
  2. Too low. Try again.
  3. Too high. Try again.

 

If the player’s guess is incorrect, your program should loop until the player finally gets the number right. Your program should keep telling the player Too high or Too low to help the player “zero in” on the correct answer. (Note: The search technique employed in this problem is called binary search in computer science.)

 

  1. (OPTIONAL, Lastname_Lab5_p6.cpp, 30 points)

The use of computers in education is referred to as computer-assisted instruction (CAI). More sophisticated CAI systems monitor the student’s performance over a period of time. The decision to begin a new topic is often based on the student’s success with previous topics. Modify the program of Program 4 to count the number of correct and incorrect responses typed by the student. After the student types 10 answers, your program should calculate the percentage of correct responses. If the percentage is lower than 75 percent, your program should print “Please ask you instructor for extra help” and then terminate.


error: Content is protected !!