#include <iostream> //for output
#include <cstdlib> //for rand, srand
#include <ctime> //for time (useful in conjunction with srand)
struct Resistor
{
//declare some variables
//Per your assignment:
//"members of the Resistor struct will be
//Rnominal, Ractual, and tol...all of type double"
};
void setActual(Resistor& r)
{
//tolerance delta: how far away you can be from nominal
//calculated by Rnominal * tolerance (tolerance expressed as 0.05 for 5%, for example)
//calculate a random number between two values
//the highest value will be the nominal value + tolerance delta
//the lowest value will be the nominal value - tolerance delta
//r.Ractual = (the random number you calculate)
}
int main()
{
//seed the random number generator with srand
//create a resistor object
//set its Rnominal to 330
//set its tol to 0.05 (which is 5%)
//call setActual and pass the resistor object as a parameter
//print all the fields of the resistor object
}
I would suggest the C++11 random library (http://www.cplusplus.com/reference/random/) over <cstdlib>. It's better, more flexible and completely outclasses and removes any need for rand().