0% found this document useful (0 votes)
7 views7 pages

Power Grid 1

Uploaded by

Aditya Bhardwaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Power Grid 1

Uploaded by

Aditya Bhardwaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

#include <iostream>

#include <string>

using namespace std;

class Appliance {

string name;

float power; // in kW

bool isEssential; // essential vs non-essential

public:

Appliance(string n = "Unknown", float p = 0.0, bool essential = true) {

name = n;

power = p;

isEssential = essential;

float getPower() const { return power; }

bool essential() const { return isEssential; }

void display() const {

cout << " Appliance: " << name

<< " | Power: " << power << " kW"

<< " | " << (isEssential ? "Essential" : "Non-Essential")

<< endl;

};

// ======================== House Class ========================

class House {

int houseID;

Appliance appliances[5]; // Each house has 5 appliances

public:
House() {}

House(int id, float powerValues[5], bool essentialFlags[5]) {

houseID = id;

string names[5] = {"Fan", "Light", "TV", "Refrigerator", "WashingMachine"};

for (int i = 0; i < 5; i++) {

appliances[i] = Appliance(names[i], powerValues[i], essentialFlags[i]);

float totalHousePower() const {

float sum = 0;

for (int i = 0; i < 5; i++)

sum += appliances[i].getPower();

return sum;

float optimizedPower() const {

float sum = 0;

for (int i = 0; i < 5; i++) {

// Only keep essential appliances

if (appliances[i].essential())

sum += appliances[i].getPower();

return sum;

void display() const {

cout << "House " << houseID << " Consumption:" << endl;

for (int i = 0; i < 5; i++) {

appliances[i].display();
}

cout << " Total House Power = " << totalHousePower() << " kW" << endl;

cout << " Optimized Power = " << optimizedPower() << " kW" << endl << endl;

int getID() const { return houseID; }

// Grant access to Grid

friend class Grid;

};

// ======================== Grid Class ========================

class Grid {

int numHouses;

House houses[10];

public:

Grid(float allHousePowers[10][5], bool essentialFlags[10][5]) {

numHouses = 10;

for (int i = 0; i < numHouses; i++) {

houses[i] = House(i + 1, allHousePowers[i], essentialFlags[i]);

void display() const {

cout << "===== Smart Power Grid Report =====" << endl;

for (int i = 0; i < numHouses; i++) {

houses[i].display();

float totalConsumption() const {


float total = 0;

for (int i = 0; i < numHouses; i++)

total += houses[i].totalHousePower();

return total;

float optimizedConsumption() const {

float total = 0;

for (int i = 0; i < numHouses; i++)

total += houses[i].optimizedPower();

return total;

void reportHighConsumers() const {

float avg = totalConsumption() / numHouses;

cout << "=== High Consumption Houses (> Average " << avg << " kW) ===" << endl;

for (int i = 0; i < numHouses; i++) {

if (houses[i].totalHousePower() > avg) {

cout << "House " << houses[i].getID()

<< " | Consumption: " << houses[i].totalHousePower() << " kW" << endl;

cout << endl;

void optimizeLoad() const {

float total = totalConsumption();

float optimized = optimizedConsumption();

cout << "=== Load Optimization Report ===" << endl;

cout << "Current City Load = " << total << " kW" << endl;

cout << "Optimized City Load = " << optimized << " kW" << endl;
cout << "Potential Savings = " << total - optimized << " kW" << endl;

cout << "================================" << endl;

};

int main() {

// Example data: 10 houses, each with 5 appliances (power in kW)

float housePowers[10][5] = {

{0.2, 0.1, 0.3, 1.0, 0.5},

{0.3, 0.1, 0.2, 1.2, 0.6},

{0.25,0.15,0.35,0.9, 0.4},

{0.4, 0.2, 0.25,1.1, 0.55},

{0.35,0.2, 0.3, 1.3, 0.7},

{0.3, 0.15,0.2, 0.95,0.45},

{0.25,0.1, 0.4, 1.0, 0.5},

{0.2, 0.2, 0.3, 1.25,0.6},

{0.3, 0.15,0.25,1.1, 0.55},

{0.35,0.2, 0.35,1.4, 0.75}

};

// Essential (1 = essential, 0 = non-essential)

bool essentialFlags[10][5] = {

{1, 1, 0, 1, 0}, // Fan, Light essential; TV, WM non-essential

{1, 1, 0, 1, 0},

{1, 1, 0, 1, 0},

{1, 1, 0, 1, 0},

{1, 1, 0, 1, 0},

{1, 1, 0, 1, 0},

{1, 1, 0, 1, 0},

{1, 1, 0, 1, 0},

{1, 1, 0, 1, 0},
{1, 1, 0, 1, 0}

};

// Create Smart Grid

Grid cityGrid(housePowers, essentialFlags);

// Reports

cityGrid.display();

cityGrid.reportHighConsumers();

cityGrid.optimizeLoad();

return 0;

Features Added

Optimization: turns off *non-essential* appliances.

High Consumers Report**: identifies which houses are above average usage.

Savings Report: shows how much load can be reduced (kW).

===== Smart Power Grid Report =====

House 1 Consumption:

Appliance: Fan | Power: 0.2 kW | Essential

Appliance: Light | Power: 0.1 kW | Essential

Appliance: TV | Power: 0.3 kW | Non-Essential

Appliance: Refrigerator | Power: 1.0 kW | Essential

Appliance: WashingMachine | Power: 0.5 kW | Non-Essential

Total House Power = 2.1 kW

Optimized Power = 1.3 kW

...

=== High Consumption Houses (> Average 2.25 kW) ===


House 5 | Consumption: 2.85 kW

House 10 | Consumption: 3.05 kW

=== Load Optimization Report ===

Current City Load = 22.5 kW

Optimized City Load = 15.0 kW

Potential Savings = 7.5 kW

================================

```

You might also like