Logic game Weaver's Island using C programming

Closed
datrainbow
Posts
1
Registration date
Tuesday July 26, 2016
Status
Member
Last seen
July 26, 2016
- Jul 26, 2016 at 01:30 AM
Ambucias
Posts
47363
Registration date
Monday February 1, 2010
Status
Moderator
Last seen
September 1, 2021
- Jul 26, 2016 at 06:37 AM
Hello everyone,
I'm currently studying computer engineering and about to finish my first semester, anyway, my teacher for C is terrible and has no idea how to explain programming at all and suddenly gives us this impossible assignment that I have no idea how to write since we barely saw arrays and functions, if somebody would be so kind and help me with this code I'd love you for the eternity. Here's the assignment (I attached the final program as an image)

For your second assignment this semester, you are required to write
a program for a logic game called "Weaver's Island".
The object of the game is transport "cargo" (Monkeys, Coconuts, and
Alligators) from a land port to an island.
In order to "transport" the cargo, you will need a "ship" (a character array)
that allows you to "transport" only 1 item at a time.
:

However, the game has the following rules:
1. Only 1 type of cargo can be transported at a time.

2. The Monkeys cannot be left alone with the Alligators
because the Alligators will eat the Monkeys.

3. The Monkeys cannot be left alone with the Coconuts, because
the Monkeys will eat the Coconuts.
In order to complete this assignment, you will be required
to complete the code for the following functions that make use of
characters strings.
Recall:
A string is a character array that is terminated with the null byte '\0'.
Also, you may make use of any of the <string.h> library
functions you wish (for example, strlen( )).

void loadCargo(char ship[ ], char land[ ], char type);
void transportCargo(char ship[ ], char destination[ ], int dir);

void loadCargo(char ship[ ], char land[ ], char type);
This function copies all of the characters that match the character
'type' from the 'land' string into the 'ship' array.
Once all of the characters have been copied into the ship array,
you must terminate the array with the null byte in order to make
it a proper string.
Also, after each character is copied from the 'land' string it MUST
be changed to lowercase (i.e. 'C' to 'c', 'M' to 'm', etc).
An uppercase character can be changed to lowercase by adding 32
to the uppercase character.

void transportCargo(char ship[ ], char destination[ ], int dir);
This function can be used to copy characters from the 'ship' string
into the 'destination' string (either the 'land' or the 'island').
If the integer value 'dir' is 1, this function copies all of the
characters in the 'ship' string to the end of the 'destination' string
(from ship to island).

If the integer value 'dir' is 0, then this function copies each
character in the 'ship' string that matches its lowercase equivalent
in the 'destination' string (replacing the lowercase equivalent in the
'destination' string) (from ship back to land).

NOTE: If copying characters from the ship to the island, don't forget
to add the null byte at the end into the destination array.


OUTPUT:
-----------------
The following program (once you have coded and called the functions
properly):

#include <stdio.h>
#include <string.h>

void loadCargo(char ship[ ], char land[ ], char type);
void transportCargo(char ship[ ], char destination[ ], int dir);

void printRegion(char region[ ], int dir);

int main( ) {
char land[121] = "CCCCCCCCAAAAAAAAAAAAAAAAAAAAAMMMMM";
char island[121] = "";
char ship[121] = "";
int i;

/*
YOUR CODE HERE...
YOUR CODE HERE...
  • /


printRegion(land, 1);
printRegion(island, 0);
return 0;
}

void loadCargo(char ship[ ], char land[ ], char type) {
/* YOUR CODE HERE... */
}
void transportCargo(char ship[ ], char destination[ ], int dir) {
/* YOUR CODE HERE... */
}

void printRegion(char region[ ], int dir) {
int i;
printf("%s: ", dir == 1 ? "LAND" : "ISLAND");
for(i=0; region[i] != '\0'; i++) {
printf("%c", region[i]);
}
printf("\n");
}

would display:
LAND: ccccccccaaaaaaaaaaaaaaaaaaaaammmmm
ISLAND: mmmmmAAAAAAAAAAAAAAAAAAAAACCCCCCCCMMMMM

NOTE: the lowercase letters in the 'land' string indicate that
they have all been moved, and the uppercase letters indicate
that they have been added.


SUBMITTING YOUR ASSIGNMENT:
---------------------------
Test your program on the C platforms that your instructor has
specified. For submission purposes, your program must work
on DevC++ version 5.11. For detailed submission requirements
follow your instructor's assignment submission guidelines.

1 reply

Ambucias
Posts
47363
Registration date
Monday February 1, 2010
Status
Moderator
Last seen
September 1, 2021
11,281
Jul 26, 2016 at 06:37 AM
Sorry but CCM does not provide help in studies, you must earn your own grades.
2