Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Help! Design and implement a class to model a battery. A battery object should know its voltage, how much energy it is capable of

Please Help!

Design and implement a class to model a battery. A battery object should know its voltage, how much energy it is capable of storing, and how much energy it is currently storing (in joules). Include the following member functions.

powerDevice: Given the current of an electrical device (amps) and the time the device is to be powered by the battery (seconds), this function determines whether the battery's energy reserve is adequate to power the device. If so, the function updates its energy reserve by subtracting the energy consumed and returns the value true. Otherwise it returns the value false and leaves the energy reserve unchanged.

maxTime: Given the current of an electrical device, the function returns the number of seconds the battery can operate the device before it is fully discharged. This function does not modify the energy reserve.

reCharge: This function sets the battery's component representing the present energy reserve to its maximum capacity.

Use the following equations in your design.

p=vi p= power in watts (W)

v= voltage in volts (V)

w=pt i= current in amos (A)

w= energy in joules (J)

t= time in seconds (s)

For this simulation, neglect any loss of energy in the transfer from battery to device.

Create a main function that tests your class by creating an object to model a 12-V automobile battery with a maximum energy storage of 5x10^6 J. Use the battery to power a 4-A light for 15 minutes. Then find out how long the battery's remaining energy could power an 8-A device. After recharging the battery, ask again how long it could operate an 8-A device.

Here is what I am so far:

#include using namespace std;

class Battery { public: Battery() {} // default constructor Battery(float voltage, float energy_joules, float curr_joules);

bool powerDevice(float current_amps, float time_secs); float maxTime(float current_amps); void reCharge();

private: float voltage; float energy_joules; float curr_joules;

friend istream& operator >> (istream&, Battery&); friend ostream& operator << (ostream&, const Battery&);

};

Battery::Battery(float battery_voltage, float battary_energy_joules, float battary_curr_joules) { voltage = battery_voltage; energy_joules = battary_energy_joules; curr_joules = battary_curr_joules; }

istream & operator >> (istream &is, Battery &batteryB){ is >> batteryB.voltage >> batteryB.energy_joules >> batteryB.curr_joules; return is; }

ostream& operator<<(ostream&os, const Battery&batteryA) { os << batteryA.voltage << fixed << "-V," << batteryA.energy_joules << scientific << "J," << batteryA.curr_joules << scientific << " J" << endl; return os; }

bool Battery::powerDevice(float current_amps, float time_secs) { double energy; energy = voltage*current_amps*time_secs; if (energy == energy_joules) { return true; }else{ return false; } }

float Battery::maxTime(float current_amps) { double time; time = energy_joules / (voltage*current_amps); }

void Battery::reCharge(){ curr_joules = energy_joules; }

int main() { Battery batteryA(12, 5000000, 5000000); bool powerDevice(4,900); float maxTime(8); void recharge();

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions

Question

Draw and explain the operation of LVDT for pressure measurement

Answered: 1 week ago