Search⌘ K
AI Features

Solution: Daily Step Tracker

Explore how to store and sort integer data using std::vector and std::sort. Understand the use of initializer lists for container setup and apply range-based for loops to iterate and display elements efficiently.

We'll cover the following...
C++ 23
// Solution: Sorting fitness data using vector and algorithms
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
// Initialize vector with step counts
std::vector<int> step_counts = {10500, 8900, 12000, 4500, 15000, 9800, 11200};
// Sort the vector in ascending order
std::sort(step_counts.begin(), step_counts.end());
std::cout << "Sorted Step Counts: ";
// Iterate through the sorted container
for (int steps : step_counts) {
std::cout << steps << " ";
}
std::cout << std::endl;
return 0;
}
...