MODULE 1: INTRODUCTION TO C++ 1.4 Ten Real-World C++ Foundation Programs

Industrial reference manual: 10 practical, real-world foundation programs implemented in C++ covering basic input/output, arithmetic computations, conditional checks, loops, and functional logic, complete with execution outputs and workflow diagrams.

💻 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.

1. Currency Converter (USD to INR)
A real-world program that converts US Dollars to Indian Rupees based on a fixed exchange rate.
C++ / Currency Conversion
#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;
}
--- Currency Exchange Calculator --- Amount in USD : $250.00 Exchange Rate : ₹86.50 Converted INR : ₹21625.00
2. Body Mass Index (BMI) Health Calculator
Calculates a user's BMI given their weight in kilograms and height in meters.
C++ / BMI Calculator
#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;
}
--- BMI Health Assessment --- Weight : 72.5 kg Height : 1.75 m Calculated BMI: 23.7
3. E-Commerce Discount Billing Calculator
Computes final retail bill after applying a festival promotional discount percentage.
C++ / Retail Discount Calculator
#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;
}
--- Retail Billing Invoice --- Marked Price : ₹4500.00 Discount (15%): -₹675.00 Final Payable : ₹3825.00
4. Electricity Bill Consumption Calculator
Calculates monthly utility charges based on total units consumed and fixed tariff rates.
C++ / Utility Bill Calculator
#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;
}
--- Electricity Utility Bill --- Units Consumed: 240 kWh Energy Charge : ₹1560.00 Fixed Charge : ₹100.00 Total Due : ₹1660.00
5. Simple Interest & Maturity Calculator
Computes simple interest earned on a fixed deposit over a specified tenure.
C++ / Fixed Deposit Interest Calculator
#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;
}
--- Fixed Deposit Maturity Statement --- Principal Amount : ₹100000.00 Interest Earned : ₹22500.00 Maturity Total : ₹122500.00
6. Temperature Conversion (Celsius to Fahrenheit)
Converts weather temperature readings from Celsius to Fahrenheit.
C++ / Temperature Converter
#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;
}
--- Temperature Conversion --- Temperature in Celsius : 37.5°C Temperature in Fahrenheit : 99.5°F
7. Employee Gross Salary & Deductions Statement
Calculates an employee's net take-home salary after factoring in HRA, DA, and provident fund deductions.
C++ / Payroll Salary Slip
#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;
}
--- Employee Salary Statement --- Basic Salary : ₹50000.00 Gross Salary : ₹80000.00 PF Deduction : -₹3600.00 Net Take-Home: ₹76400.00
8. Automated Parking Fee Calculator
Calculates parking garage fees based on total hours parked and hourly parking rates.
C++ / Parking Fee Calculator
#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;
}
--- Automated Parking Garage Invoice --- Total Hours Parked : 4 hrs Total Parking Fee : ₹140.00
9. Fuel Efficiency & Trip Cost Estimator
Estimates total fuel consumption and trip cost for a road journey based on distance, mileage, and fuel price.
C++ / Trip Cost Estimator
#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;
}
--- Road Trip Cost Estimator --- Trip Distance : 450.0 km Fuel Consumed : 24.32 Litres Estimated Cost : ₹2347.30
10. Student Semester Grade Point Average (SGPA) Calculator
Computes a student's Semester GPA based on course credits and grade points earned across 3 subjects.
C++ / SGPA Calculator
#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;
}
--- Student SGPA Academic Report --- Total Registered Credits : 11 Semester SGPA : 9.09 / 10.0