0% found this document useful (0 votes)
26 views7 pages

C++ Test 3 Practical

Uploaded by

8x.mala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views7 pages

C++ Test 3 Practical

Uploaded by

8x.mala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Name: _________________________

Class: __________________________

Date:___________________________

Test 3 (Practical) – Looping (50 Points)

Instructions:

• Submit a single .cpp file containing all your answers.


• Include the following at the top of your file:
o Your full name
o Date
o Class
o A description of the file contents
• Each question must include:
o A program that solves the problem.
o Comments explaining your code and definitions where applicable.

Student Information Block Example

cpp
Copy code
/*
Name: John Doe
Date: November 27, 2024
Class: High School C++ Programming

Description: This file contains solutions to the Practical Quiz on Looping.


Each program demonstrates key concepts of loops, accompanied by explanations.
*/
Test Outline and Points Distribution

Section 1: Definitions and Concepts (15 points)

Students must answer these by writing short programs/examples and including comments
explaining their understanding.

1. Incrementing a Value (3 points):


Write a program that demonstrates incrementing a variable. Add a comment explaining
why and when incrementing is useful.
2. Decrementing a Value (3 points):
Write a program that demonstrates decrementing a variable. Include a comment
explaining its utility.
3. Pre-increment vs. Post-increment (3 points):
Write a program to compare pre- and post-increment. Use comments to explain the
difference and provide a practical example of when each might be used.
4. Accumulator (3 points):
Write a program that uses an accumulator to calculate the sum of 5 numbers entered by
the user. Explain how an accumulator simplifies repetitive addition.
5. Sentinel Value (3 points):
Write a program that keeps asking for numbers until the user enters -1. Include
comments explaining how sentinel values prevent infinite loops.
Section 2: Real-World Problems (25 points)

1. Even/Odd Counter (5 points):


Write a program that takes 10 user-input numbers and counts how many are even and
how many are odd.
o Hint: Use the % operator.
o Comments: Explain the logic behind the modulus operator and its application in
loops.
2. Password Validation (5 points):
Write a program that asks for a password and allows up to 3 attempts. If the user enters
the correct password, display "Access Granted"; otherwise, display "Access Denied."
o Hint: Use a while loop with a condition for retries.
o Comments: Explain how loops control retries and the use of break to terminate
the loop early.
3. Cafeteria Inventory (5 points):
A cafeteria tracks how many items are sold each hour. Write a program to calculate the
total items sold and the average per hour. Collect data for 8 hours.
o Hint: Use a loop for input and an accumulator to store the total.
o Comments: Explain why accumulators are efficient for tracking totals.
4. Prime Number Finder (5 points):
Write a program that asks the user for a number n and finds all prime numbers between 1
and n.
o Hint: Use nested loops to check for divisors of each number.
o Comments: Explain the logic behind testing for prime numbers using loops.
5. Student Grade Average (5 points):
Write a program that calculates the average grade for 5 subjects and assigns a letter grade
(A, B, C, D, F).
o Hint: Use a loop for input and conditions for assigning grades.
o Comments: Explain how loops reduce repetitive input tasks.
Section 3: Advanced Challenge (10 points)

1. Star Pattern Generator (5 points):


Write a program that asks the user for a number and prints a right-angle triangle of stars.
o Example: If the user enters 5, the output should be:

*
**
***
****
*****

o Hint: Use nested loops for rows and stars.


o Comments: Explain how nested loops are used to create patterns.
2. Shopping List Calculator (5 points):
Write a program that allows a user to enter the prices of items until they enter 0. Display
the total cost of all items.
o Hint: Use a while loop with a sentinel value (0) to stop input.
o Comments: Explain how sentinel values work and why they’re useful in loops.

Total Points Breakdown

• Section 1: Definitions and Concepts (15 points)


• Section 2: Real-World Problems (25 points)
• Section 3: Advanced Challenge (10 points)
Total: 50 points

Submission Notes

• Your programs must compile and run correctly.

• Include clear comments to explain your logic and understanding of definitions.

• Plagiarism will result in zero points. Be creative and original!


Grading Rubric: Practical Test 3 – Looping (50 Points)

Section 1: Definitions and Concepts (15 Points)

Question Criteria Max Points Comments


Points Awarded
1. Incrementing a Correct 1 Does the program correctly
Value functionality increment a variable?
Code clarity and 1 Are comments clear and
comments explanatory?
Example 1 Is the use of incrementing
explanation clearly explained?
2. Decrementing Correct 1 Does the program correctly
a Value functionality decrement a variable?
Code clarity and 1 Are comments clear and
comments explanatory?
Example 1 Is the use of decrementing
explanation clearly explained?
3. Pre- vs. Post- Correct 1 Does the program correctly
Increment functionality compare pre/post-increment?
Code clarity and 1 Are comments clear and
comments explanatory?
Example 1 Is the distinction well-
explanation explained with practical use
cases?
4. Accumulator Correct 1 Does the program correctly
functionality sum numbers with an
accumulator?
Code clarity and 1 Are comments clear and
comments explanatory?
Example 1 Is the utility of accumulators
explanation explained?
5. Sentinel Value Correct 1 Does the program terminate
functionality correctly with a sentinel
value?
Code clarity and 1 Are comments clear and
comments explanatory?
Example 1 Is the concept of sentinel
explanation values explained well?

Section 1 Total: ________/15


Section 2: Real-World Problems (25 Points)

Question Criteria Max Points Comments


Points Awarded
1. Even/Odd Correct 2 Does the program correctly
Counter functionality count even/odd numbers?
Code clarity and 1 Are comments clear and
comments explanatory?
Logic explanation 2 Is the modulus operator logic
explained well?
2. Password Correct 2 Does the program handle
Validation functionality retries and validate
passwords?
Code clarity and 1 Are comments clear and
comments explanatory?
Logic explanation 2 Is the retry logic clearly
explained?
3. Cafeteria Correct 2 Does the program calculate
Inventory functionality total and average correctly?
Code clarity and 1 Are comments clear and
comments explanatory?
Logic explanation 2 Is accumulator usage
explained effectively?
4. Prime Correct 2 Does the program identify
Number Finder functionality all primes correctly?
Code clarity and 1 Are comments clear and
comments explanatory?
Logic explanation 2 Is prime-checking logic
explained well?
5. Student Correct 2 Does the program calculate
Grade Average functionality and assign grades
accurately?
Code clarity and 1 Are comments clear and
comments explanatory?
Logic explanation 2 Are conditions for grades
explained clearly?

Section 2 Total: ________/25


Section 3: Advanced Challenge (10 Points)

Question Criteria Max Points Comments


Points Awarded
1. Star Pattern Correct 2 Does the program generate
Generator functionality the correct star pattern?
Code clarity and 1 Are comments clear and
comments explanatory?
Logic explanation 2 Is the nested loop logic
explained effectively?
2. Shopping List Correct 2 Does the program calculate
Calculator functionality total cost correctly?
Code clarity and 1 Are comments clear and
comments explanatory?
Logic explanation 2 Is the use of sentinel values
explained well?

Section 3 Total: ________/10

Final Score:

Total: ________/50

You might also like