Write a C or C++ program A6p1.c[pp] that accepts two command line arguments n and m where n is an integer between 2 and 6 inclusive and m can be assumed to be a multiple of 60 (e.g. 60,120,etc). Generate a string of m random upper case English characters and store them somewhere (e.g. in a char array). Use pthread to create n threads to convert the string of m chars in place into an off-by-one lower case version (i.e. ‘A’→’b’, ‘B’→’c’, ‘C’→’d’,…, ‘Y’→’z’, ‘Z’→’a’). You should divide this conversion task among the n threads as evenly as possible. Print out the string both before and after conversion on two separate lines. Hint: it is dangerous to have code to print messages in your thread function(s). You may refer to testThread.c, testThread2.c, pthread_ex1.c, pthread_ex2.c for examples. Note: if you do not use pthread to divide the conversion task among the threads, you may get zero points.
Has to contain two line arguments, not just one.
/ CPP Program to find sum of array
#include <iostream>
#include <pthread.h>
#include <cstdlib>
#include <stdio.h>
// size of array
#define MAX 60
using namespace std;
char a[MAX];
int part = 0;
int MAX_THREAD;
void *convert_to_lowercase(void *arg)
{
// Each thread will convert 1/MAX_THREAD part of the array
int thread_part = part++;
for (int i = thread_part *(MAX / MAX_THREAD); i < (thread_part + 1) *(MAX / MAX_THREAD); i++)
{
//if the character is Z then it should be converted to a
if (a[i] == 90)
a[i] = 97;
else
a[i] = a[i] + 33;
}
}
// Driver Code
int main(int argc, char **argv)
{
if (argc == 2)
sscanf(argv[1], "%d", &MAX_THREAD);
else
{
cout << "The number of arguments is invalid" << endl;
return -1;
}
if (MAX_THREAD < 3 || MAX_THREAD > 5)
{
cout << "The number of threads is invalid" << endl;
return -1;
}
for (int i = 0; i < MAX; i++)
//create a string of random upper case characters and storing it in an char array
a[i] = (char)(64 + rand() % 26 + 1);
cout << "The String before conversion is: " << endl;
//print the string with random characters
for (int i = 0; i < MAX; i++)
cout << a[i];
cout << endl;
pthread_t threads[MAX_THREAD];
// Creating 4 threads
for (int i = 0; i < MAX_THREAD; i++)
pthread_create(&threads[i], NULL, convert_to_lowercase, (void*) NULL);
// joining 4 threads i.e. waiting for all 4 threads to complete
for (int i = 0; i < MAX_THREAD; i++)
pthread_join(threads[i], NULL);
cout << "The String after conversion is: " << endl;
for (int i = 0; i < MAX; i++)
cout << a[i];
cout << endl;
return 0;
}
Write a C or C++ program A6p1.c[pp] that accepts two command line arguments n and m where n is an integer between 2 and 6 inclusive and m can be assumed to be a multiple of 60 (e.g. 60,120,etc). Generate a string of m random upper case English characters
Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusive. Generate a string of 60 random upper case English characters and store them somewhere (e.g. in a char array). Use pthread to create n threads to convert the string into a complementary string (‘A’<->’Z’, ‘B’<->’Y’, ‘C’<->’X’, etc). You should divide this conversion task among the n threads as evenly as possible. Print out the string both before...
1. (50 pts) Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusive. Generate a string of 60 random upper case English characters and store them somewhere (e.g. in a char array). Use pthread to create n threads to convert the string into a complementary string ('A'<>'Z', 'B'<->'Y', 'C''X', etc). You should divide this conversion task among the n threads as evenly as possible, Print out the...
1. Write a C or C++ program A6p2.c[pp] that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60 random integers between 1 and 39 inclusive and store them in a 5 by 12 two dimensional integer array (e.g.,int a[5][12];). Use pthread to create n threads to convert all 60 array elements modulo 11 (i.e. take the remainder after division by 11) in place. You should divide this update task among the n threads as evenly as possible. Print the array both before and after...
Write a C++ program that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60 random integers between 1 and 49 inclusive and store them in a 5 by 12 two dimensional integer array (e.g.,int a[5][12];). Use pthread to create n threads to square all 60 array elements. You should divide this update task among the n threads as evenly as possible. Print the array both before and after the update separately as...
Write a C or C++ program
A6pc(pp) that accepts one command
line argument which is an integer n between 2 and 6
inclusive. Generate a string of 60 random upper case English
characters and store them somewhere (e.g. in a char array). Use
pthread to create n threads to convert the string into a
complementary string (‘A’<->’Z’, ‘B’<->’Y’,
‘C’<->’X’, etc). You should divide this conversion task among
the n threads as evenly as possible. Print out the string
both before...
Write a C or C++ program A8p1.c(pp) that accepts one command line string parameter. Call the fork function to produce two processes. In the child process print out the lower case version of the string. In the parent process print out the reversed upper case version of the string (e.g. child: “abc”; parent: ”CBA”). You may call the toupper and tolower functions in the header <ctype.h> if you wish. Specify in the output whether the parent or child process is...