✟꧁ঔৣঔৣ꧂✟
✟꧁ঔৣঔৣ꧂✟
✟꧁ঔৣঔৣ꧂✟
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
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
BinaryByter
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)
✟꧁ঔৣঔৣ꧂✟
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 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
I_Interface
✟꧁ঔৣঔৣ꧂✟
thank you all
឵
yes he can just return
I_Interface
឵
a results of operations
឵
but i try to use authors code style 🙂
឵
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
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