Exercise 2: Battery Model
We want to design a program to manage battery models.
(a) Define a type, BatteryModel, that represents a battery model, that is made of the known voltage , the amount of energy
it is capable of storing, and the energy it is currently storing (in joules).
(b) Define a function PowerDevice that takes as arguments: a current of an electrical device (amps), a battery of type
BatteryModel, and the time the device is to be powered by the battery (seconds), and determines whether the battery's energy reserve is adequate to power the device. If so, the function updates its reserve by subtracting the energy consumed and returns the value 1. Otherwise it returns the value 0 and leaves the energy reserve unchanged.
(c) Define a function MaxTime that takes as arguments: a current of an electrical device and a battery of type BatteryModel,
and returns the number of seconds this battery can operate the device before it is fully discharged. This function may not modify the energy reserve.
#include <stdio.h>
struct Battery_Model{
int voltage;
int energy;
};
int PowerDevice(struct Battery_Model c, int t){
if (t>50)
return 1;
else
return 0;
}
int MxaTime(int c, int model){
int t;
return t;
}
int main()
{
return 0;
}
Comments
Leave a comment