Congratulations on reaching Question #30! This is THE ULTIMATE CHALLENGE that combines EVERYTHING you've learned from Questions 1-29. Are you ready? π
Problem: Life & Fitness Analytics Dashboard
Create a comprehensive analytics report that takes multiple inputs and produces a beautifully
formatted output combining ALL Basic I/O concepts!
What Makes This Question Special?
This is NOT just another questionβit's a MASTERPIECE that tests your mastery of EVERY SINGLE CONCEPT from the entire Basic I/O section! If you can solve this, you've truly conquered Basic I/O! πͺ
Concept | From Question(s) | Usage in Challenge |
---|---|---|
Multiple Inputs | #6, #20 | 5 different input values |
Long Long Type | #20 | Large hour calculations |
Decimal Operations | #22 | Weight & distance calculations |
Type Casting | #23 | Integer to double conversions |
abs() Function | #21, #28 | Weight difference calculation |
Division & Modulo | #27, #29 | Time & age decomposition |
fixed & setprecision | #13, #22 | Weight & distance formatting |
setfill & setw | #9, #27 | Time format padding (00:30:00) |
Mathematical Logic | #26 | Conditional text without if-else |
String Output | #1-5 | Dashboard headers & labels |
// Input: 8520 days
// Extract years (365 days = 1 year)
int years = days / 365;
// 8520 / 365 = 23 years
days = days % 365;
// 8520 % 365 = 120 days remaining
// Extract months (30 days = 1 month)
int months = days / 30;
// 120 / 30 = 4 months
days = days % 30;
// 120 % 30 = 0 days
// Result: 23 years, 4 months, 0 days β
// Input: 8520 days total
// Convert days to hours
long long total_hours = originalDays * 24;
// 8520 Γ 24 = 204,480 hours
// Format: 204480:00:00:00
// (hours:minutes:seconds) - all zeros since exact days
// Inputs: current=75.5, target=70.0
double diff = abs(current - target);
// abs(75.5 - 70.0) = abs(5.5) = 5.50
// Determine gain or lose (without if-else!)
// If current < target: "to gain"
// If current >= target: "to lose"
// Mathematical approach from Q#26!
string status = (current < target) ? "to gain" : "to lose";
// For 75.5 vs 70.0: "to lose" β
// Input: 5000 meters
double km = static_cast<double>(meters) / 1000.0;
// static_cast(5000) / 1000.0 = 5.00 km
// Format with 2 decimal places
cout << fixed << setprecision(2) << km;
// Output: 5.00 km β
// Input: 1800 seconds
int hours = seconds / 3600;
// 1800 / 3600 = 0 hours
seconds = seconds % 3600;
// 1800 % 3600 = 1800 seconds
int mins = seconds / 60;
// 1800 / 60 = 30 minutes
seconds = seconds % 60;
// 1800 % 60 = 0 seconds
// Format: 00:30:00 (with leading zeros!)
cout << setfill('0') << setw(2) << hours << ":"
<< setw(2) << mins << ":"
<< setw(2) << seconds;
// Output: 00:30:00 β
// Formula: calories = distance_in_km Γ 65
int calories = static_cast<int>(km * 65);
// static_cast(5.00 Γ 65) = 325 calories
// Output as integer (no decimals)
cout << calories << " cal";
// Output: 325 cal β
// === INPUT ===
Days: 8520
Current Weight: 75.5 kg
Target Weight: 70.0 kg
Distance: 5000 meters
Workout: 1800 seconds
// === CALCULATIONS ===
// Age Breakdown:
Years: 8520/365 = 23, Remainder: 120
Months: 120/30 = 4, Remainder: 0
Days: 0
// Total Hours:
8520 Γ 24 = 204480 hours
// Weight Difference:
abs(75.5 - 70.0) = 5.50 kg
75.5 > 70.0 β "to lose"
// Distance:
5000/1000.0 = 5.00 km
// Workout Time:
1800 sec = 0 hours, 30 minutes, 0 seconds
// Calories:
5.00 Γ 65 = 325 cal
// === OUTPUT ===
=== LIFE ANALYTICS DASHBOARD ===
Age: 23 years, 4 months, 0 days
Total Time Lived: 204480:00:00:00
=== FITNESS METRICS ===
Current Weight: 75.50 kg
Target Weight: 70.00 kg
Weight Difference: 5.50 kg to lose
Distance Today: 5.00 km
Workout Time: 00:30:00
Calories Burned: 325 cal
You've journeyed through 30 carefully crafted questions, from simple print statements to this complex analytics dashboard. You've learned not just syntax, but patterns, techniques, and problem-solving approaches that will serve you throughout your programming career!
Welcome to the elite group of developers who've conquered Basic I/O! You're now ready for the next chapter! π
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
// Input variables
int totalDays, meters, workoutSec;
double currentWeight, targetWeight;
cin >> totalDays >> currentWeight >> targetWeight
>> meters >> workoutSec;
// Save original days for hour calculation
int originalDays = totalDays;
// === AGE CALCULATION ===
int years = totalDays / 365;
totalDays = totalDays % 365;
int months = totalDays / 30;
int days = totalDays % 30;
// === TOTAL HOURS LIVED ===
long long totalHours = originalDays * 24;
// === WEIGHT DIFFERENCE ===
double weightDiff = abs(currentWeight - targetWeight);
string status = (currentWeight < targetWeight)
? "to gain" : "to lose";
// === DISTANCE CONVERSION ===
double km = static_cast<double>(meters) / 1000.0;
// === WORKOUT TIME BREAKDOWN ===
int hours = workoutSec / 3600;
workoutSec = workoutSec % 3600;
int mins = workoutSec / 60;
int secs = workoutSec % 60;
// === CALORIES CALCULATION ===
int calories = static_cast<int>(km * 65);
// === OUTPUT ===
cout << "=== LIFE ANALYTICS DASHBOARD ===" << endl;
cout << "Age: " << years << " years, "
<< months << " months, " << days << " days" << endl;
cout << "Total Time Lived: " << totalHours
<< ":00:00:00" << endl;
cout << endl;
cout << "=== FITNESS METRICS ===" << endl;
cout << fixed << setprecision(2);
cout << "Current Weight: " << currentWeight << " kg" << endl;
cout << "Target Weight: " << targetWeight << " kg" << endl;
cout << "Weight Difference: " << weightDiff
<< " kg " << status << endl;
cout << "Distance Today: " << km << " km" << endl;
cout << "Workout Time: "
<< setfill('0') << setw(2) << hours << ":"
<< setw(2) << mins << ":"
<< setw(2) << secs << endl;
cout << "Calories Burned: " << calories << " cal";
return 0;
}