✟꧁۝ঔৣঔৣ۝꧂✟
✟꧁۝ঔৣঔৣ۝꧂✟
✟꧁۝ঔৣঔৣ۝꧂✟
where did i use STD:: tupls
✟꧁۝ঔৣঔৣ۝꧂✟
tuple
yse nan becouse
f and s wasnt initialised
✟꧁۝ঔৣঔৣ۝꧂✟
ok how did i initialised them
and also u have to check divizion by zero
wait a second
i ll send u an example
✟꧁۝ঔৣঔৣ۝꧂✟
ok i will wait
float calculate(float fr, char op, float sc) { float result; if(op == '+') { result = fr + sc; } else if(op == '-') { result = fr - sc; } else if(op == '*') { result = fr * sc; } else if(op == '/') { result = fr / sc; // check devizion by zero!!! } else { // Wrong operation (return 1 argument)!!! result = fr; } return result; }
https://en.cppreference.com/w/cpp/utility/tuple
tuple allow u to return a collection of values
Anonymous
Constructor is useful or not in c and c++ programs
BinaryByter
Constructor is useful or not in c and c++ programs
it can be useful depending on what you do
BinaryByter
Like anything, if you use it well it can help
BinaryByter
its about knowing WHEN to use it
Anonymous
Why copy constructor is rarely use in programming
Anonymous
BinaryByter
However, using too much OOP is a bad habit many programmers have
BinaryByter
i'd advise you to keep the oop to a minimum
BinaryByter
until you understand how you stuff works
✟꧁۝ঔৣঔৣ۝꧂✟
it work
BinaryByter
ps: not even the cpp standard commitee knows how oop works well 😉😉
BinaryByter
Take as example std::substr 😂😂😂
✟꧁۝ঔৣঔৣ۝꧂✟
Anonymous
Ok bro
it work
note, i dont check if 2nd parameter is zero (it could create UB ( /0)
✟꧁۝ঔৣঔৣ۝꧂✟
note, i dont check if 2nd parameter is zero (it could create UB ( /0)
i think it work on the else if (op ==char('/')) && sc !=0)
✟꧁۝ঔৣঔৣ۝꧂✟
if i put the above
yes but if u do so it will return the 1st argument (the else statment) and u will not know that 2nd paramter was zero
as u are using floats
✟꧁۝ঔৣঔৣ۝꧂✟
what about we used on else if and
it will return infs(-/+) inf as a result of number / 0
✟꧁۝ঔৣঔৣ۝꧂✟
and else for wrong opratoon and F=0
also there are one more intresting situation
0 / 0
which will return Nan
std::isnan() can help
✟꧁۝ঔৣঔৣ۝꧂✟
yes you are right
✟꧁۝ঔৣঔৣ۝꧂✟
u will return nothing if operation is incorrect
u have to return something
✟꧁۝ঔৣঔৣ۝꧂✟
I_Interface
u have to return something
compiler should send a warning
i just want to write it)
I_Interface
and why not switch case ?
I_Interface
it's more readble
yes
but i try to use authors (@Jagama_kelo) code style
✟꧁۝ঔৣঔৣ۝꧂✟
ok let me write again with swich and i will back
✟꧁۝ঔৣঔৣ۝꧂✟
it's a bad style :)
ya i now i am bigner 😊
✟꧁۝ঔৣঔৣ۝꧂✟
it's a bad style :)
i will back with swich
✟꧁۝ঔৣঔৣ۝꧂✟
thank you all
I_Interface
ya i now i am bigner 😊
and u don't need a "result" var for those operations
yes he can just return
a results of operations
but i try to use authors code style 🙂
I_Interface
but i try to use authors code style 🙂
nah, better to learn him for a good style now, mate
enum OPERATIONS : uint8_t {ADD = '+', SUB = '-', MUL = '*', DIV = '/'} float calculate(float fr, OPERATIONS op, float sc) { switch (op) { case OPERATIONS::ADD: return fr + sc; case OPERATIONS::SUB: return fr - sc; case OPERATIONS::MUL: return fr * sc; case OPERATIONS::DIV: // as we use floats we // can return +/- Inf (num / 0) // and Nan (if 0 / 0) return fr / sc; default: return fr; } }
Dima
https://godbolt.org/z/OBlSBd
http://cpp.sh
@Jagama_kelo u can test it here
BinaryByter
#ot
Anonymous
Please tell me baalguruswamy book is best or not for c and c++ programming
Try Ivor Horton’s book. It’s best. It contains updated material.
tejaswi
tejaswi
Can anyone remove all the error and make it run from me
tejaswi
Please
tejaswi
After removing all errors please send me the CPP file
tejaswi
Please help