Fetheddine
Fetheddine
Idk if my question is clear!
olli
Why in the fonction we used a pointer.
You basically want to pass your array to the function and void foo(int*) is the same as void foo(int[]) because when passing an array you lose information about its size and it decays into a pointer.
Fetheddine
Thank uuu
Sam
can anyone help me to change this linear queue to cicular queue plz🥲
mayway
I've learned c++ from aman dhattarwal playlist upto oop ..I think it's all about mugging concepts..can anyone help me where should i learn my oop concept and dsa (yt, website, course.. any resources)
ᴹᵒʰᵃᵐᵐᵃᵈ
am = fopen("C:\\Users\\mohammad_z\\Desktop\\create_test\\graph_out1.txt", "w+");
Hello friends
This line works in this project, but does not allow the rest of the code to be executed, and after executing this line, the program ends, the same line in a test project I tested works well and my debugging goes well, but here the debugging gives an error and the project does not work properly, commenting on this function works properly in other parts of the project
Amirhossein
hi guys i have a question.
char s1[3] = "hi";
s1 = "test";
in the above example i can't do this because s1 is a static array ok?
but look below example
char s1[3] = "hi";
strcpy(s1,"test");
now no error and now s1 = "test"
how is this possible?
tnx
olli
Anonymous
Am getting an error(overloaded function with no contextual type information). anyone knows where i have done something wrong?
#include <iostream>
using namespace std;
float areaofcircle(float radius);
int main()
{
float radius;
cout<< "Enter radius"<<endl;
cin>> radius;
cout<< "arae is "<<areaofcircle();
}
float areaofcircle()
{
float pi=3.14;
float radius;
areaofcircle=pi*radius*radius;
return 0;
}
Anonymous
Any one
Amirhossein
Peace
Is String a class ?
Nils
What is better?
https://github-dotcom.gateway.web.tr/andreiamatuni/zstdpp
Or just raw zstd?
shriman_deepak
//Multiplication Of two Matrices
#include<stdio.h>
int main()
{
int row1,col1,sum=0;
printf("Enter the no. of rows and column ");
scanf("%d %d",&row1, &col1 );
int M1[row1][col1];
printf("Enter the elements of matrices ");
for (int i = 0; i < row1; i++)
{
for (int j = 0; j < col1; j++)
{
scanf("%d", &M1[i][j]);
}
}
for (int i = 0; i < row1; i++)
{
for (int j = 0; j < col1; j++)
{
printf("%d ", M1[i][j]);
}
printf("\n");
}
int row2,col2;
printf("Enter the no. of rows and column ");
scanf("%d %d",&row2, &col2 );
int M2[row2][col2];
printf("Enter the elements of matrices ");
for (int i = 0; i < row2; i++)
{
for (int j = 0; j < col2; j++)
{
scanf("%d", &M2[i][j]);
}
}
for (int i = 0; i < row2; i++)
{
for (int j = 0; j < col2; j++)
{
printf("%d ", M2[i][j]);
}
printf("\n");
}
int P[row1][col2];
if (col1 != row2)
{
printf("This cannot be executed ");
}
else
for (int i = 0; i < row1; i++)
{
for (int j = 0; i < col2; j++)
{
for (int k = 0; k <col2; k++)
{
sum += M1[i][k] * M2[k][j];
}
sum = P[i][j] ;
sum = 0;
}
}
for (int i = 0; i < row1; i++)
{
for (int j = 0; j < col2; j++)
{
printf("%d", P[i][j]);
}
printf("\n");
}
return 0;
}
shriman_deepak
can anyone plzz check this code
Talula
//Multiplication Of two Matrices
#include<stdio.h>
int main()
{
int row1,col1,sum=0;
printf("Enter the no. of rows and column ");
scanf("%d %d",&row1, &col1 );
int M1[row1][col1];
printf("Enter the elements of matrices ");
for (int i = 0; i < row1; i++)
{
for (int j = 0; j < col1; j++)
{
scanf("%d", &M1[i][j]);
}
}
for (int i = 0; i < row1; i++)
{
for (int j = 0; j < col1; j++)
{
printf("%d ", M1[i][j]);
}
printf("\n");
}
int row2,col2;
printf("Enter the no. of rows and column ");
scanf("%d %d",&row2, &col2 );
int M2[row2][col2];
printf("Enter the elements of matrices ");
for (int i = 0; i < row2; i++)
{
for (int j = 0; j < col2; j++)
{
scanf("%d", &M2[i][j]);
}
}
for (int i = 0; i < row2; i++)
{
for (int j = 0; j < col2; j++)
{
printf("%d ", M2[i][j]);
}
printf("\n");
}
int P[row1][col2];
if (col1 != row2)
{
printf("This cannot be executed ");
}
else
for (int i = 0; i < row1; i++)
{
for (int j = 0; i < col2; j++)
{
for (int k = 0; k <col2; k++)
{
sum += M1[i][k] * M2[k][j];
}
sum = P[i][j] ;
sum = 0;
}
}
for (int i = 0; i < row1; i++)
{
for (int j = 0; j < col2; j++)
{
printf("%d", P[i][j]);
}
printf("\n");
}
return 0;
}
Depends on what you're trying to do and please using paste bin
shriman_deepak
shriman_deepak
And i am trying to multiply 2 matrixes
𝔼𝕃𝔸𝕀𐇲
hey guys
𝔼𝕃𝔸𝕀𐇲
what is the best speech recognition library ?
Max
Who can help me with matrix exercise
We have matrix[i][j]
Program should count similar numbers next by next not from all matrix elements and print that element witch was similar most times or if it is two or more such elements print the last
Example
3 4 5
4 4 5
6 7 7
Print: 7
Because in second line is two 4 but in third line is two 7 and it is the last witch was similar two times
Max
Thank you Who will help me
Pavel
Thank you Who will help me
Hi, you need two loops one inside another (one for rows and one inside it for elements inside row), then you need to store variables for previous number, current repetitions, number with max repetitions and max amount of repetitions.
Then when iterating check if current number is not different from previous then, increase current repetitions, else reset. Each time check if current > max, and if it is, then update the max.
Max
now i have something like that
Max
#include <stdio.h>
int main(int argc, char const *argv[])
{
int rows = 0, cols = 0;
scanf("%d%d", &rows, &cols);
const int NUM_ROWS = rows;
const int NUM_COLS = cols;
int matrix[NUM_ROWS][NUM_COLS];
for (int i = 0; i < NUM_ROWS; i++)
{
for (int j = 0; j < NUM_COLS; j++)
{
scanf("%d", &matrix[i][j]);
}
}
printf("\n");
// алгоритм и вывод результата здесь
int sum = 0;
int count = 0;
int temp = 0;
for (int i = 0; i < NUM_ROWS; i++)
{
for (int j = 0; j <= NUM_COLS / 2; j++)
{
if( j <= i && j <= NUM_ROWS - i - 1){
printf("%d ", matrix[i][j]);
sum+=matrix[i][j];
}
}
printf("\n");
}
for (int i = 0; i < NUM_ROWS; i++)
{
for (int j = i + 1; j < NUM_COLS; j++)
{
if (matrix[i][j]==matrix[i][j+1])
{
count++;
}
}
}
printf("%d %d %d",sum,count,temp);
return 0;
}
Anshul
While using unordered map for a user defined key type, I need to overload== operator in the class that is the type of key.
And the other thing is I need to create my own hash function and in this class I need to write a method that returns a value of type size_t. But how is it taken care that the value returned by this function is always in bounds of the hash-table size
Anonymous
//Multiplication Of two Matrices
#include<stdio.h>
int main()
{
int row1,col1,sum=0;
printf("Enter the no. of rows and column ");
scanf("%d %d",&row1, &col1 );
int M1[row1][col1];
printf("Enter the elements of matrices ");
for (int i = 0; i < row1; i++)
{
for (int j = 0; j < col1; j++)
{
scanf("%d", &M1[i][j]);
}
}
for (int i = 0; i < row1; i++)
{
for (int j = 0; j < col1; j++)
{
printf("%d ", M1[i][j]);
}
printf("\n");
}
int row2,col2;
printf("Enter the no. of rows and column ");
scanf("%d %d",&row2, &col2 );
int M2[row2][col2];
printf("Enter the elements of matrices ");
for (int i = 0; i < row2; i++)
{
for (int j = 0; j < col2; j++)
{
scanf("%d", &M2[i][j]);
}
}
for (int i = 0; i < row2; i++)
{
for (int j = 0; j < col2; j++)
{
printf("%d ", M2[i][j]);
}
printf("\n");
}
int P[row1][col2];
if (col1 != row2)
{
printf("This cannot be executed ");
}
else
for (int i = 0; i < row1; i++)
{
for (int j = 0; i < col2; j++)
{
for (int k = 0; k <col2; k++)
{
sum += M1[i][k] * M2[k][j];
}
sum = P[i][j] ;
sum = 0;
}
}
for (int i = 0; i < row1; i++)
{
for (int j = 0; j < col2; j++)
{
printf("%d", P[i][j]);
}
printf("\n");
}
return 0;
}
In your 2nd for loop, you are checking for i < col2 which is not correct. It should be j < col2
And k iterates in the 3rd for loop from 0 to col2 which is wrong. It should be 0 to col1.
Anshul
Anshul
P.S.
why the function needs to be a const function?
I compiled just now and got error because I didn't make it const function
Anonymous
Anonymous
Anonymous
The function inside hash function class.
If it is not a const function, the implication is that it stores some state which gets altered everytime you call it. The basic underlying assumption behind hashing is that it always returns the same value everytime you call it with the same key. If it is not a const function, this assumption stands violated.
Anshul
Anshul
class Student
{
public:
string firstName;
string lastName;
string rollNo;
Student(string f,string l,string roll)
{
firstName=f;
lastName=l;
rollNo=roll;
}
Student()
{
}
/*bool operator==(const Student s) const
{
return rollNo==s.rollNo;
}*/
};
bool operator==(const Student &s1,const Student &s2)
return s1.rollNo==s2.rollNo;
}
class HashFn
{
public:
size_t operator()(const Student &s) const
{
return s.firstName.length()+s.lastName.length();
}
};
int main()
{
Student s1("Anshul","Pareek","2001");
Student s2("Anshul","Pareek","3001");
Student s3("Ayushi","Sijeria","2011");
Student s4("Nishant","Bhat","2031");
unordered_map<Student,int,HashFn> Student_map;
Student_map[s1]=85;
Student_map[s2]=68;
Student_map[s3]=15;
Student_map[s4]=78;
for(auto it=Student_map.begin();it!=Student_map.end();it++)
{
cout<<it->first.firstName<<" "<<it->first.rollNo<<" Marks: "<<it->second<<endl;
}
/*
for(auto x:Student_map)
{
cout<<x.first.firstname<<" "<<x.first.rollNo<<" Marks: "<<x.second<<endl;
}*/
}
J
Hello
German student trying to solve a douple liked list task here :D
Anshul
Anonymous
class Student
{
public:
string firstName;
string lastName;
string rollNo;
Student(string f,string l,string roll)
{
firstName=f;
lastName=l;
rollNo=roll;
}
Student()
{
}
/*bool operator==(const Student s) const
{
return rollNo==s.rollNo;
}*/
};
bool operator==(const Student &s1,const Student &s2)
return s1.rollNo==s2.rollNo;
}
class HashFn
{
public:
size_t operator()(const Student &s) const
{
return s.firstName.length()+s.lastName.length();
}
};
int main()
{
Student s1("Anshul","Pareek","2001");
Student s2("Anshul","Pareek","3001");
Student s3("Ayushi","Sijeria","2011");
Student s4("Nishant","Bhat","2031");
unordered_map<Student,int,HashFn> Student_map;
Student_map[s1]=85;
Student_map[s2]=68;
Student_map[s3]=15;
Student_map[s4]=78;
for(auto it=Student_map.begin();it!=Student_map.end();it++)
{
cout<<it->first.firstName<<" "<<it->first.rollNo<<" Marks: "<<it->second<<endl;
}
/*
for(auto x:Student_map)
{
cout<<x.first.firstname<<" "<<x.first.rollNo<<" Marks: "<<x.second<<endl;
}*/
}
Btw this is an inconsistent implementation of hash function. Two keys which are equal will return different hashes. Your hash function should be consistent with your == and != operators
Amu
does anyone know how to do multithreaded programming using pthreads
Amu
if so please dm me
Anonymous
Amu
/*
* ------------------------------------------------------------------
* startSimulation --
* Create a new Simulation object. This object will serve as
* the shared state for the simulation.
*
* Create the following threads:
* - 1 supplier generator thread.
* - 1 customer generator thread.
* - numSuppliers supplier threads.
* - numCustomers customer threads.
*
* After creating the worker threads, the main thread
* should wait until all of them exit, at which point it
* should return.
*
* Hint: Use sthread_join.
*
* Results:
* None.
*
* ------------------------------------------------------------------
*/
static void
startSimulation(int numSuppliers, int numCustomers, int maxTasks, bool useFineMode)
{
// // TODO: Your code here.
// sthread_t supplier_generator_thread;
// sthread_t customer_generator_thread;
// sthread_t supplier_thread[numSuppliers];
// sthread_t customer_thread[numCustomers];
// pthread_create(&supplier_generator_thread, NULL, &supplierGenerator, NULL);
// pthread_create(&customer_generator_thread, NULL, &customerGenerator, NULL);
// for (int i = 0; i < numSuppliers; i++)
// {
// pthread_create (&supplier_thread[i], NULL, &supplier, NULL);
// }
// for (int i = 0; i < numCustomers; i++)
// {
// pthread_create (&customer_thread[i], NULL, &customer, NULL);
// }
// pthread_join(supplier_generator_thread, NULL);
// pthread_join(customer_generator_thread, NULL);
// for (int i = 0; i < numSuppliers; i++)
// {
// pthread_join (supplier_thread[i], NULL);
// }
// for (int i = 0; i < numCustomers; i++)
// {
// pthread_join (customer_thread[i], NULL);
// }
}
int main(int argc, char **argv)
{
bool useFineMode = false;
// Seed the random number generator.
// You can remove this line or set it to some constant to get deterministic
// results, but make sure you put it back before turning in.
srand(time(NULL));
if (argc > 1)
useFineMode = strcmp(argv[1], "--fine") == 0;
startSimulation(10, 10, 100, useFineMode);
return 0;
}
Amu
i’ve commented out my code because im not entirely sure if i did it right, basically im supposed to create supplier threads and customer threads for a customer - supplier multithreaded problem in c++
Amu
this is how i attempted to write the supplier queue, basically i took the simulation object which contains a pointer to a taskqueue which contains enque deque capabilities. The supplier generator generates and enques these files using the estore functions while supplier deques these and implements them
Anonymous
Amu
Anonymous
Amu
I used monitors (false monitors of course since this isn’t java) using pthread api
Amu
Anonymous
sorry how do i share the pastebin link?
Just post the link here.
And ask specific questions if you have any. Posting a big chunk of code and asking people to check if it is correct won't get you many answers.
Amu
Amu
https://pastebin.com/db6dbdTL
tanu kumari
How can we use graphics.h header file in vs code
Anonymous
Amirhossein
Peace
Un-buffered standard error stream (cerr) , what does this buffer means ?
Anonymous
Hello guys, i am from Indonesian, nice to meet you all
Mj
Hope
Strife
Itx
Hi
Peace
Anonymous
Anunay
#ot
Anunay
Go there for off-topic chats
Luca
Hi all guys ..I'm planning to build a P2P network...any advice from there?
Talula