QuestionQuestion

Write a makefile for problems 1 and 2. Don’t use the default “a.out” executable filename.

1. Write a C or C++ program to input from the command line one string parameter. Use the fork function to get two processes. In the child process print out the all lower case version of the string parameter. In the parent process print out the all upper case version of the string parameter. Specify in the output whether the parent or child is printing.

2. Write a C or C++ program to input from the command line four real number parameters a, b, c, d. Create two threads in the main function and pass the four parameters a,b,c,d to the two threads in some way of your choice (thread function parameter is recommended). In one thread calculate and print out the product of the two complex numbers a+bi and c+di (where i is the imaginary unit), that is, the complex number (a+bi)(c+di). In the other thread calculate and print out the quotient of the two complex numbers a+bi and c+di, that is, the complex number (a+bi)/(c+di). Report an error if both c and d are zero. Specify in the output whether the result is the product or quotient. Use synchronization if necessary.

3. Write a bash script to call your C or C++ program in problem 1 and 2 with the following parameters. For problem 1, give the two string parameters “Helloween is one week away” and “Thanksgiving is one month away”. For problem 2 give two groups of parameters “1.1 2.2 3.3 4.4” and “-1.5 2.5 -3.5 4.5”.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>

/*
*
*/
int main(int argc, char** argv) {
   
    int i;
    int j;
    pid_t pid;
    pid = fork();
   
    if (pid < 0) { /// no child is created
       exit(0);
    } else if (pid == 0) { // child's process '      
for(i = 1;i < argc; i++) // for each word in the input
    for (j = 0; j < strlen(argv[i]); j++) // for each letter in each word
      if (islower(argv[i][j])) { // if it is lower case
printf("child prints: %c\n", argv[i][j]); // print it out
fflush(stdout); // forced printing
      }      
    } else {...
$50.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Linux Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats