Given the following input: 267 U 0 10,H 1525 04812252933 0101525010152501015250101516171819202122232425010152519152523456781525 The expected output is: ASSIGNMENT RUBRIC: 15 points for each test correct output (max 30 points). 25 points for using a single memory location for thread argument passing. 5 points for code readability (modularity + comments). 10 points for taking full advantage of multithreading. Penalties: 100% for using global variables. 100% for not using pthread library. 100% for presenting a solution that does not compile. Requested files main.cpp TEST 1 Your output is incorrect. Your program tested with: Input string: 267 U 0 10, H 1525 04812252933 YOUR OUTPUT: .main1.sh: line 1: 4128112 Seqmentation fault (core dumped) .main < input1.txt CORRECT OUTPUT: TEST 2 Your output is incorrect. Your program tested with: Input string: {:335 {: - 22325061 #include #include #include #include #define MAXROWS 100 #define MAXCOLS 100 Structure to hold row data for each thread typedef struct { int rownum; int *headPos; int *dataPos; char *symbols; char *decodedrow; } threaddatat; Function to decode a single row void *decoderow(void *arg) { threaddatat *data = (threaddatat *)arg; int start = data→headPos[data→rownum]; int end = (data→rownum + 1 < MAXROWS) ? data→headPos[data→rownum + 1] : MAXCOLS; Decode the row based on headPos and dataPos for (int i = start; i < end; i++) { data→decodedrow[i] = data→symbols[data→dataPos[i]]; } Print the decoded row printf("Row %d: %s ", data→rownum, data→decodedrow); return NULL; } int main() { int n, m; char buffer[MAXCOLS]; int headPos[MAXROWS]; int dataPos[MAXROWS]; char symbols[MAXCOLS]; char decodedrow[MAXCOLS]; Read input from STDIN scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { scanf(" %c", &symbols[i]); } for (int i = 0; i < n; i++) { scanf("%d", &headPos[i]); } for (int i = 0; i < n; i++) { scanf("%d", &dataPos[i]); } Create threads to decode each row pthreadt threads[MAXROWS]; threaddatat threaddata[MAXROWS]; for (int i = 0; i < n; i++) { threaddata[i].rownum = i; threaddata[i].headPos = headPos; threaddata[i].dataPos = dataPos; threaddata[i].symbols = symbols; threaddata[i].decodedrow = decodedrow; if (pthreadcreate(&threads[i], NULL, decoderow, &threaddata[i]) ≠ 0) { perror("Failed to create thread"); exit(EXITFAILURE); } } Wait for all threads to finish for (int i = 0; i < n; i++) { pthreadjoin(threads[i], NULL); } return 0; } Fix this code in c++, following each requirement and make sure the code brings the expected input with the output and pleaseMAKE SURE IT IS CORRECT!!!!
Question:
Given the following input: 267 U 0 10,H 1525 04812252933 0101525010152501015250101516171819202122232425010152519152523456781525 The expected output is: ASSIGNMENT RUBRIC: 15 points for each test correct output (max 30 points). 25 points for using a single memory location for thread argument passing. 5 points for code readability (modularity + comments). 10 points for taking full advantage of multithreading. Penalties: 100% for using global variables. 100% for not using pthread library. 100% for presenting a solution that does not compile. Requested files main.cpp TEST 1 Your output is incorrect. Your program tested with: Input string: 267 U 0 10, H 1525 04812252933 YOUR OUTPUT: .main1.sh: line 1: 4128112 Seqmentation fault (core dumped) .main < input1.txt CORRECT OUTPUT: TEST 2 Your output is incorrect. Your program tested with: Input string: {:335 {: - 22325061 #include #include #include #include #define MAXROWS 100 #define MAXCOLS 100 Structure to hold row data for each thread typedef struct { int rownum; int *headPos; int *dataPos; char *symbols; char *decodedrow; } threaddatat; Function to decode a single row void *decoderow(void *arg) { threaddatat *data = (threaddatat *)arg; int start = data→headPos[data→rownum]; int end = (data→rownum + 1 < MAXROWS) ? data→headPos[data→rownum + 1] : MAXCOLS; Decode the row based on headPos and dataPos for (int i = start; i < end; i++) { data→decodedrow[i] = data→symbols[data→dataPos[i]]; } Print the decoded row printf("Row %d: %s ", data→rownum, data→decodedrow); return NULL; } int main() { int n, m; char buffer[MAXCOLS]; int headPos[MAXROWS]; int dataPos[MAXROWS]; char symbols[MAXCOLS]; char decodedrow[MAXCOLS]; Read input from STDIN scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { scanf(" %c", &symbols[i]); } for (int i = 0; i < n; i++) { scanf("%d", &headPos[i]); } for (int i = 0; i < n; i++) { scanf("%d", &dataPos[i]); } Create threads to decode each row pthreadt threads[MAXROWS]; threaddatat threaddata[MAXROWS]; for (int i = 0; i < n; i++) { threaddata[i].rownum = i; threaddata[i].headPos = headPos; threaddata[i].dataPos = dataPos; threaddata[i].symbols = symbols; threaddata[i].decodedrow = decodedrow; if (pthreadcreate(&threads[i], NULL, decoderow, &threaddata[i]) ≠ 0) { perror("Failed to create thread"); exit(EXITFAILURE); } } Wait for all threads to finish for (int i = 0; i < n; i++) { pthreadjoin(threads[i], NULL); } return 0; } Fix this code in c++, following each requirement and make sure the code brings the expected input with the output and pleaseMAKE SURE IT IS CORRECT!!!!
Asked by: Test User 100081
Created at: 2025-04-27 16:08:57
Final Answer:
📢 Instructions:
- Ask anything relatd to above question only.
- For new Question goto :
VIPSolutions