Question

IrmaMoves.h : #include "IrmaMoves.h" typedef struct Move { Irma irma;            // an instance of Irma L...

IrmaMoves.h :

#include "IrmaMoves.h"

typedef struct Move {

Irma irma;            // an instance of Irma

L Location from_loc; // location where Irma is moving from

Location current_loc; // location where Irma is passing over

Location to_loc; // location where Irma is moving to

} Move;

typedef struct Location {

char col; // the square's column ('a' through 'h')

int row; // the square's row (0 through 7)

} Location;

typedef struct Irma {

int ws; // wind speed (MPH)

int wg; // wind gusts (MPH)

} Irma;

IrmaMoves.c:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "IrmaMoves.h"

char **createMapBoard(void){
    char **board = malloc(8*sizeof(char *)); //dynamically allocate memory for rows

    for(int i = 0 ; i < 8 ; i++) //dynamically allocate memory for indiviual elements
        board[i] = malloc( 8*sizeof(char) );

    board[0][0] = 'F'; //initialize the array with the map layout
    board[0][1] = 'F';
    board[0][2] = ' ';
    board[0][3] = ' ';
    board[0][4] = ' ';
    board[0][5] = ' ';
    board[0][6] = ' ';
    board[0][7] = ' ';
    board[1][0] = ' ';
    board[1][1] = 'F';
    board[1][2] = ' ';
    board[1][3] = ' ';
    board[1][4] = ' ';
    board[1][5] = ' ';
    board[1][6] = ' ';
    board[1][7] = ' ';
    board[2][0] = ' ';
    board[2][1] = 'F';
    board[2][2] = 'F';
    board[2][3] = ' ';
    board[2][4] = ' ';
    board[2][5] = ' ';
    board[2][6] = ' ';
    board[2][7] = ' ';
    board[3][0] = ' ';
    board[3][1] = ' ';
    board[3][2] = 'F';
    board[3][3] = ' ';
    board[3][4] = ' ';
    board[3][5] = ' ';
    board[3][6] = ' ';
    board[3][7] = ' ';
    board[4][0] = ' ';
    board[4][1] = ' ';
    board[4][2] = 'K';
    board[4][3] = ' ';
    board[4][4] = ' ';
    board[4][5] = ' ';
    board[4][6] = ' ';
    board[4][7] = ' ';
    board[5][0] = 'C';
    board[5][1] = ' ';
    board[5][2] = ' ';
    board[5][3] = 'B';
    board[5][4] = ' ';
    board[5][5] = ' ';
    board[5][6] = ' ';
    board[5][7] = ' ';
    board[6][0] = ' ';
    board[6][1] = 'C';
    board[6][2] = 'C';
    board[6][3] = ' ';
    board[6][4] = 'D';
    board[6][5] = ' ';
    board[6][6] = ' ';
    board[6][7] = ' ';
    board[7][0] = ' ';
    board[7][1] = ' ';
    board[7][2] = 'C';
    board[7][3] = ' ';
    board[7][4] = ' ';
    board[7][5] = 'D';
    board[7][6] = 'D';
    board[7][7] = ' ';

    return board;
};


char **destroyMapBoard(char **board){
    //frees up the memory allocated to the board
    free(board);
    return NULL;
};

void printMapBoard(char **board){
    //printing the map in the specified format
    printf("========\n");
    for (int i = 0; i < 8; i++){
        for (int j = 0; j < 8; j++){
            printf("%c",board[i][j]);}
        printf("\n");}
    printf("========");
    printf("\n");
    printf("\n");
};

Problems:

char **predictIrmaChange (char* str, Move *irmaMove);

Description: This function should start by printing the map board with Irma in its starting position, using the arrangement described in “Appendix A: Irma Movement” and the specific format shown in the test case output files included with this assignment. (You will want to call createMapBoard() from within this function to create a 2D char array to represent the map board, and then call the printMapBoard() function to print it to the screen. See above for the descriptions of both of those functions.)

After printing the initial map board, this function should parse all of the algebraic notation strings passed in through making calls to the parseNotationString() function (described below). The printMapBoard() function is called once after the Irma’s location has been identified, and another time after the board’s final configuration has been processed. Note that this function should print the resulting board (again, with a line of eight equal signs above and below the board each time, always followed by a blank line).

