#include <iostream>
#include <cmath>
#include <iomanip>
// Constants
const double MAX_SUNLIGHT_INTENSITY = 1000.0; // Max sunlight intensity in watts per square meter
const double PANEL_EFFICIENCY = 0.18; // Efficiency of the solar panel
// Class to represent a solar panel
class SolarPanel {
public:
SolarPanel(double area, double angle)
: area(area), angle(angle) {}
// Method to update the angle of the solar panel
void setAngle(double newAngle) {
angle = newAngle;
}
// Method to calculate the energy output based on sunlight intensity and panel angle
double calculateEnergyOutput(double sunlightIntensity) const {
// Simplified model where energy output is affected by the cosine of the angle
double effectiveIntensity = sunlightIntensity * cos(angle * M_PI / 180.0);
effectiveIntensity = std::max(0.0, effectiveIntensity); // No negative intensity
return effectiveIntensity * area * PANEL_EFFICIENCY;
}
// Method to print the current state of the solar panel
void printInfo(double sunlightIntensity) const {
double energyOutput = calculateEnergyOutput(sunlightIntensity);
std::cout << "Panel Area: " << std::fixed << std::setprecision(2)
<< area << " m²\n"
<< "Panel Angle: " << angle << " degrees\n"
<< "Sunlight Intensity: " << sunlightIntensity << " W/m²\n"
<< "Energy Output: " << energyOutput << " watts\n";
}
private:
double area; // Area of the solar panel in square meters
double angle; // Angle of the solar panel in degrees
};
int main() {
// Create a solar panel with a given area and initial angle
SolarPanel panel(1.0, 30.0); // 1 square meter panel, 30 degrees angle
// Simulation parameters
double sunlightIntensity = MAX_SUNLIGHT_INTENSITY; // Initial sunlight intensity
double angleStep = 10.0; // Step to change the angle
int simulationSteps = 10; // Number of simulation steps
// Run the simulation
for (int step = 0; step < simulationSteps; ++step) {
std::cout << "Step " << (step + 1) << ":\n";
panel.printInfo(sunlightIntensity);
// Update panel angle for the next step
panel.setAngle(panel.getAngle() + angleStep);
sunlightIntensity *= 0.9; // Simulate decreasing sunlight intensity over time
std::cout << std::endl;
}
return 0;
}