Dr
Two clients, yes. No server in this architecture
klimi
Luca
yes.
Talula
Isn’t this like WebSocket or MQTT?
Dr
But MQTT need broker right!?👀
Peace
A pointer could be of void type but reference variables cannot . Why ?
Pavel
But I'm not an expert here
Max
Hi
Strife
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
//------F(3.6)
int F(int m,int n){
if(m==1 || n==0 || m==n)
return 1;
else
return F(m-1,n)+F(m-1,n-1);
}
int a(){
int m=3;
int n=6;
cout<<"F(3-1,6)+F(3-1,6-1)="<<F(m-1,n)+F(m-1,n-1);
return 0;
}
int b(){
int n=3;
int m=6;
cout<<"F(m-1,n)+F(m-1,n-1)="<<F(m-1,n)+F(m-1,n-1);
return 0;
}
main(){
cout<<"F(3-1,6)+F(3-1,6-1)= "<<'\n'<<"answer \\\\ "<<a();
cout<<'\n'<<'\n';
cout<<"F(6-1,3)+F(6-1,3-1)= "<<'\n'<<"answer \\\\ "<<b();
return 0;
}
Strife
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
//------F(3.6)
int F(int m,int n){
if(m==1 || n==0 || m==n)
return 1;
else
return F(m-1,n)+F(m-1,n-1);
}
int a(){
int m=3;
int n=6;
cout<<"F(3-1,6)+F(3-1,6-1)="<<F(m-1,n)+F(m-1,n-1);
return 0;
}
int b(){
int n=3;
int m=6;
cout<<"F(m-1,n)+F(m-1,n-1)="<<F(m-1,n)+F(m-1,n-1);
return 0;
}
main(){
cout<<"F(3-1,6)+F(3-1,6-1)= "<<'\n'<<"answer \\\\ "<<a();
cout<<'\n'<<'\n';
cout<<"F(6-1,3)+F(6-1,3-1)= "<<'\n'<<"answer \\\\ "<<b();
return 0;
}
hi guys
i'm beginner in c++ so please check this code
Talula
Strife
a() must be 4 and b() =20 But it shows me other answers
Talula
Strife
i change return my answer change if return 1 a() =41
Strife
Talula
yes
Because you're returning 0 and it is displaying that.
Talula
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
//------F(3.6)
int F(int m,int n){
if(m==1 || n==0 || m==n)
return 1;
else
return F(m-1,n)+F(m-1,n-1);
}
void a(){
int m=3;
int n=6;
cout<<"F(3-1,6)+F(3-1,6-1)="<<F(m-1,n)+F(m-1,n-1);
}
void b(){
int n=3;
int m=6;
cout<<"F(m-1,n)+F(m-1,n-1)="<<F(m-1,n)+F(m-1,n-1);
}
int main(){
cout<<"F(3-1,6)+F(3-1,6-1)= "<<'\n'<<"answer \\\\ ";
a();
cout<<'\n'<<'\n';
cout<<"F(6-1,3)+F(6-1,3-1)= "<<'\n'<<"answer \\\\ ";
b();
return 0;
}
Anonymous
Strife
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
//------F(3.6)
int F(int m,int n){
if(m==1 || n==0 || m==n)
return 1;
else
return F(m-1,n)+F(m-1,n-1);
}
void a(){
int m=3;
int n=6;
cout<<"F(3-1,6)+F(3-1,6-1)="<<F(m-1,n)+F(m-1,n-1);
}
void b(){
int n=3;
int m=6;
cout<<"F(m-1,n)+F(m-1,n-1)="<<F(m-1,n)+F(m-1,n-1);
}
int main(){
cout<<"F(3-1,6)+F(3-1,6-1)= "<<'\n'<<"answer \\\\ ";
a();
cout<<'\n'<<'\n';
cout<<"F(6-1,3)+F(6-1,3-1)= "<<'\n'<<"answer \\\\ ";
b();
return 0;
}
thanks
Luca
Strife
Peace
why compiler is not dereferencing void pointer? int p=10;
void *ptr;
ptr=&p;
cout << *ptr << " "<< ptr;
return 0;
Peace
Pavel
Pavel
Pavel
I mean we have std::any
Pavel
then why it is allowed if eventually void will get casted into another datatype.
If you want to pass some data and you don't know the type of it.
So you can have an event system and want to be able to attach data of any type to the event.
So you can allocate it, store as void*, some info about type, and probably pointer to a function that will clear the data (call delete).
But that's an old (C) way of doing that, you would use std::any in C++ for that.
Pavel
C++ is supporting a lot of C features, and a lot of very specific features, it doesn't mean you need to use them all
Anonymous
then why it is allowed if eventually void will get casted into another datatype.
void* is useful in C++ when you need to treat memory as just memory. It is used in custom allocators where people need to write their own memory allocators for efficiency reasons suited to their own use cases. The part of this allocator which allocates memory doesn't know the types of objects that is going to be stored there. So they have to reference this memory using void* pointers. If you look at the standard library allocators code, you would find multiple void* references
Anshul
in set stl, when i am doing this how does the find function works
Anshul
set<Student,Student_cmp> s;
int n;
cin>>n;
for(int i=0;i<n;i++)
{
string name,rollNo;
int age;
cin>>age>>name>>rollNo;
Student temp(name,age,rollNo);
s.insert(temp);
}
for(auto x:s)
{
cout<<x.name<<" "<<x.age<<" "<<x.rollNo<<endl;
}
Student to_find("Anshul",20,"2001");
if(s.find(to_find)!=s.end())
{
cout<<s.find(to_find)->rollNo;
}
else
{
cout<<"not present";
}
Anshul
class Student
{
public:
string name;
int age;
string rollNo;
Student(string n,int a,string roll)
{
name=n;
age=a;
rollNo=roll;
}
Student(){}
};
class Student_cmp
{
public:
bool operator()(Student s1,Student s2)
{
return s1.rollNo<s2.rollNo;
}
};
Anshul
Anonymous
what if i want to know the element which is exactly same. i.e. i want to define my own == operator
In your case, you take only the roll number into consideration. So if there are two students with the same roll number but different names, the set will treat them as equal and only one of them will be inserted into the tree.
If your comparison operator is designed well and it takes all attributes of importance into consideration then you will have no issues.
In your example if no students have the same roll number (typically that would be the case), then your comparison is fine. It should be able to locate the element whose roll number is the same as the roll number of the student you are looking for.
Anshul
Anshul
i want that i sort students according to their roll no. but consider two students to be same if their names are same
Dark
Please send mingw compiler link
Dima
lol
Dima
maybe pdf?
Anonymous
Anshul
Anonymous
Vlad
Anshul
Anonymous
Anonymous
Yeah that is fine. But don't expect immediate feedback.
Amu
i have a question regarding a small part of my concurrency code
Amu
* enqueueStops --
*
* Enqueue "num" stop requests (i.e. one per worker thread) into
* the task queue associated with this request generator.
*
* Hint: Use the stop_handler function declared in
* RequestHandlers.h in conjunction with the task queue to
* create the stop requests.
*
* Results:
* Does not return a value.
*
* ------------------------------------------------------------------
*/
void RequestGenerator::
enqueueStops(int num)
{
// stop_handler(num)
// TODO: Your code here.
}
Amu
what does it mean to enqueue num of stop requests if anyone understands
Anonymous
what does it mean to enqueue num of stop requests if anyone understands
We can't comment much without understanding the full context.
But I guess it means that there is a mechanism by which threads can indicate that they want a running job to be stopped using a stop handler. They probably expect you to be able to enqueue a stop request from each worker thread (therefore num stop requests in all) and thus stop 'num' jobs currently in progress.
Amu
The code for the stop handler is below:/*
* ------------------------------------------------------------------
* stop_handler --
*
* The thread should exit.
*
* Results:
* None.
*
* ------------------------------------------------------------------
*/
void
stop_handler(void* args)
{
// TODO: Your code here.
}
Anonymous
Amu
I understand that but what do you think is the right info to add to the stop handler? perhaps pthread exit?
Amu
and also what could the argument possibly be
Amu
“ Enqueue arg->maxTasks requests to the supplier queue, then
* stop all supplier threads by enqueuing arg->numSuppliers
* stop requests.”
Amu
I see, thanks for the info. i’ll probably be back if i have any more questions
Amu
static void*
supplierGenerator(void* arg)
{ class Simulation
{
public:
TaskQueue supplierTasks;
TaskQueue customerTasks;
EStore store;
int maxTasks;
int numSuppliers;
int numCustomers;
explicit Simulation(bool useFineMode) : store(useFineMode) { }
};
Amu
I have a class called simulation and supplier generator takes arg which is a pointer to the shared simulation object, however the shared simulation object does not have a constructor. How do create this shared simulation object in my supplier generator function? (remember arg is a pointer to the shared simulation object and I can’t use new)
Peace
What does it mean by flushing the stream when using cout<< endl; ?
Prince Of Persia
Peace
Prince Of Persia
please explain..
cout << end
Is equal to
cout << '\n' << flush;
Peace
Prince Of Persia