Nothing Special   »   [go: up one dir, main page]

Task 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Task 2

Choose 2 out of 3 programs to code!!

Task 2-1: Guess the Number Game


Create a C++ project in Code::Blocks, and save it as: Task2-1_studentNumber (include your
student number).

This is a popular game where the computer randomly picks a number, and the player must
guess the number. The computer provides feedback on each guess. Your task is to implement
this game in C++ with a few added features.

Instructions
1. The computer should pick a random number between 1 and 10 (inclusive).
2. The player has up to 5 attempts to guess the number.
3. After each guess, the computer should tell the player if their guess was too high, too
low, or correct.
4. Implement input validation to ensure that the player’s input is a number between 1
and 10. If the player’s input is invalid, ask for their input again.
5. If the player guesses the number correctly, congratulate them and tell them how
many tries it took. Then ask them if they want to play again.
6. If the player uses all their attempts without guessing correctly, tell them they’ve lost
and reveal the secret number. Then ask them if they want to play again.
7. Implement a loop so that if the player wants to play again, the game starts over
without having to run the program again.
8. Make sure to use if-else statements, while loops and named constants where
appropriate.
Task 2-2: Simple Calculator
Create a C++ project in Code::Blocks, and save it as: Task2-2_studentNumber (include your
student number).

Create a simple calculate program that performs basic arithmetic operations based on user
input. The program should allow the user to choose an operation (addition, subtraction,
multiplication, division) and then enter two numbers. The program should output the result
of the operation.

Instructions
1. Display a menu to the user with options for addition, subtraction, multiplication,
and division.
2. Use a switch statement to handle the user’s choice of operation.
3. Ask the user to enter two numbers (floating-point values)).
4. Perform the chosen operation on the two numbers and display the results.
5. Implement input validation to ensure that the user enters valid numbers.
6. Handle division by zero with an appropriate error message.
7. After displaying the result, ask the user if they want to perform another
calculation.
8. Implement a loop so that if the user want to perform another calculation, the
program starts over without having to run the program again.

Notes
• Make sure to use function from the <iomanip> library to format the output.
o Use setprecision() and fixed to control how many digits appear after the decimal
point for the result
Task 2-3: Grade Converter
Create a C++ project in Code::Blocks, and save it as: Task2-3_studentNumber (include your
student number).

Create a program that evaluates a student’s grade based on their score and provides
feedback. The program should determine the grade (A, B, C, D, F) based on predefined ranges
and give specific feedback for each grade, including special cases for borderline scores.

Instructions
1. Ask the user to enter the student’s score (a floating-point value between 0 and
100).
2. Use a nested if-else structure to determine the grade:
a. 90-100 = A
b. 80-89 = B
c. 70-79 = C
d. 60-69 = D
e. 0-59 = F
3. Provide specific feedback for each grade:
a. A: “Excellent work!”
b. B: “Good job!”
c. C: “You passed.”
d. D: “Needs improvement.”
e. F: “Failed. Better luck next time.
4. Handle special cases for borderline scores:
a. 89.5-89.9: “Almost an A! Great effort.”
b. 79.5-79.9: “Almost a B! Keep trying.”
c. 69.5-69.9: “Almost a C! You can do it.”
d. 59.5-59.9: “Almost a D! Don’t give up.”
5. Implement input validation to ensure that the user’s input is a valid number
between 0 and 100.
6. After displaying the grade and feedback, ask the user if they want to evaluate
another grade.
7. Implement a loop so that if the user want to evaluate another grade, the program
starts over without having to run the program again.

Notes
• Correct implementation of input and output operations in C++;
• Proper use of control structures (if, else-if, else, switch, loops);
• Appropriate use of data types;
• Code readability and proper commenting;
• Accurate input validation and error handling;
• Effective use of standard libraries and function;
• Successful compilation and execution of the program; and
• Logical and efficient program design - logically structured and efficient in their execution
Rubric
Program 1 Program runs, and meets all expectations 10
Program runs, doesn’t meet all expectations 4
Program does not run, doesn’t meet all expectations 0

Program 2 Program runs, and meets all expectations 10


Program runs, doesn’t meet all expectations 4
Program does not run, doesn’t meet all expectations 0

Sub-Total 20/2
Grand Total 10

You might also like