Anonymous
can you any one explain how this code workes?
Anonymous
can you any one explain how this code workes?
this looks like it is someone explaining private inheritance, without actually using inheritance. you want people to explain the explanation itself?
Anonymous
i would suggest reading a book
Anonymous
though i guess the base of the cylinder is called "base" as well
Anonymous
this looks like it is someone explaining private inheritance, without actually using inheritance. you want people to explain the explanation itself?
You mean you would do this instead class Cylinder : private Circle or that someone is trying to explain this?
Anonymous
You mean you would do this instead class Cylinder : private Circle or that someone is trying to explain this?
ye the Circle was called "base" so i guessed someone was trying to explain what private inheritance looks like.
Anonymous
Yes I am really confused this based method
it's not a method, it just calls the Circle(double) constructor for the member variable named base
Anonymous
Double volume (){return base.area()*height;}
Anonymous
Double volume (){return base.area()*height;}
base is an object of type Circle. You can call Circle's public members using it. Here the constructor of circle initialized the base object's radius to r following which you call base.area() which calls the area member function in Circle. It returns a double value (the area of the base) which is then multiplied by the height of the cylinder to compute the volume of the cylinder.
....
Guys where can I learn making an app with c++ or if u have pdf
....
yo, what app do you mean? GUI or TUI?
Just one of them I dont really know what they are too
klimi
Just one of them I dont really know what they are too
it would be better to learn the basics of the language and then learn the graphical libraries
Anonymous
Just one of them I dont really know what they are too
Bryan Cairns' Qt courses on Udemy
....
Bryan Cairns' Qt courses on Udemy
I tried that but it is not that nice do u have pdf or if u would tell me where can I get it?
Anonymous
SDL is a nice graph lib
....
OK man do u have PDF?
Nils
void updateProgress(uint8_t percentage) { if (percentage <= 100) { barY = (barRect.x2-barRect.x1)/100*percentage; } } Any clue why this does not work? with percentage 100 given the value is not (barRect.x2-barRect.x1)
Anonymous
integral
there is your answer
Nils
Uhm?
Anonymous
Uhm?
the divide by 100 will truncate digits after the decimal
Nils
Ohhh
Nils
lol thanks let me try that by casting to float first
Nils
the divide by 100 will truncate digits after the decimal
barY = (float(barRect.x2-barRect.x1))/100*percentage; It's still not working.
Nils
Yeah, made a float of every single value in the calculation, still same problem.
Anonymous
://
Anonymous
barY = (float(barRect.x2-barRect.x1))/100*percentage; It's still not working.
add a watch for the expression (float(barRect.x2-barRect.x1))/100*percentage; on your IDE and see what happens
ꍏꈤꀸ
how to evaluate CPU usage by the process while it’s waiting to enter critical section? right now i have one more thread, which in while(true) each 1s. calculate CPU usage during all execution. I'm not sure it's the best solution. BTW, is it ok, that CPU usage is 0% when i'm locking/unlocking mutex?
Arnabjit
How to approach this problem? https://codeforces.com/problemset/problem/1065/C
ian
Does anyone know why clang -O2 makes my program have this behavior? In my code there is no loop however when using -O2 in clang the program seems to repeat for some reason, but when using -O1 or GCC -O2 it doesn't it does. IMG: https://postimg.cc/mcGpcwrM The code is very simple and is the following: https://paste.opensuse.org/657e1578 clang version 11.0.1 gcc version 10.3.0 (SUSE Linux)
olli
FreeBSD 13 clang does not cause my program to crash using -O2 (FreeBSD clang version 11.0.1 (git@github.com:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c3fe)) https://postimg.cc/PPC2qcdN I assume it has to do with the clang build provided by SUSE ?
You should fix your warnings, there are multiple issues in your program. scanf stores length + 1 characters because the string has to be null-terminated, hence 8 bytes are not enough to store "DDMMAAAA"
PS
How to find largest subsequence of array??
Anonymous
How to find largest subsequence of array??
You dont have to find anything. Just return the array.
Anonymous
How to approach this problem? https://codeforces.com/problemset/problem/1065/C
Sort the array of blocks on height from smallest to tallest and use greedy programming
PS
It has a condition too
PS
That sum of elements in subsequence must be greater than 0
Talula
Anonymous
That sum of elements in subsequence must be greater than 0
You should mention that as well when you ask a question. Does the sub sequence elements need to be in the same order as in the array I.e. should they be contiguous elements?
Anshul
If I make a pointer of type list. Then will it be able to access the elements of list. (List I'm referring is c++ stl) fun(list * start, list* end) { List *p; for(p=start;p!=null;p=p->next) ..... ... Here is it possible to do p->next will p not be pointing at the head of the list. Or p will be pointing at the first node in the list
Anshul
Okay
Anshul
P will be pointing to an object of list? So by Using arrow operator with p, I can only access head of list right?
Anonymous
P will be pointing to an object of list? So by Using arrow operator with p, I can only access head of list right?
No. Suppose say you do this: void fun(){ std::list<int> a; //populate a auto p = &a; } Here a is allocated on the stack. But when you populate the list, the elements themselves will be allocated on the heap. So p will be pointing to the data structure on the stack and not to the elements on the heap. You have to understand the difference clearly here.
Anonymous
Yeah thanks. So will there be any use of creating such pointer. As we can't access anything using pointer p
There are not many uses for creating a pointer to a STL data structure in Modern C++. But if you have a pointer, you can still access the list's public data members using that pointer. You can also pass this pointer to other functions instead of passing the list data structure itself (a reference should be preferred however).
Anshul
If I pass list like this Fun( list a) {} Main () { List<int> b; Fun(b); } Here any changes made to a will it reflect to b as well?
Anshul
You mean I should pass like this Fun (list &a) {} instead this Fun (list *a) {}
Anonymous
If I pass list like this Fun( list a) {} Main () { List<int> b; Fun(b); } Here any changes made to a will it reflect to b as well?
No. Here you are passing a copy and changes to the copy wont be reflected in the original list.
Anonymous
You mean I should pass like this Fun (list &a) {} instead this Fun (list *a) {}
Yes. The first method is preferred. There are other ways of passing a list like passing an iterator range or using ranges library (or std::ranges if you use C++20)
Anshul
You mean I should pass like this Fun (list &a) {} instead this Fun (list *a) {}
And in both cases changes will be reflected in the original list? And why first one is preferred? Is it because first one doesn't create a new memory space
Anonymous
And in both cases changes will be reflected in the original list? And why first one is preferred? Is it because first one doesn't create a new memory space
Yes changes will be reflected in both. The first one is preferred because generally when you use raw pointers, it is not clear at the call site if the caller/callee should free the memory associated with the pointer. Because raw pointers are seldom needed in Modern C++, the second method should not be used.
Evans
Anyone with Full C resources? Good person
Anonymous
i need help on c programming on homework please contact me ! i can pay thank you ! its a business for you, you can earn money ! 😀
klimi
i need help on c programming on homework please contact me ! i can pay thank you ! its a business for you, you can earn money ! 😀
no.. no... no... :( why you have to do this? why don't you atleast comply with the rules?
klimi
Anyone with Full C resources? Good person
https://en.cppreference.com/w/
Anonymous
hey, guys following the best practices, should I write: char* string or char *string ?
Anonymous
hey, guys following the best practices, should I write: char* string or char *string ?
Just follow the style already existing in the code base. If it is a new code base and if you are in the habit of declaring multiple variables of the same base type on a line choose char *str. If you follow the practice of declaring/defining only one variable on a line then either is good.
Anshul
What can be the reason for this Terminate called after throwing an instance of std::logic_error
Anshul
terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_M_construct null not valid