C++ So here\'s what I got. I have a working program that in the main() that crea
ID: 3558021 • Letter: C
Question
C++
So here's what I got. I have a working program that in the main() that creates an array of 5 pointer objects of the Class Resistor. What I can't figure out is how to use a static variable (shown below as resNumber) to limit the number of class objects created to say 3 (just for argument). The requirement is for that I'm having issues meeting is spelled out below. Everything else I'm good on...
#include "Resistor.h"
int Resistor::resNumber = 0;
Resistor::Resistor()
{
// not random for some reason...
nominalRes = rand() % 10000 + 1000; //should set random number between 1,000 and 10,000
nominalTol = 0.05;
resNumber++;
resistorName = "Resistor";//would like to add resNumber to the endof this...
}
//not full main or class obviously...
void main(void)
{
srand(GetTickCount());
Resistor *ptRes[5];
}
Explanation / Answer
Static variable will be invoked before the execution of constructor and it
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.