104 - Array Practice - Loops and Array Comprehensive Practice
104 - Array Practice - Loops and Array Comprehensive Practice
Monday: 5 stickers
Tuesday: 8 stickers
Wednesday: 3 stickers
Thursday: 7 stickers
Friday: 6 stickers
Questions: How many total? What's the average per day? Which day had the most?
Example 3: Test Scores in Your Class Your class has 10 students with test scores. You want to:
SECTION A: Creating Even Numbers Purpose: Fill an array with even numbers: 2, 4, 6, 8, 10...
cpp
#include <iostream>
using namespace std;
int main() {
cout << "=== Even Numbers Generator ===" << endl;
return 0;
}
cpp
int main() {
cout << "=== Times Table Generator ===" << endl;
int timesTable[10];
int multiplyBy = 5; // Let's do the 5 times table
return 0;
}
SECTION C: Sum of Number Sequence Purpose: Add up all numbers in our array
cpp
int main() {
cout << "=== Adding Up Numbers ===" << endl;
return 0;
}
cpp
#include <iostream>
using namespace std;
int main() {
cout << "=== Growing Star Pattern ===" << endl;
return 0;
}
Output:
*
* *
* * *
* * * *
* * * * *
SECTION B: Number Triangle Purpose: Make a triangle with numbers instead of stars
cpp
int main() {
cout << "=== Number Triangle ===" << endl;
int height = 4;
return 0;
}
Output:
1
1 2
1 2 3
1 2 3 4
cpp
int main() {
cout << "=== Rectangle Pattern ===" << endl;
int width = 6;
int height = 4;
return 0;
}
Output:
* * * * * *
* * * * * *
* * * * * *
* * * * * *
SECTION A: Input and Display Scores Purpose: Store and show test scores for 5 students
cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "=== Class Test Score Analyzer ===" << endl;
int scores[5];
string names[5] = {"Alice", "Bob", "Charlie", "Diana", "Eve"};
return 0;
}
SECTION B: Find Highest and Lowest Scores Purpose: Find the best and worst scores
cpp
cout << "\n=== Best and Worst Scores ===" << endl;
cout << "Highest score: " << names[highestStudent] << " (" << highest << ")" << endl;
cout << "Lowest score: " << names[lowestStudent] << " (" << lowest << ")" << endl;
SECTION C: Calculate Class Average Purpose: Find the average score for the class
cpp
SECTION D: Count Passing Students Purpose: Count how many students passed (score ≥ 70)
cpp
cout << "\nTotal students who passed: " << passCount << " out of 5" << endl;
return 0;
}
Tips:
Tips:
* * * *
* * * *
* * * *
* * * *
Tips:
Tips:
cpp
2. Forgetting to Initialize:
cpp
cpp
Remember: Programming is like learning to ride a bike - start slow, practice a lot, and don't worry
about making mistakes. Every programmer started with simple problems like these!
Keep practicing these basic patterns until they feel easy. Then you'll be ready for more
advanced challenges! 🎯