somebody help me please!
Write the following C\C++ program:
Program starts two threads (from now onwards A and B).

Main program generates number N from range 5000 and 10000.

Number N is passed to thread A.

Threads A generates N random numbers from the range [1, 100].

Generated numbers are passed to thread B.

Thread B writes these numbers to a file. The user of the program is prompted in the main thread for the names of the file (path) number are to be written to. The name is passed to the thread B.

Each thread returns count of processed numbers to the main program. The massage showing both counts should be printed at last.

To control run of threads events mechanism should be used.

Identification numbers of the process and threads should be printed out.

The zipped project needs to be written in Eclipse-Galileo environment.

Comments
Thread hijack and zero effort failure!

Could you show us what you have so far...

srand(time(NULL) ); 
int N = rand()%5001+5000; 
int num; 

for(int i=0;i <N;++i) 

    num = rand()%100+1;

and don't know what else to do

Edited 6 Years Ago by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

Could you show us what you have so far...

#define STRICT
#include <windows.h>
#include <stdio.h>

int main()
{
	unsigned int	ppid	= (unsigned int)GetCurrentProcessId();
	unsigned int	pthid	= (unsigned int)GetCurrentThreadId();
	HANDLE		hThread;
	DWORD		thId;

	//Parent Process and Parent 
printf ("(THREAD2:MAIN):     PID = %5d : THID =%5d : Parent process started.\n",
				(int)ppid, (int)pthid);

	fflush(stdout);

	//Create Thread
	if (hThread) {
		printf ("(THREAD A:MAIN):     Thread ID =%5d created successfully.\n",
				(int)thId);
		fflush(stdout);
	}
	else	{
			printf ("(THREAD2:MAIN):     Function \"CreateThread\" failed with error nbr %d.\n", (int)GetLast Error());
		}




	return 0;}

Edited 6 Years Ago by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

You will want to use _beginthreadex() to create the two threads. Scroll down to the bottom of that link and it will show you an example of how to create the thread and wait for the thread to exit. After the thread ends call GetExitCodeThread() to get its return value. Those functions are declared in <process.h> and <windows.h>

The program instructions also state that you have to pass several variables to those threads. The only way you can do that is to create structures to hold the values and pass a pointer to the structure instance as the parameter to _beginthreadex().

Edited 6 Years Ago by Ancient Dragon: n/a

This article has been dead for over six months. Start a new discussion instead.