Dima
Continue learning cxx
Dima
Knowing just syntax won’t give you anything
Anonymous
https://pastebin.com/
Anonymous
Hi
Anonymous
I want to share my code
Anonymous
how can I do it ?
Anonymous
I put it in pastebin
Anonymous
Thanks
olli
I want to share my code
Input your code, click on "create" and copy that link. It should look like https://pastebin.com/xxxXXxXx
Anonymous
Hello all
Anonymous
😊
Anonymous
I don't understand virtual function concept in c++
Anonymous
start understanding classes
Class concept doesn't bother me much.friend , virtual function do
BinaryByter
Class concept doesn't bother me much.friend , virtual function do
virtual functions are functions that don'T exist
BinaryByter
you cannot call them
Anonymous
So why we use them?
BinaryByter
it forces classes that inherit from your class to implement them
BinaryByter
concrete example:
Dima
You can take look at webcpp code
Dima
BinaryByter
"shape" has a virtual function called "area"
olli
Class concept doesn't bother me much.friend , virtual function do
Virtual functions are there to support dynamic or late dispatching. In comparison to other object oriented languages C++ functions are not virtual by default, since virtual functions come with a performance hit. They are required to support polymorphism.
BinaryByter
however a "shape" doesnt have an area
BinaryByter
however, a square has an area
BinaryByter
and it inherits from shape
olli
you cannot call them
Did you mean pure virtual? You can call virtual functions
olli
Class concept doesn't bother me much.friend , virtual function do
You can also have a look at that answer, proving an example. https://stackoverflow.com/a/2392656
Anonymous
Thank you
Anonymous
#include "stdio.h" int main() { int num = 0; double average = 0.0; int total = 0; int count = 0; printf("Print numbers: "); do{ count = count + 1; scanf("%d", &num); total = total + num; }while(num != 0); average = total/count; printf("%.1f", average); return 0; }
Anonymous
I know this code has logical error
Anonymous
But I dont know where
Anonymous
code should get numbers from user until the user put 0
Anonymous
and find average
BinaryByter
BinaryByter
was it allah?
BinaryByter
or was it jesus?
BinaryByter
wait jesus isn't a god
BinaryByter
well he partly is
BinaryByter
He only is 1/3 of a god
BinaryByter
anyway, which god told you that it has a logical error?
Ariana
I know this code has logical error
at least say the error-_-
Anonymous
anyway, which god told you that it has a logical error?
ok funny guy tell me if u know ... unless ...go
BinaryByter
I was hinting to you that we cannot really help you without knowing which error it is
BinaryByter
How would you help me if I told you "my body doesnt work" and then gave you a graph of all the molecules of my body?
Anonymous
for example: I put 10 20 0
Anonymous
and got 10.000000
BinaryByter
what did you expect as a result?
BinaryByter
because i'd say that 10.000000 is a pretty good average
Anonymous
15.000
BinaryByter
check the calculation by hand, do you mind?
Anonymous
10+20 =30
Anonymous
30/2
Anonymous
15
BinaryByter
except you do 30/3
Anonymous
I want 0 just work as a agent to exit
BinaryByter
well then leave the loop before doing any array operations
BinaryByter
and decrement the iterator
BinaryByter
this is what you want
Anonymous
let me check
Anonymous
Nice 😉
Anonymous
Thanks buddy
BinaryByter
sure 😉
🐰🐾 سمیه
Hi, what does this part mean? while contains no statement.
BinaryByter
wat?
🐰🐾 سمیه
wat?
explain what this part do in the program plz?
BinaryByter
it reads a char and compares it to other chars
BinaryByter
and assigns that character to s[0] and c
BinaryByter
operator= returns the asignee
🐰🐾 سمیه
it reads a char and compares it to other chars
what happens after that? it has no statement
BinaryByter
yes
BinaryByter
it just loops until the condition is not met
BinaryByter
it is like doing this while (...) { }
BinaryByter
its function body is replaced by a ";"