Dima
very sus
borealis
it is just Exercise for teach of constructor throw Exceptions mechanism.friend please Find updated Code Below for causing Exception to Throw For Invalid Triangle after negative value Issue being resolved by Appropriate unsign integer usage . Below is check if Mathematical triangle can be form , raise exception if Not possible . Pyramid(unsigned int l, unsigned int w, unsigned int h) : length(l), width(w), height(h) { auto sides = { length, width, height }; auto max = *std::max_element(sides.begin(), sides.end()); auto sum = std::accumulate(sides.begin(), sides.end(), 0); sum > 2 * max ?0: throw std::invalid_argument("invalid triangle!"); };
Dima
lol
borealis
sorry External link,, it was Link for helpful Triangle calculation web site.
Danya🔥
Wtf is going on
Ughhh
Hello. Does anyone have a .net maui todo list application?
Ughhh
That is fully functional
borealis
this is Not DOt net Programming group
Paulo
it is just Exercise for teach of constructor throw Exceptions mechanism.friend please Find updated Code Below for causing Exception to Throw For Invalid Triangle after negative value Issue being resolved by Appropriate unsign integer usage . Below is check if Mathematical triangle can be form , raise exception if Not possible . Pyramid(unsigned int l, unsigned int w, unsigned int h) : length(l), width(w), height(h) { auto sides = { length, width, height }; auto max = *std::max_element(sides.begin(), sides.end()); auto sum = std::accumulate(sides.begin(), sides.end(), 0); sum > 2 * max ?0: throw std::invalid_argument("invalid triangle!"); };
I understand what ware you doing the exercise, explicit mention throw a exception for invalid number, this exercise also specify the type of values. And also if you make something like that. Pyramid pyramid(-4, -4, 6); the constructor will convert de negative number in a bigg positive number, because of the type rules and signal bit. My question is more about the good practices about validate variables inside a constructor the best way to do that. I appreciate your help.
web Developer
Please I need you guys to suggest me C++ mini project👌?
Manav
Please I need you guys to suggest me C++ mini project👌?
Find what you're interested in, make an app in C++ related to it.
Ziky
desktop app dont thank
https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life I did it in QT
Paulo
Hi everyone I'm read this article and found a good explanation about emplace_back and push_back.
Paulo
This is the article: https://andreasfertig.blog/2023/04/push_back-vs-emplace_back-when-to-use-what/#:~:text=emplace_back%20for%20better%20performance,And%20that%20is%20 What I understood is that emplace back only has performance improvements if it can create the object inside the vector, if you give a temporary object or an object it will behave exactly like push-back
Paulo
Is that correct? I showed this article to an experienced C++ developer and he didn't agree, but the source code shows that is correct.
FriedRice
I think think there is no difference in performance, just semantic difference.
Paulo
In some cases if emplace can create an object inside the vector it will avoid operations and only call the constructor of the object
Pavel
This is the article: https://andreasfertig.blog/2023/04/push_back-vs-emplace_back-when-to-use-what/#:~:text=emplace_back%20for%20better%20performance,And%20that%20is%20 What I understood is that emplace back only has performance improvements if it can create the object inside the vector, if you give a temporary object or an object it will behave exactly like push-back
One thing though that emplace_back would forward arguments to a constructor, even explicit one, so e.g. if you have v.push_back(2); And later change the type of v to be std::vector<std::vector<int>> then this code will still compile and create a vector with two elements. So IMO push_back is preferable unless the intention is to actually create an object in-place
Paulo
What you wrote sounds correct, do you remember what exactly he disagreed with?
I sent a code where I had an object called emplace_back and push_ back, in both case The behavior is the same, because emplace can't create an object inside a vector when it already exists, but he said the function emplace will create the object inside the vector, but it no happens
Paulo
Object obj; vector v; v.push_back(obj); v.emplace_back(obj); v.push_back(Object()); v.emplace_back(Object()); In both cases the exists and is just passed for the function and both emplace and push have the same behavior.
Paulo
Want to say thanks, this kind of discussion helps me a lot.
D1ws
https://www.youtube.com/watch?v=7xwjjolDnwg
Danya🔥
https://www.youtube.com/watch?v=7xwjjolDnwg
I watched this talk halfway yesterday and it seemed to me chaotic, as if the speaker was trying to fit a course on operating systems and assembly programming into one presentation. It's not bad, but it can be confusing.
Anonymous
So guys, can anyone help me solve this exercise? Make a program that performs simple operations on complex numbers: • Create and read two complex numbers z and w, composed of a real part and an im- gym. • Present the addition, subtraction and product between z and w, in that order, as well as the module of both.
web Developer
Who need Grading system source code using pure C++ ?
Pavel
Object obj; vector v; v.push_back(obj); v.emplace_back(obj); v.push_back(Object()); v.emplace_back(Object()); In both cases the exists and is just passed for the function and both emplace and push have the same behavior.
In this case yes, but in case of emplace_back in the second case you would normally just call v.emplace_back(); without arguments Also, not really reliable way, but at least some way to reason about what is happening there https://wandbox.org/permlink/RT9JXxiUCnLY2XJq
FriedRice
I mean pushback takes rvalue reference as well so it may somehow construct object in-place imo.
Priyanshu
What is flow chart
Priyanshu
Flow chart
Pavel
I mean pushback takes rvalue reference as well so it may somehow construct object in-place imo.
The object that is going to be stored will be constructed in the corresponding place in the vector, there's no way from that. push_back will construct it via copy or move constructor. emplace_back will construct it with a constructor that matches the provided arguments (so if you pass another object of this type it will try to call the copy constructor, and if you pass rvalue reference or temporary it will try to call the move constructor).
Jhinga_Man
How can I learn C programming, specifically after arrays
Jhinga_Man
How can I start DSA?
Manav
How can I start DSA?
Data structures are mostly language independent. It's not like binary trees look much different when coded in C or javascript, for instance.
Manav
How can I learn C programming, specifically after arrays
There's no set hierarchy so it's not clear what you mean by after arrays. I could teach you about arrays before i talk about structs or delay talking about arrays until i have taught nearly everything.
Jhinga_Man
So can we talk in DMs?
Manav
So can we talk in DMs?
We can talk here, it's more beneficial for you as it also prevents me from talking bs as others can check my replies.
Jhinga_Man
Okay😂 suits me
Jhinga_Man
Like I am in college.... So from where should I start in C language?
Jhinga_Man
I have learned loops, conditional statements and arrays
Jhinga_Man
Read the rules
Don't worry I took the permission!!
Manav
Like I am in college.... So from where should I start in C language?
There's book recommendations in https://t.me/cpp20programming
Jhinga_Man
Cs50 is not enough
John
Cs50 is not enough
But u can begin with it
Jhinga_Man
But u can begin with it
Yeah I have already done that
Arnold
implement all the common data structures yourself in plain C and you will feel much better
Anonymous
Yeah I have already done that
You can do this course: https://youtube.com/playlist?list=PLeURq1l0XRkj7EQMLeQwtaEMOXlP_DpEz&feature=shared to learn Data Structures and Algorithms. You need to be familiar with some programming language before you do that so that you can try implementing what is taught in that course
Jhinga_Man
Write a C program to find if a graph is Eulerian (i.e., does it have an Eulerian cycle). Your input is what is called as an Adjacency matrix A. If a graph has N nodes then A is an array of size N × N, with A[i][j] = 1 if node i is connected to j and 0 otherwise. Your program should be able to read an Adjacency matrix of any size N. For simplicity, let the graphs that are read be connected graphs, i.e., every node can be reached from every other node Like what I have study to understand this kind of question
Jhinga_Man
Okay got it thanks .... Helped a lot
Anonymous
Note to all: I have added the above YouTube Playlist to the videos section in the Resources channel. In future, if someone asks about references for DSA courses, kindly point them to the Resources channel in the pinned post.
Arnold
try implementing a depth first search or a breadth first search algorithm. That's a good and easy intro to any graph work.
Arnold
Just google what depth first search is. You should definitely be able to do that before you do your assignment.
Hasna
what is the difference between string& name; string name;
Michael
what is the difference between string& name; string name;
The first one is an error, the second one isn't
Light
what is the difference between string& name; string name;
First one means the address of an object belonging to string class Second one is the object itself belonging to string class
Light
The first one is an error, the second one isn't
Its not error, it just depends on how you use it
Michael
Its not error, it just depends on how you use it
The way it's written leads to a compilation error
VD
First one means the address of an object belonging to string class Second one is the object itself belonging to string class
First one does not mean address of an object. It is actually a reference to a string (it is implemented as pointers underneath the hood though). References can't be null and hence it causes a compilation error as mentioned by the other user. References need to be initialized. Anyway I guess the Op's post was about differences between a reference and normal variable
Michael
Now both lead to compilation errors 😁
imminent
did you include <string>?
imminent
and prefix the string with a std::
VD
string& name; string &name; ?
string alpha = "alpha"; string& ref = alpha; string &ref1 = alpha; cout << ref; //prints alpha ref1.push_back('b'); cout << ref; //prints alphab ref.push_back('e'); cout << ref1; //prints alphabe alpha.push_back('t'); cout << ref; //prints alphabet cout << ref1;//prints alphabet
artemetra 🇺🇦
string& name; string &name; ?
no difference. you can even write string & name;, but i personally don't do that
Light
Writing string & name is the biggest crime one can comit 😂
The
no tests should every fail. if a test fails, something is wrong and should be fixed (leaving "correctly failing" tests in the pipeline creates noise that will let race condition bugs slip away)
JFYI .. boost::lockfree::spsc_queue getting hung up on producer side... in the sense not allowing consumer to consume.. after around 12 seconds of run :/ producer is a bit faster than consumer... once it tilts to producer it's not coming back to consumer.. gonna do strand-post next.. Edit: this was my code mistake.. queue's fine 😅