CPP Mid-Coding
Quiz
•
Computers
•
University
•
Practice Problem
•
Hard
John Oli
Used 1+ times
FREE Resource
Enhance your content in a minute
12 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
Movie Ticket Pricing
Problem: A cinema charges $12 for adults (age >= 18), $8 for teens (13–17), and $5 for kids (< 13). The code crashes for some inputs.
Question: What’s wrong with the code?
The variable price is not initialized and may be undefined.
The condition age > 18 should be age >= 18
The else if statements are in the wrong order
The cout statement is outside the if block.
Answer explanation
If none of the conditions match (e.g., invalid age), price remains uninitialized, leading to undefined behavior. Add an else or initialize price:
2.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
Weather App Alert
Problem: A weather app alerts based on temperature: "Freezing" (< 0°C), "Cold" (0–10°C), "Mild" (> 10°C). The code has a syntax error.
Question: What’s wrong with the code?
Nothing; the code is correct.
The condition temp <= 10 should be temp < 10.
Missing ; after cout statements.
The temp variable should be a float.
Answer explanation
Explanation: The code is syntactically correct and logically sound. For temp = 5, it outputs "Cold" as expected.
3.
MULTIPLE CHOICE QUESTION
1 min • 5 pts
Vending Machine Change
Problem: A vending machine returns change if payment > $5, dispenses the item if payment == $5, or requests more money otherwise. The logic fails.
Question: What’s the issue?
The condition payment = 5 should use ==.
The payment variable should be an int.
The else if is unnecessary.
The cout statements are incorrect.
Answer explanation
Explanation: The else if condition uses = (assignment) instead of == (comparison). Correct code:
4.
MULTIPLE CHOICE QUESTION
1 min • 5 pts
Student Grade Calculator
Problem: A grading system assigns: A (>= 90), B (80–89), C (70–79), F (< 70). The code assigns incorrect grades.
Question: What’s wrong?
The conditions should use >= instead of >.
The grade variable is not initialized.
The conditions are in the wrong order.
The code is correct.
Answer explanation
Explanation: The conditions exclude boundary values (e.g., score = 90 gets B instead of A). Use >=:
5.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
Parking Fee Calculator
Problem: A parking lot charges $5 for <= 2 hours, $10 for 3–5 hours, $15 for > 5 hours. The code has a syntax error.
Question: What’s the issue?
Missing semicolon ; after fee = 10.
The fee variable is not initialized.
The condition hours <= 5 is incorrect.
The else if should be elif.
Answer explanation
Explanation: A missing ; after fee = 10 causes a syntax error. Correct code:
6.
MULTIPLE CHOICE QUESTION
30 sec • 5 pts
Online Shopping Discount
Problem: An online store offers 20% off for orders > $100, 10% for $50–100, and no discount for < $50. The discount is incorrect.
Question: What’s wrong?
The condition order > 50 should be order >= 50.
The discount variable should be an int.
The cout statement is incorrect.
The code is correct.
Answer explanation
Explanation: The condition order > 50 excludes $50. Use >=:
7.
MULTIPLE CHOICE QUESTION
1 min • 5 pts
Elevator Weight Limit
Problem: An elevator allows entry if weight <= 1000 lbs, warns if 1000–1200 lbs, and blocks if > 1200 lbs. The code has a syntax error.
Question: What’s the issue?
Missing semicolon ; after cout << "Warning: Overweight" << endl.
The condition weight <= 1200 is incorrect.
The weight variable should be a double.
The else if is invalid.
Answer explanation
Explanation: A missing ; after cout << "Warning: Overweight" << endl causes a syntax error. Correct code:
Create a free account and access millions of resources
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?
Similar Resources on Wayground
15 questions
Digital Etiquette
Quiz
•
4th Grade - University
15 questions
Data Mining - Classification Mining
Quiz
•
University
10 questions
Quiz CodeIgniter 4
Quiz
•
University
10 questions
Què has après sobre el web ?
Quiz
•
University
9 questions
CHAPTER 5 ONLINE QUIZ
Quiz
•
University
12 questions
Javascript
Quiz
•
University
16 questions
Quiz on List and Tuples
Quiz
•
University
10 questions
CSC413 - Sound
Quiz
•
University
Popular Resources on Wayground
10 questions
Honoring the Significance of Veterans Day
Interactive video
•
6th - 10th Grade
9 questions
FOREST Community of Caring
Lesson
•
1st - 5th Grade
10 questions
Exploring Veterans Day: Facts and Celebrations for Kids
Interactive video
•
6th - 10th Grade
19 questions
Veterans Day
Quiz
•
5th Grade
14 questions
General Technology Use Quiz
Quiz
•
8th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
15 questions
Circuits, Light Energy, and Forces
Quiz
•
5th Grade
19 questions
Thanksgiving Trivia
Quiz
•
6th Grade
Discover more resources for Computers
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)
Quiz
•
8th Grade - University
7 questions
Force and Motion
Interactive video
•
4th Grade - University
9 questions
Principles of the United States Constitution
Interactive video
•
University
18 questions
Realidades 2 2A reflexivos
Quiz
•
7th Grade - University
10 questions
Dichotomous Key
Quiz
•
KG - University
25 questions
Integer Operations
Quiz
•
KG - University
7 questions
What Is Narrative Writing?
Interactive video
•
4th Grade - University
20 questions
SER vs ESTAR
Quiz
•
7th Grade - University
