Resistor Struct C++ programming

newbuie
Last edited on
We won't do your homework for you
please solve this problem I don't have any idea about this
I'd be interested in why Yansons post was reported.

please solve this problem I don't have any idea about this
Then learn a few things so you have an idea about this?
Seriously I could solve it in a bunch of ways, some of them would not even be readable...

You should try to do it yourself first and then ask for help on what you don't understand.



and you should probably read this article:
http://www.cplusplus.com/forum/articles/1295/
Last edited on
??this is now hw
I am jjust studying myself
Then show us what you've done in your studying.
When studying programming you need to write code, show us what you've got.
@leetgb
Here's a starting point for you:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#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().
Topic archived. No new replies allowed.