Answer:
Implementation of resistor.cpp
#include "resistor.h"
Ohms::Ohm()
{
// default constructor
voltage=0;
}
Ohms::Ohm( double x) // parameterised constructor
{
voltage = x; // voltage x set to the supply voltage in the private data field called voltage
}
Ohms:: setVoltage(double a)
{
voltage = a;// to set supply voltage in private data field called voltage
}
Ohms::setOneResistance( String s, double p)
{
cin>>p; //enter the resistance value
if(p<=0) // if resistance is less than or equals to 0
return false
else // if re
cin.getline(s);
}
Ohms::getVoltage()
{
return voltage; //return voltage of ckt
}
Ohms::getCurrent()
{
return current; //return current of ckt
}
Ohms:: getNode()
{
return resistors; //return resistors of ckt
}
Ohms::sumResist()
{
double tot_resist = accumulate(resistors.begin(),resistors.end(),0); //std::accumulate function for calculating sum //of vectors and following are the starting and ending points
return tot_resist;
}
Ohms::calcCurrent()
{
if(current <=0) // if current is less than or equal to 0
return false;
else // if current is greater than 0
return true;
}
Ohms:: calcVoltageAcross()
{
if(voltage<=0) // if voltage is less than or equal to 0
return false;
else //if voltage greater than 0
return true;
}
Explanation:
in the case of main.cpp its simple just make a class object and remember to include resistors.cpp with it for which the second last picture describes the process precisely. (Hint: Use theunit test case functions in the main.cpp).
As you can see node is a structure consisting of member variables, followed by a class Ohms representing a DC circuit.
By looking at these pictures, it is needed to implement the main.cpp and resistor.cpp files. The user defined header file resistor.h already consists of all contents of Class Ohm, struct node. You don't need to modify it in anyway in such case.