Be pricese with correct answers hungryBees.cpp (100 Points)…Be pricese with correct answers hungryBees.cpp (100 Points)Overview:There is a farmer who wants honey.There are 4 bee hives that are willing to give honey, but want flowers in return.Thefarmerthread runs a loop that only stops when: honey >= NUM_BEE_HIVES. Until then, the farmer patiently makes another flower with new Flower and gives it to one of the bee hives.Thebee hivethreads collect Flower instances and add them to their own personal PrivateGarden instances. When their PrivateGarden instances have NUM_FLOWERS_TO_COLLECT flowers, then they increment the honey counter for the farmer.Cut-and-paste the following:/*————————————————————————-* *— —* *— hungryBees.cpp —* *— —* *— This file defines a C-ish C program that exercises —* *—knowledge ofPOSIX threads and linked list manipulation.—* *— —* *——- —- —- —- —- —- —- —- —* *— —* *—Version 1a Joseph Phillips —* *— —* *————————————————————————-*///—Header file inclusion:—// #include #include #include #include #include #include //—Definition of constants: —// // PURPOSE: To tell how many flowers each bee hive must visit.const int NUM_FLOWERS_TO_COLLECT = 5;// PURPOSE: To tell the number of bee hives that exist.const int NUM_BEE_HIVES= 4;// PURPOSE: To hold the names of the flowers:const char* FLOWER_NAME_ARRAY[] = { “Jasmine”,”Daffodil”,”Daisy”,”Stinging Nettle”,”Venus fly trap”,”Tumbleweed”,”Kudzu”,”Poison Ivy” };// PURPOSE: To tell how many flower names there are.const size_t NUM_FLOWER_NAMES= sizeof(FLOWER_NAME_ARRAY)/sizeof(const char*);//— Definition of classes and structs: —//// PURPOSE: To represent a flower.class Flower{ // I. Member vars: // PURPOSE: To hold address of the name of the flower as a C-string. const char*nameCPtr_; // PURPOSE: To hold the address of the Flower instance after ‘*this’ one, // or ‘NULL’ if there is no such Flower. Flower*nextPtr_; // II. Disallowed auto-generated methods: // No copy constructor: Flower (const Flower&); // No copy assignment op: Flower&operator= (const Flower&);protected : // III. Protected methods:public : // IV. Constructor(s), assignment op(s), factory(s) and destructor: // PURPOSE: To make ‘*this’ a stand-alone Flower instance with a randomly- // chosen name. No parameters. No return value. Flower () : nameCPtr_(FLOWER_NAME_ARRAY[rand() % NUM_FLOWER_NAMES] ), nextPtr_(NULL) { } // PURPOSE: To release the resources of ‘*this’. No parameters. No // return value. ~Flower() { } // V. Accessors: // PURPOSE: To return the name of the flower. No parameters. const char*getNameCPtr () const { return(nameCPtr_); } // PURPOSE: To return the address of the Flower instance after ‘*this’ one, // or ‘NULL’ if there is no such Flower. Flower* getNextPtr() const { return(nextPtr_); } // VI. Mutators: // PURPOSE: To note that the next flower in the list has address // ‘newNextPtr’. No return value. voidsetNextPtr(Flower* newNextPtr ) { nextPtr_ = newNextPtr; } // VII. Methods that do main and misc work of class:};class PrivateGarden{ // I. Member vars: // YOUR MEMBER VARS HERE // II. Disallowed auto-created methods: // No copy constructor: PrivateGarden (const PrivateGarden&); // No copy assignment op: PrivateGarden& operator= (const PrivateGarden&);protected : // III. Protected methods:public : // IV. Constructor(s), assignment op(s), factory(s) and destructor: // PURPOSE: To initialize ‘*this’ to an empty garden. No parameters. // No return value. PrivateGarden () { // INITIALIZE HERE } // PURPOSE: To release the resources of ‘*this’. No parameters. // No return value. ~PrivateGarden () { // GET RID OF LIST HERE } // V. Accessor(s): // PURPOSE: To hold length of ‘*this’ list. int getNumFlowers() const { return(0); /* CHANGE THAT 0 */} // VI. Mutator(s): // VII. Methods that do main and misc. work of class: // PURPOSE: To add the Flower with address ‘flowerPtr’ at the back of // ‘*this’ PrivateGarden of Flower instances. No return value. voidstore (Flower* flowerPtr ) { // ADD TO LIST HERE } // PURPOSE: To print this list of Flower instances in ‘*this’ PrivateGarden. // No parameters. No return value. voidprint () { // ADD TO LIST HERE } };structHive{ std::stringname_; PrivateGarden*gardenPtr_; Hive() : name_(“”), gardenPtr_(NULL) { } ~Hive () { delete(gardenPtr_); } const char*getNameCPtr () const { return(name_.c_str()); }};//—Definition of global vars: —//// PURPOSE: To hold the address of the flower offered by the farmer.//or to hold ‘NULL’ if there is no such Flower.Flower*availableFlowerPtr= NULL;// PURPOSE: To tell how much honey has been produced by the bee hives.inthoney= 0;// YOUR CODE HERE to add global vars to control access to availableFlowerPtr and honey://—Definition of main functions:—//// PURPOSE: To be the function run by the bee hive threads. ‘vPtr’ points//to an instance of ‘Hive’. Returns ‘NULL’.void* hive (void*vPtr ){ // I. Application validity check: // II. Get the flowers: // II.A. Initialize local vars: Hive*hivePtr= NULL; // CHANGE THAT NULL PrivateGarden* gardenPtr= NULL; // CHANGE THAT NULL // II.B. Each iteration obtains another Flower instance for the graden //of Hive ‘*hivePtr’: while (gardenPtr->getNumFlowers() < NUM_FLOWERS_TO_COLLECT) { // YOUR CODE HERE: Make access to avaialbleFlowerPtr thread-safe while (availableFlowerPtr == NULL) {printf("%s: "Hey! No flowers, no honey!"n",hivePtr->getNameCPtr()); } printf(“%s: “A %s! Sure we will take that!”n”, hivePtr->getNameCPtr(),availableFlowerPtr->getNameCPtr()); gardenPtr->store(availableFlowerPtr); availableFlowerPtr = NULL; // Leave this outside critical section: sleep(rand() % 3); // Please leave this OUT of the critical section } // II.C. Add to the honey when have enough flowers: printf(“%s “Finally, enough flowers to make some honey.”n”,hivePtr->getNameCPtr() ); // YOUR CODE HERE: Make incrementing honey thread-save honey; // III. Finished: return(NULL);}// PURPOSE: To be the function run by the farmer thread. ‘vPtr’ is ignored.//Returns ‘NULL’.void* farmer(void* vPtr){ // I. Application validity check: // II. Give flowers: // II.A. Each iteration creates and gives another Flower instance //until there is sufficient honey: while (true) { // YOUR CODE HERE: Make access to honey thread-safe if (honey >= NUM_BEE_HIVES) {break; } printf(“Farmer: “I have to gather *more* flowers?!?”n”); // YOUR CODE HERE: Make access to availableFlowerPtr thread-safe while (availableFlowerPtr != NULL) {printf(“Farmer: “Hey, you said you wanted”” a flower, come and take it.”n” ); } availableFlowerPtr = new Flower; printf(“Farmer: “Okay here is another flower: a %s”n”, availableFlowerPtr->getNameCPtr()); // Leave this outside critical section: sleep(rand() % 3); // Please leave this OUT of the critical section } // III. Finished: printf(“Farmer “I *finally* got my honey!”n”); return(NULL);}// PURPOSE: To run the program. Ignores command line arguments. Returns//’EXIT_SUCCESS’ to OS.intmain (){ // I. Application validity check: // II. Have the farmer give Flower instances until sufficient honey // has been obtained: // II.A. Randomize random number generator: srand(getpid()); // II.B. Initialize global vars: HivehiveArray[NUM_BEE_HIVES]; // Add something here? // II.C. Make threads: // II.C.1. Make bee hive threads: for (int i = 0; i < NUM_BEE_HIVES; i) { hiveArray[i].name_= std::string("Hive ") (char)('A'); hiveArray[i].gardenPtr_ = new PrivateGarden; // Add something here? } // II.C.2. Make farmer thread: // Add something here? // II.D. Wait for child threads: // II.D.1. Wait for bee hive threads: for (int i = 0; i < NUM_BEE_HIVES; i) { // Add something here? printf("%s has:n",hiveArray[i].getNameCPtr()); hiveArray[i].gardenPtr_->print(); } // II.D.2. Wait for farmer thread: // Add something here? // II.E. Get rid of global vars: // Add something here? // III. Finished: return(EXIT_SUCCESS);}Considering Two Cases Please write program for1rst question )Given a string “aaabbbcc”, compress it, = “a3b3c2” . Given that output string’s length is always smaller than input string, you have do it inplace. No extra space like array should be used.2nd Question)Given a string “aaabbbcc”, compress it, = “3a3b2c” . Given that output string’s length is always smaller than input string, you have do it inplace. No extra space like array should be used.Please write a very simple Java and C program to explain the logic of both the questions . I want to know how to do the program in both C and java . I am not clear with the concepts and getting confused.Hence i beg you please provide me correct program of both the QUESTION and write program in C and JAVA BOTHHelp make 2 programming question that can be done in 10 minutes and the answer cant be searched on google easilyalso provide the answer, test case, and the time limit.the language allowed is C, C, and JAVA.Hello, please help me with my systems assignment using c! The code looks quite long but he adds a lot of fluff, the amount of coding is minimal. Please finish the two “Your Code Here” sections within theserver_getFileByFirstLetter.cprogram. Thank you so much!Purpose:To practice:SocketsLow-level I/O in CProcesses and signallingAssignment:Please finish the server of a client-server application. The client asks the user for a letter (a character in {A-Z,a-z}), and then sends that letter to the server. The server malloc()s memory to store both the loop variable i and the file descriptor from accept() for talking to the client. It then pthread_create()s a child to handle the client and gives it the malloc()ed memory. All of the threadsexceptthe last (i == (NUM_CLIENTS_TO_SERVE-1)) should bedetachedthreads. The last thread should be an ordinary, joinable thread, which the parent thread should join with outside the loop.The child thread should:Get the thread id (coming in as the loop variable) and file descriptor. It then free()s that malloc()ed memory.Gets the letter from the clientAttempts to open the current directory (“.”). If it cannot open that directory then it:sends CANT_READ_DIR_CODE back to the client (in network endian),prints its id and “id num: Cannot read directoryn”,returns NULL.Iterates thru the directory to looking for afile(not a directory or anything else) whose name starts with the letter obtained from the client.If the server finds no matching file then itsends NO_MATCH_CODE back to the client (in network endian),prints its id and “id num: No matching filen”,returns NULL.Attempts to open the file for reading. If it cannot open the file then it:sends CANT_READ_FILE_CODE back to the client (in network endian),prints its id and “id num: Cannot read file n”,returns NULL.Prints its id and “id num: Sending , bytesn”Sends the size of the file as a uint32_t integer to the client (in network endian)Sends the bytes of the file to the client. It should send the file in buffers of bytes of size BUFFER_LEN.close()s what it should close.returns NULL.Code:/*————————————————————————-* *— —* *— getFileByFirstLetter.h —* *— —* *— This file declares constants common to both the client and *—server of an application where the client asks the user for a—* *—letter, and then asks a server for the text of a file that—* *—begins with that letter.—* *— —* *——- —- —- —- —- —- —- —- —* *— —* *—Version 1.02017 May 14Joseph Phillips —* *— —* *————————————————————————-*//*— Header file inclusion —*/#include #include #include #include // For socket()#include // For sockaddr_in and htons()#include// For getaddrinfo()#include// For errno var#include // For open(), read(),write(), stat()#include// and close()#include// For MacOS()/*— Definition of constants: —*/#defineBUFFER_LEN 256#defineNO_MATCH_CODE ((uint32_t) -1)#defineCANT_READ_FILE_CODE ((uint32_t) -2)#defineCANT_READ_DIR_CODE((uint32_t) -3)#defineDEFAULT_HOSTNAME “localhost”/*————————————————————————-* *— —* *— client_getFileByFirstLetter.c —* *— —* *— This file defines a C program that asks the user for a—* *—letter, and then asks a server for the text of a file that—* *—begins with that letter.—* *— —* *——- —- —- —- —- —- —- —- —* *— —* *—Version 1.02017 May 13Joseph Phillips —* *— —* *————————————————————————-*//*— Header file inclusion —*/#include “getFileByFirstLetter.h”#include// isalpha()// PURPOSE: To ask the user for the name and the port of the server. The//server name is returned in ‘url’ up to length ‘urlLen’. The port//number is returned in ‘*portPtr’. No return value.void obtainUrlAndPort (int urlLen,char*url,int* portPtr ){ // I. Application validity check: if ( (url == NULL) || (portPtr == NULL) ) { fprintf(stderr,”BUG: NULL ptr to obtainUrlAndPort()n”); exit(EXIT_FAILURE); } if(urlLen <= 1) { fprintf(stderr,"BUG: Bad string length to obtainUrlAndPort()n"); exit(EXIT_FAILURE); } // II. Get server name and port number: // II.A. Get server name: printf("Machine name [%s]? ",DEFAULT_HOSTNAME); fgets(url,urlLen,stdin); char* cPtr = strchr(url,'n'); if (cPtr != NULL) *cPtr = ''; if (url[0] == '') strncpy(url,DEFAULT_HOSTNAME,urlLen); // II.B. Get port numbe: char buffer[BUFFER_LEN]; printf("Port number? "); fgets(buffer,BUFFER_LEN,stdin); *portPtr = strtol(buffer,NULL,10); // III. Finished:}// PURPOSE: To attempt to connect to the server named 'url' at port 'port'.//Returns file-descriptor of socket if successful, or '-1' otherwise.int attemptToConnectToServer (const char* url, int port){ // I. Application validity check: if (url == NULL) { fprintf(stderr,"BUG: NULL ptr to attemptToConnectToServer()n"); exit(EXIT_FAILURE); } // II. Attempt to connect to server: // II.A. Create a socket: int socketDescriptor = socket(AF_INET, // AF_INET domain SOCK_STREAM, // Reliable TCP 0); // II.B. Ask DNS about 'url': struct addrinfo* hostPtr; int status = getaddrinfo(url,NULL,NULL,&hostPtr); if (status != 0) { fprintf(stderr,gai_strerror(status)); return(-1); } // II.C. Attempt to connect to server: struct sockaddr_in server; // Clear server datastruct memset(&server, 0, sizeof(server)); // Use TCP/IP server.sin_family = AF_INET; // Tell port # in proper network byte order server.sin_port = htons(port); // Copy connectivity info from info on server ("hostPtr") server.sin_addr.s_addr = ((struct sockaddr_in*)hostPtr->ai_addr)->sin_addr.s_addr; status = connect(socketDescriptor,(struct sockaddr*)&server,sizeof(server)); if (status < 0) { fprintf(stderr,"Could not connect %s:%dn",url,port); return(-1); } // III. Finished: return(socketDescriptor);}// PURPOSE: To do the work of the application. Gets letter from user, sends//it to server over file-descriptor 'fd', and either prints text of//returned error code, or prints returned file. No return value.void communicateWithServer(int fd ){ // I. Application validity check: // II. Do work of application: // II.A. Get letter from user: char buffer[BUFFER_LEN]; do { printf("Please enter a letter to look for: "); fgets(buffer,BUFFER_LEN,stdin); } while ( !isalpha(buffer[0]) ); // II.B. Send letter to server: write(fd,buffer,1); // II.C. Get response from server: uint32_tfileSize; read(fd,&fileSize,sizeof(fileSize)); fileSize = ntohl(fileSize); // II.D. Interpret server response: switch (fileSize) { case NO_MATCH_CODE : printf("No matching file found for %cn",buffer[0]); break; case CANT_READ_FILE_CODE : printf("Matching file found for %c, but could not openn",buffer[0]); break; case CANT_READ_DIR_CODE : printf("Server could not open %c.n",buffer[0]); break; default : {unsigned inttotalNumBytesRead = 0;int numBytesRead;printf("The file that matches %c has size %un",buffer[0],fileSize);while ( (totalNumBytesRead < fileSize) && ( (numBytesRead = read(fd,buffer,BUFFER_LEN)) > 0)){ buffer[numBytesRead] = ”; printf(“%s”,buffer); totalNumBytesRead = (unsigned int)numBytesRead;} } } // III. Finished:}// PURPOSE: To do the work of the client. Ignores command line parameters.//Returns ‘EXIT_SUCCESS’ to OS on success or ‘EXIT_FAILURE’ otherwise.int main (){ charurl[BUFFER_LEN]; int port; int fd; obtainUrlAndPort(BUFFER_LEN,url,&port); fd = attemptToConnectToServer(url,port); if (fd < 0) exit(EXIT_FAILURE); communicateWithServer(fd); close(fd); return(EXIT_SUCCESS);}/*-------------------------------------------------------------------------* *--- ---* *--- server_getFileByFirstLetter.c ---* *--- ---* *--- This file defines a C program that waits for a client to ---* *---connect, gets a letter from the client, and looks for a file in ---* *---the current directory that begins with that letter. If it---* *---finds such a file then it sends the length of the file back as ---* *---a network-endian 32-bit unsigned integer, followed by the text ---* *---of the file. Sends back the appropriate error integer code ---* *---otherwise. *--- ---* *------- ---- ---- ---- ---- ---- ---- ---- ---* *--- ---* *---Version 2.02017 May 19Joseph Phillips ---* *--- ---* *-------------------------------------------------------------------------*/////Compile with://$ gcc server_getFileByFirstLetter.c -o server -lpthread///*--- Header file inclusion ---*/#include "getFileByFirstLetter.h"#include // For opendir(), readdir(), closedir()#include// For pthread_create(), etc.const int LO_LEGAL_PORT = 1025;const int HI_LEGAL_PORT = 65535;const int ERROR_FD= -1;const int NUM_CLIENTS_TO_SERVE = 4;// PURPOSE: To attempt to create and return a file-descriptor for listening//to the OS telling this server when a client process has connect()-ed//to 'port'. Returns that file-descriptor, or 'ERROR_FD' on failure.intgetServerFileDescriptor (int port,const char* progName ){ // I. Application validity check: if (progName == NULL) { fprintf(stderr,"BUG: NULL ptr to getServerFileDescriptor().n"); exit(EXIT_FAILURE); } // II. Attempt to get socket file descriptor and bind it to 'port': // II.A. Create a socket int socketDescriptor = socket(AF_INET, // AF_INET domain SOCK_STREAM, // Reliable TCP 0); if (socketDescriptor < 0) { perror(progName); return(ERROR_FD); } // II.B. Attempt to bind 'socketDescriptor' to 'port': // II.B.1. We'll fill in this datastruct struct sockaddr_in socketInfo; // II.B.2. Fill socketInfo with 0's memset(&socketInfo,'',sizeof(socketInfo)); // II.B.3. Use TCP/IP: socketInfo.sin_family = AF_INET; // II.B.4. Tell port in network endian with htons() socketInfo.sin_port = htons(port); // II.B.5. Allow machine to connect to this service socketInfo.sin_addr.s_addr = INADDR_ANY; // II.B.6. Try to bind socket with port and other specifications int status = bind(socketDescriptor, // from socket()(struct sockaddr*)&socketInfo,sizeof(socketInfo)); if (status < 0) { perror(progName); return(ERROR_FD); } // II.B.6. Set OS queue length: listen(socketDescriptor,5); // III. Finished: return(socketDescriptor);}// PURPOSE: To ask the user which port to attempt to monopolize, and to return//entered port number.intgetPort(){ // I. Application validity check: // II. Get port number intport; do { char buffer[BUFFER_LEN]; printf("Please enter port number to monopolize [%d-%d]: ", LO_LEGAL_PORT,HI_LEGAL_PORT); fgets(buffer,BUFFER_LEN,stdin); port = strtol(buffer,NULL,10); } while ( (port < LO_LEGAL_PORT) || (port > HI_LEGAL_PORT) ); // III. Finished: return(port);}// PURPOSE: To do the work of handling the client. Communication with the//client take place using file-descriptor pointed to by ‘*vPtr’. Returns//’NULL’.void* handleClient (void* vPtr ){ // I. Application validity check: // II. Handle the client: // YOUR CODE HERE // III. Finished: return(NULL);}// PURPOSE: To serve the clients using file-descriptor ‘listenFd’ to tell//when a client has connected. Each client is handled by its own child//process. Both the parent and the child processes close unnecesary//file-descriptorors. Serves ‘NUM_CLIENTS_TO_SERVE’ clients, then quits.//No return value.void doServer (int listenFd ){ // I. Application validity check: if (listenFd < 0) { fprintf(stderr,"Illegal file-descriptor to doServer()n"); exit(EXIT_FAILURE); } // II. Do the work of the server: inti; pthread_ttId; pthread_attr_t tAttr; pthread_attr_init(&tAttr); pthread_attr_setdetachstate(&tAttr,PTHREAD_CREATE_DETACHED); for (i = 0; i < NUM_CLIENTS_TO_SERVE; i) { // YOUR CODE HERE } pthread_join(tId,NULL); pthread_attr_destroy(&tAttr); // III. Finished:}// PURPOSE: To oversee the main work of the server. Ignores 'argc' but//uses 'argv[0]' as the name of the program. Returns 'EXIT_SUCCESS' to//OS on success or 'EXIT_FAILURE' otherwise.intmain (int argc,char*argv[] ){Computer Science Engineering & Technology C Programming COMPUTER S CYB113

Order your essay today and save 20% with the discount code ESSAYHELP