Session 3: Variables and Data Types
Your Name
- 4 minutes read - 704 wordsSession 3: Variables and Data Types
Understand how computers store different types of information and learn to work with numbers, text, and true/false values.
🎯 Key Skills You'll Learn:
- int, double, char, bool, string
- Variable naming conventions
- Variable declaration and initialization
🚀 Session Project:
Personal Profile Generator
Learning Objectives
- Understand what variables are and why we need them
- Learn different data types in C++
- Practice declaring and using variables
Warm-up (5 minutes)
In your mad libs program, you used variables like string adjective. Why do you think we need to tell the computer it’s a “string”?
New Concept Introduction (20 minutes)
What are Variables?
Variables are like labeled boxes where we store information:
- The label is the variable name
- The box type determines what kind of data it can hold
- The contents are the actual data
C++ Data Types
Text Data:
|
|
Number Data:
|
|
True/False Data:
|
|
Variable Declaration and Initialization
|
|
Variable Naming Rules
- Must start with letter or underscore
- Can contain letters, numbers, underscores
- No spaces or special characters
- Case sensitive (
ageandAgeare different)
Good names: playerScore, user_name, isGameOver
Bad names: x, data1, thing
Hands-on Practice (25 minutes)
Exercise 1: Variable Playground (10 minutes)
|
|
Exercise 2: Age Calculator (15 minutes)
|
|
Challenge/Quiz (10 minutes)
Challenge: Personal Profile Generator Create a program that asks for and stores:
- Full name (string)
- Age (int)
- Height in feet (double)
- Favorite subject grade (char)
- Whether they like programming (bool)
Display all information in a nicely formatted profile.
Validation Prompt
🤖 AI Validation Prompt
Copy this prompt and your code to ChatGPT or Claude for instant feedback:
```
I'm learning C++ and just completed Session 3. Here's my solution to the Personal Profile Generator challenge:
[PASTE YOUR CODE HERE]
The challenge was: Create a program that collects personal information using different data types and displays it as a formatted profile.
Please check if my solution:
1. Uses at least 4 different data types correctly
2. Has meaningful variable names
3. Gets user input and stores it properly
4. Displays the information in a clear format
If there are issues, please explain what's wrong and give me a hint to fix it (don't give me the complete solution).
```
What You Learned
- ✅ Different data types: string, int, double, char, bool
- ✅ How to declare and initialize variables
- ✅ Variable naming conventions
- ✅ Using variables in calculations
Next Session Preview
In Session 4, you’ll learn to work with numbers and mathematical operations in C++!