💻 Mastering C++ Fundamentals Through 10 Real-World Scenarios
Writing your first C++ programs goes beyond printing "Hello, World!". Below are 10 distinct, production-aligned beginner programs addressing practical real-world use cases—ranging from currency conversion and BMI calculation to discount billing and parking fee computations.
📊 End-to-End C++ Foundation Program Execution Workflow Diagram
1. Include Headers
Import `#include <iostream>` and `#include <iomanip>` for I/O.
2. Define `main()`
Entry point function returning integer exit status code 0.
3. Variable Declaration
Initialize strongly-typed variables (`int`, `double`, `string`).
6. Process Termination
Program completes execution and returns control to OS.
5. Formatted Console Output
Render formatted results using `std::cout` and `std::fixed`.
4. Logic Execution
Execute arithmetic, conditional evaluation, or loop iterations.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double usdAmount = 250.0;
double exchangeRate = 86.50; // 1 USD = 86.50 INR
double inrAmount = usdAmount * exchangeRate;
cout << "--- Currency Exchange Calculator ---" << endl;
cout << "Amount in USD : $" << fixed << setprecision(2) << usdAmount << endl;
cout << "Exchange Rate : ₹" << exchangeRate << endl;
cout << "Converted INR : ₹" << inrAmount << endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double weightKg = 72.5;
double heightM = 1.75;
double bmi = weightKg / (heightM * heightM);
cout << "--- BMI Health Assessment ---" << endl;
cout << "Weight : " << weightKg << " kg" << endl;
cout << "Height : " << heightM << " m" << endl;
cout << "Calculated BMI: " << fixed << setprecision(1) << bmi << endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double markedPrice = 4500.00;
double discountPercentage = 15.0; // 15% OFF
double discountAmount = (markedPrice * discountPercentage) / 100.0;
double finalPayable = markedPrice - discountAmount;
cout << "--- Retail Billing Invoice ---" << endl;
cout << "Marked Price : ₹" << fixed << setprecision(2) << markedPrice << endl;
cout << "Discount (15%): -₹" << discountAmount << endl;
cout << "Final Payable : ₹" << finalPayable << endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int unitsConsumed = 240;
double ratePerUnit = 6.50;
double fixedCharge = 100.00;
double totalBill = (unitsConsumed * ratePerUnit) + fixedCharge;
cout << "--- Electricity Utility Bill ---" << endl;
cout << "Units Consumed: " << unitsConsumed << " kWh" << endl;
cout << "Energy Charge : ₹" << fixed << setprecision(2) << (unitsConsumed * ratePerUnit) << endl;
cout << "Fixed Charge : ₹" << fixedCharge << endl;
cout << "Total Due : ₹" << totalBill << endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double principal = 100000.0; // ₹1 Lakh
double rateOfInterest = 7.5; // 7.5% p.a.
int timeYears = 3;
double simpleInterest = (principal * rateOfInterest * timeYears) / 100.0;
double maturityAmount = principal + simpleInterest;
cout << "--- Fixed Deposit Maturity Statement ---" << endl;
cout << "Principal Amount : ₹" << fixed << setprecision(2) << principal << endl;
cout << "Interest Earned : ₹" << simpleInterest << endl;
cout << "Maturity Total : ₹" << maturityAmount << endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double celsius = 37.5;
double fahrenheit = (celsius * 9.0 / 5.0) + 32.0;
cout << "--- Temperature Conversion ---" << endl;
cout << "Temperature in Celsius : " << fixed << setprecision(1) << celsius << "°C" << endl;
cout << "Temperature in Fahrenheit : " << fahrenheit << "°F" << endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double basicSalary = 50000.0;
double hra = basicSalary * 0.40; // 40% HRA
double da = basicSalary * 0.20; // 20% DA
double pfDeduction = 3600.0;
double grossSalary = basicSalary + hra + da;
double netSalary = grossSalary - pfDeduction;
cout << "--- Employee Salary Statement ---" << endl;
cout << "Basic Salary : ₹" << fixed << setprecision(2) << basicSalary << endl;
cout << "Gross Salary : ₹" << grossSalary << endl;
cout << "PF Deduction : -₹" << pfDeduction << endl;
cout << "Net Take-Home: ₹" << netSalary << endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int hoursParked = 4;
double baseRateFirstHour = 50.00;
double hourlyRateSubsequent = 30.00;
double totalParkingFee = baseRateFirstHour + ((hoursParked - 1) * hourlyRateSubsequent);
cout << "--- Automated Parking Garage Invoice ---" << endl;
cout << "Total Hours Parked : " << hoursParked << " hrs" << endl;
cout << "Total Parking Fee : ₹" << fixed << setprecision(2) << totalParkingFee << endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double distanceKm = 450.0;
double vehicleMileageKmPerLitre = 18.5;
double fuelPricePerLitre = 96.50;
double fuelConsumedLitres = distanceKm / vehicleMileageKmPerLitre;
double totalTripCost = fuelConsumedLitres * fuelPricePerLitre;
cout << "--- Road Trip Cost Estimator ---" << endl;
cout << "Trip Distance : " << distanceKm << " km" << endl;
cout << "Fuel Consumed : " << fixed << setprecision(2) << fuelConsumedLitres << " Litres" << endl;
cout << "Estimated Cost : ₹" << totalTripCost << endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
// Subject 1: C++ Programming (4 Credits, 9 Grade Points)
int credit1 = 4; double gp1 = 9.0;
// Subject 2: Data Structures (4 Credits, 10 Grade Points)
int credit2 = 4; double gp2 = 10.0;
// Subject 3: Computer Networks (3 Credits, 8.0 Grade Points)
int credit3 = 3; double gp3 = 8.0;
int totalCredits = credit1 + credit2 + credit3;
double weightedScore = (credit1 * gp1) + (credit2 * gp2) + (credit3 * gp3);
double sgpa = weightedScore / totalCredits;
cout << "--- Student SGPA Academic Report ---" << endl;
cout << "Total Registered Credits : " << totalCredits << endl;
cout << "Semester SGPA : " << fixed << setprecision(2) << sgpa << " / 10.0" << endl;
return 0;
}