In addition, updating Irma’s wind speed/gusts and checking Irma directions should be
======== FF    F FF   F   K C B CC D    C DD   ========
← Note: This is a completely blank line. (No spaces.)
implemented in this function as described in “Appendix A: Irma Movement”.

Output: This should print out the map board in the manner described above, with precisely the same format shown in the test case output files included with this assignment.
Return Value: A pointer to the dynamically allocated 2D array (i.e., the base address of the 2D array), or NULL if any calls to malloc() fail.

void parseNotationString(char* str, Move* irmaMove);

Description: This function receives an algebraic notation string, str, and one Move struct pointer. The function must parse str and extract information about Irma moves encoded there, and populate all corresponding fields in the struct pointed to by irmaMove.

At the very least, it will always be possible to set the from_loc, current_loc, to_loc, and irma.ws, irma.wg fields in Irma struct. It is necessary to denote which column and/or row the Irma’s move is coming from, and also the column and/or row in a move’s to_loc field which determine where Irma ends. To initialize from_loc, current_loc, to_loc   fields, you must initialize that move’s from/current/to_loc.col fields to ‘x’ to indicate that the column is currently unknown. Similarly, the move’s from/current/to_loc.row coordinate must be initialized to -1.

After initialization, update from_loc, current_loc, to_loc, and irma.ws, irma.wg fields through extracting information from given algebraic notation string.


Output: This function should not print anything to the screen.
Return Value: There is no return value. This is a void function.

double difficultyRating(void);

Output: This function should not print anything to the screen.
Return Value: A double indicating how difficult you found this assignment on a scale of 1.0 (ridiculously easy) through 5.0 (insanely difficult).

double hoursSpent(void);

Output: This function should not print anything to the screen.
Return Value: An estimate (greater than zero) of the number of hours you spent on this assignment.

Above is the Header file for IrmaMoves and the beginning of IrmaMoves.c. I bolded the functions that I am unsure of how to do.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

void printMapBoard(char **board){
    //printing the map in the specified format
    printf("========\n");
    for (int i = 0; i < 8; i++){
        for (int j = 0; j < 8; j++){
            printf("%c",board[i][j]);}
        printf("\n");}
    printf("========");
    printf("\n");
    printf("\n");
};

} Move;

typedef struct Location {

char col; // the square's column ('a' through 'h')

int row; // the square's row (0 through 7)

} Location;

typedef struct Irma {

int ws; // wind speed (MPH)

int wg; // wind gusts (MPH)

} Irma;

IrmaMoves.c:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "IrmaMoves.h"

char **board = malloc(8*sizeof(char *)); //dynamically allocate memory for rows

    for(int i = 0 ; i < 8 ; i++) //dynamically allocate memory for indiviual elements
        board[i] = malloc( 8*sizeof(char) );

}

