Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <time.h>
- using namespace std;
- class NumarComplex {
- private:
- float r;
- float i;
- public:
- NumarComplex() {}
- NumarComplex(float r, float i)
- : r(r)
- , i(i)
- {}
- friend ostream& operator<< (ostream& out, const NumarComplex& c);
- };
- ostream& operator<< (ostream &out, const NumarComplex &c)
- {
- out << c.r << " + " << c.i << "i\n";
- return out;
- }
- class A {
- private:
- int ri; // random integer
- float rf; // random float;
- NumarComplex rc; //random complex
- public:
- A(){
- srand(time(NULL));
- ri = rand();
- rf = (float)(RAND_MAX) / (float)rand();
- rc = NumarComplex((float)(RAND_MAX) / (float)rand(), (float)(RAND_MAX) / (float)rand());
- }
- int getRi() {
- return ri;
- }
- float getRf() {
- return rf;
- }
- NumarComplex getRc() {
- return rc;
- }
- template <typename T>
- T getRandom(T t) {
- return t;
- }
- };
- int main() {
- A a;
- srand(time(NULL));
- int random_type = (int)(rand() % 3);
- if (random_type == 0)
- cout << "Nr intreg: " << a.getRandom<int>(a.getRi());
- else if (random_type == 1)
- cout << "Nr real: " << a.getRandom<float>(a.getRf());
- else if (random_type == 2)
- cout << "Nr complex: " << a.getRandom<NumarComplex>(a.getRc());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement