Data Types CS Thinking Example 3
Follow the full solution, then compare it with the other examples linked below.
Example 3
mediumFor each scenario, choose the most appropriate data type: (a) a student's name, (b) number of students in a class, (c) whether a student passed, (d) a student's average grade (e.g., 87.5).
Solution
- 1 Step 1: (a) Name is text โ string. (b) Count of students is a whole number โ integer.
- 2 Step 2: (c) Passed or not is yes/no โ boolean. (d) Average can have decimals โ float/real.
Answer
(a) String, (b) Integer, (c) Boolean, (d) Float/Real.
Choosing the correct data type ensures data is stored efficiently and operations behave as expected. Using an integer for a count prevents nonsensical fractional students.
About Data Types
Categories that classify data values and determine which operations can validly be performed on them. Common data types include integers, floating-point numbers, strings, booleans, and arrays, each with its own set of permitted operations.
Learn more about Data Types โMore Data Types Examples
Example 1 easy
Classify each value into its data type: (a) 42, (b) 'Hello', (c) 3.14, (d) TRUE.
Example 2 mediumA program reads user input as a string '25'. What happens if you try to calculate '25' + 10 without
Example 4 hardA program stores prices as integers in pence (e.g., 499 for ยฃ4.99) rather than as floats. Explain tw