Add a comment
Know the answer?
Add Answer to:
IrmaMoves.h : #include "IrmaMoves.h" typedef struct Move { Irma irma;            // an instance of Irma L...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include <stdio.h> #include <stdlib.h> #include <string.h> struct game_piece { ...

    #include <stdio.h> #include <stdlib.h> #include <string.h> struct game_piece { }; struct game_board { }; void game_piece_init_default(struct game_piece* piece) { } void game_piece_init(struct game_piece* piece, char* new_label) { } char* game_piece_get_label(struct game_piece* piece) { return ""; } char* game_piece_to_string(struct game_piece* piece) { return ""; } void game_board_init(struct game_board* game_board, int rows, int cols) { } int game_board_is_space_valid(struct game_board* game_board, int row, int col) { return 0; } int game_board_add_piece(struct game_board* game_board, struct game_piece* piece, int row, int col) { return 0;...

  • PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int...

    PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int x, y; int h, w; } box; typedef struct { unsigned int baud : 5; unsigned int div2 : 1; unsigned int use_external_clock : 1; } flags; int main(int argc, char** argv){ printf("The size of box is %d bytes\n", sizeof(box)); printf("The size of flags is %d bytes\n", sizeof(flags)); return 0; } 2. #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned...

  • IN C Programming #include<stdio.h> #include<stdlib.h> typedef struct nodestruct { int item; struct nodestruct *next; } Node;...

    IN C Programming #include<stdio.h> #include<stdlib.h> typedef struct nodestruct { int item; struct nodestruct *next; } Node; typedef struct { int size; // Number of items on user’s list Node *head, *tail; } List; //In addition to creating an empty list, this function will also create two dummy nodes; one for the head, and the other for the tail. List* createList(); //This function creates a node containing the provided item, then inserts it into the list pointed by the provided list...

  • IN C PROGRAMMING. PLEASE INCLUDE COMMENTS #include #include #include typedef struct Contact_struct { char myName[20]; //name...

    IN C PROGRAMMING. PLEASE INCLUDE COMMENTS #include #include #include typedef struct Contact_struct { char myName[20]; //name of this Contact int numGoals; struct Contact_struct* next; //pointer to the next Contact } Contact; //Contact Constructor void Contact_Create(Contact* thisContact, char thisName[], int thisGoals, Contact* nextContact) { strcpy(thisContact->myName,thisName); thisContact->numGoals = thisGoals; thisContact->next = nextContact; } void Contact_PrintList(Contact* headContact){ Contact* currContact = headContact; while (currContact != NULL){ printf("%s has scored %d goals\n",currContact->myName, currContact->numGoals); currContact = currContact->next; } } int Contact_SumGoals(Contact* headContact){ //Develop Functionality for Contact_SumGoals...

  • Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */...

    Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */ struct myWord{    char Word[21];    int Length; }; int tokenizeLine(char line[], struct myWord wordList[]); void printList(struct myWord wordList[], int size); void sortList(struct myWord wordList[], int size); /** * main function */ int main() {    struct myWord wordList[20];    char line[100];    printf("Enter an English Sentence:\n");    gets(line);    int size = tokenizeLine(line, wordList);    printf("\n");    printf("Unsorted word list.\n");    printList(wordList, size);...

  • OPERATING SYSTWM Question 31 What is the output of this C program? #include #include void main()...

    OPERATING SYSTWM Question 31 What is the output of this C program? #include #include void main() int mptr, *cptr mptr = (int*)malloc(sizeof(int)); printf("%d", "mptr); cptr = (int)calloc(sizeof(int),1); printf("%d","cptr); garbage 0 000 O garbage segmentation fault Question 8 1 pts If this program "Hello" is run from the command line as "Hello 12 3" what is the output? (char '1'is ascii value 49. char '2' is ascii value 50 char'3' is ascii value 51): #include<stdio.h> int main (int argc, char*argv[]) int...

  • The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() {    char board[...

    The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() {    char board[SIZE];    int player, choice, win, count;    char mark;    count = 0; // number of boxes marked till now    initBoard(board);       // start the game    player = 1; // default player    mark = 'X'; // default mark    do {        displayBoard(board);        cout << "Player " << player << "(" << mark...

  • How can I integrate these programs into this menu template: #define _CRT_SECURE_NO_WARNINGS #include #include #include #include...

    How can I integrate these programs into this menu template: #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include void program_one (); void program_two (); void program_three (); void program_four(); void program_five(); int main() { int menu_option = 0; while (menu_option != 9) { printf(" = 1\n"); //Change this to your first program name. Nothing else. printf(" = 2\n"); //Change this to your second program name. Nothing else. printf(" = 3\n"); //Change this to your third program name. Nothing else. printf(" =...

  • If void * is a pointer to void is a "generic" pointer type, and a void...

    If void * is a pointer to void is a "generic" pointer type, and a void * can be converted to any other pointer type * without an explicit cast, why in the ,myarrcopy function the malloc is created like char and not like void? if we are going to work with different type of arrays? Here is de program: *This is a function that make a copy of any given array. * We then use this function make a...

  • #include <stdio.h> #include <stdlib.h> #include <strings.h> #include <unistd.h> #include <pthread.h> pthread_mutex_t mtx; // used by each...

    #include <stdio.h> #include <stdlib.h> #include <strings.h> #include <unistd.h> #include <pthread.h> pthread_mutex_t mtx; // used by each of the three threads to prevent other threads from accessing global_sum during their additions int global_sum = 0; typedef struct{ char* word; char* filename; }MyStruct; void *count(void*str) { MyStruct *struc; struc = (MyStruct*)str; const char *myfile = struc->filename; FILE *f; int count=0, j; char buf[50], read[100]; // myfile[strlen(myfile)-1]='\0'; if(!(f=fopen(myfile,"rt"))){ printf("Wrong file name"); } else printf("File opened successfully\n"); for(j=0; fgets(read, 10, f)!=NULL; j++){ if (strcmp(read[j],struc->word)==0)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT