/********************************************************************
Engineering 3891 Advanced Structured Programming
Assignment: 8 Date Due: December 4th/2000
Name: Daryl Martin
Student #: 9713520
Username: darylm
*********************************************************************/
#include <cstdlib>
#include "assign8.h"
int Capacitor::last = 0;
int Resistor::last = 0;
int Gate::last = 0;
Pin Device::dummy;
/******************************************************************
* Device::Device (char d, int i, int n) -- The constructor
* creates a device of n pins
*
*
* Date: 12/4/00
*******************************************************************/
Device::Device (char d, int i, int n){
if(n == 0 || i == 0 || d == '/0' || !(mpPins = new Pin[n]))
{
mNumPins = 0;
mInstance = 0;
mDesignator = '\0';
}
else{
mDesignator = d;
mNumPins = n;
mInstance = i;
}
}
/******************************************************************
* Device::~Device() -- Kill off the pin array
*
*
* Date: 12/4/00
*******************************************************************/
Device::~Device(){
delete mpPins;
}
/******************************************************************
* Pin& Device::operator[] (int i) -- Overload of the iterator
* to allow reading or connection of the i'th pin
*
*
* Date: 12/4/00
*******************************************************************/
Pin& Device::operator[] (int i){
if(i < 1 || i > mNumPins){
return dummy;
}
else{
return mpPins[i-1];
}
}
/******************************************************************
* char* who()
*
*
* Date: 12/4/00
*******************************************************************/
char* Device::who(){
static char devName[6];
devName[0] = mDesignator;
_itoa(mInstance,devName + 1,10);
return devName;
}
/******************************************************************
* Simple:Simple (d,i,v,t) -- Must construct a 2 pin device,
* designation d, instance i, value v and tolerance tl
*
*
* Date: 12/4/00
*******************************************************************/
Simple::Simple (char d, int i, double v, double t1) : Device(d,i,2){
mValue = v;
mTolerance = t1;
}
/******************************************************************
* double Simple::value() -- Return value
*
*
* Date: 12/4/00
*******************************************************************/
double Simple::value(){
return mValue;
}
/******************************************************************
* double Simple::tolerance() -- Return tolerance
*
*
* Date: 12/4/00
*******************************************************************/
double Simple::tolerance(){
return mTolerance;
}
/******************************************************************
* void Simple::set(double v, double t) -- Change value & tolerance
*
*
* Date: 12/4/00
*******************************************************************/
void Simple::set(double v, double t){
mValue = v;
mTolerance = t;
}
/******************************************************************
* void Simple::set(double v, double t) -- Construct 2 pin device,
* designation 'C', instance last of value c, capType t, tolerance m
*
*
* Date: 12/4/00
*******************************************************************/
Capacitor::Capacitor(double c, CapType t,double m):
Simple('C',++last,c,m){
mCapType = t;
}
/******************************************************************
* CapType Capacitor::type() -- Return Captype
*
*
* Date: 12/4/00
*******************************************************************/
CapType Capacitor::type(){
return mCapType;
}
/******************************************************************
* Resistor::Resistor(c,t,m) -- / Construct simple device,
* designation 'R', instance last, of value r, tolerance t
*
*
* Date: 12/4/00
*******************************************************************/
Resistor::Resistor(double r, double t):
Simple('R',++last,r,t){
}
/******************************************************************
* Gate::Gate(LogicType t) -- Need NULL constructor for new
*
*
* Date: 12/4/00
*******************************************************************/
Gate::Gate(LogicType t):
Device('U', ++last, 3)
{
mpPins[0].t = IN;
mpPins[1].t = IN;
mpPins[2].t = OUT;
}
/******************************************************************
* LogicType Gate::logicType() -- Return the Logic type
*
*
* Date: 12/4/00
*******************************************************************/
LogicType Gate::logicType(){
return mLogicType;
}