Complete C code

Description

The purpose of this assignment is to practice your coding in C, using basic constructs such as loops,arrays, and strings. As well, you will be using several functions from the C standard library, which will give you the opportunity to explore the Standard C Library.

Don't use plagiarized sources. Get Your Custom Assignment on
Complete C code
From as Little as $13/Page

Unformatted Attachment Preview

Assignment
The purpose of this assignment is to practice your coding in C, using basic constructs such as loops,
arrays, and strings. As well, you will be using several functions from the C standard library, which will
give you the opportunity to explore the Standard C Library.
This assignment is divided into three problems, where each problem builds on the next. Each problem
subsumes the previous one. Hence, if you complete Problem 3, you will have also completed Problem 2
and Problem 1.
Preparation:
1. Complete Assignment 0 or ensure that the tools you would need to complete it are installed.
2. Inside the repository there is a scrabble directory, in which the code is to be written. Inside
this directory there is a tests directory that contains tests that will be executed each time you
submit your code. Please do not modify the tests directory or the .gitlab-ci.yml file
that is found in the root directory. Modifying these files may break the tests. These files will be
replaced with originals when the assignments are graded. You are provided with a sample
Makefile that can be used to build your program. If you are using CLion, a Makefile will
be generated from the CMakeLists.txt file generated
by CLion.
Background
Scrabble1 is a well know board game, where players take
turns placing words on a grid created from letter tiles. The
first word is placed in the middle of the board and then
each following word must connect to an existing word on
the board. Each word is scored by adding up the points.
One of the challenges in playing Scrabble is determining
where the next word can be placed so that it is connected
to the other words. To simplify the problem, we will only
consider connected words that cross each other as shown in Figure 1. I.e., two words are
connected if they share exactly one letter and are perpendicular. In Scrabble,
words can be placed left to right and top to bottom.
1
Scrabble is published by Hasbro, https://en.wikipedia.org/wiki/Scrabble)
Fig 1: Connected words.
You have been hired to help Scrabble Players figure out where to place words on the board.
Problem 1: Setup
Write a C program called scrabble, which reads in a list of words and their location on the board,
places them to the board, and then displays the board.
Input
Your program will read its input from stdin. The remainder of the input consists of several lines:
• The first line contains a single integer (N) denoting the size of the board (N´ N).
• The second line contains a second integer (W) denoting the number of words to place.
• This is followed by W lines, each containing the location (X,Y), direction (D), and the word (S).
X Y D S where
X is an integer in the range 0 £ X < N, denoting the X coordinate of the first letter of the word Y is an integer in the range 0 £ Y < N, denoting the Y coordinate of the first letter of the word D is either H or V, denoting the direction of the word. H for horizontal (left to right) and V for vertical (top to bottom). S is a single lower-case word which will be two or more letters. • Finally, there is another integer (F), which for this problem will always be 0. All words will be in lower-case letters. (Hint: Use scanf to read the input). See example below. Processing The program should use a 2D array to represent an (N´ N) scrabble and add the words to this board. • To allocate a 2D array of characters use the declaration: char board[n][n]; in the main() function after your program has read in the value for N and stored it in variable n. • The top-left corner of the board has coordinate (0,0) and the bottom right corner is (N-1,N-1). • Empty spaces are represented by periods (.). Hint: initialize all board elements to ‘.’ before placing any words. • Horizontal words are placed left to right and vertical words placed top to bottom. • All words will be correctly placed. Output All output should be performed to stdout. The output must be exactly as specified. The output should consist of an N´ N block of characters representing a Scrabble board with the word placed on it. The topleft corner of the board is location (0,0) and the bottom right corner is (N-1,N-1). All words should be in lower case. Examples Input 10 4 2 3 H hello 3 2 V hello 6 2 V howdy 5 6 H bye 0 Problem 2: Mistakes Were Made Output .......... .......... ...h..h... ..hello... ...l..w... ...l..d... ...o.bye.. .......... .......... .......... Extend your scrabble program from Problem 1 to handle one change. The list may include words that cannot be legally placed. All words that cannot be placed should be identified and not added to the board. Input The input format is the same as in Problem 1. Processing Same as problem 1, except that words that cannot be legally placed should be identified and not placed on the board. A word cannot be legally placed if one or more of the following conditions hold. • if the word extends past the edge of the board • If the word does not cross one or more other words, except in the case of the first word to be placed. • If there is a letter mismatch at a crossing-point of two words. I.e., the letter at the crossing point of the word to be placed is not the same as the letter of crossing point of the already placed word. If the word can be legally placed, it is added to the board. Otherwise, the program should identify the illegal word. The program then prints out the board, just like in Problem 1. Output As the words are being placed, identify each illegal word by outputting the following: Invalid word placement: (X,Y) D, S where X, Y, D, and S, are as described in the Input section of Problem 1. Lastly, output the game board as in Problem 1. Examples Input 1 10 3 2 3 H hello 3 0 V bye 3 4 V eyb 0 Output 1 Invalid word placement: (3,0) V, bye Invalid word placement: (3,4) V, eyb .......... .......... .......... ..hello... .......... .......... .......... .......... .......... .......... Input 2 10 4 2 3 H hello 2 2 V hello 3 2 V hello 0 4 H hello 0 Output 2 Invalid word placement: (2,2) V, hello .......... .......... ...h...... ..hello... hello..... ...l...... ...o...... .......... .......... .......... Problem 3: Finding Places! Extend your scrabble from Problem 2 to handle one more change. The purpose of your program is to help players find where to place their words. A player typically looks for a specific letter on the board around which they can build a word. Given a letter (L) and the number of letters that come before (B) and after (A) the given letter, your program will need to find all places on the board where the word can be placed such that the letter L is already on the board and either there are A free spaces above the letter and B free spaces below the letter, or there are A free spaces to the left of the letter and B free spaces to the right of the letter. Input The input format is the same as in Problem 1. Except that, the last integer (F), after the list of words to be placed, is positive and represents the number of searches to perform. After the integer F, there are F lines, with each line containing a single query. The query is of the form BLA where B is an integer denoting the number of blank spaces that the word needs before the letter L is a lower-case letter A is an integer denoting the number of blank spaces that the word needs after the letter Processing Same as problem 2, except that after the game board is displayed, your program will need to output for each query all places that would satisfy the query. The query can be satisfied at location (X,Y) on the game board if • Letter L is located at (X,Y) • The word can be placed vertically or horizontally at this location o Vertically: there are B free spaces above (X,Y) and A free spaces below (X,Y) o Horizontally: there are B free spaces left of (X,Y) and A free spaces right of (X,Y) • The word can fully fit on the board The locations satisfying the query should be ordered by Y and then X coordinates. I.e., Suppose a word can be placed at (x1,y1) and (x2,y2). If (y1 < y2) or (y1 = y2, and x1 < y2) then location (x1,y1) should come before location (x2,y2). Output The output for this problem consists of the output for Problem 2, followed by the results for each of the queries described above. For each location where a query can be satisfied output a line of the form: Place D at (X,Y) where D is the word horizontally or vertically depending on whether the word should be placed vertically or horizontally, and (X,Y) is the location of the letter L on the board. Examples 5 2 2 V hello 3 1 V hello 2 2 H hello 2 6 H olleh 6 2 V olleh 3 2 o 3 2 h 3 2 e 3 Input Output Invalid word placement: (3,1) V, hello .......... .......... ..hello... ..e...l... ..l...l... ..l...e... ..olleh... .......... .......... .......... Place vertically at (3,2) Place horizontally at (2,3) Place horizontally at (6,5) Place vertically at (5,6) Grading If your program does not compile, it is considered non-functional and of extremely poor quality, meaning you will receive 0 for the solution. The assignment will be graded based on three criteria: Functionality: “Does it work according to specifications?”. This is determined in an automated fashion by running your program on inputs and ensuring that the outputs match the expected outputs. The score is determined based on the number of tests that your program passes. So, if your program passes t/T tests, you will receive that proportion of the marks. Quality of Solution: “Is it a good solution?” This considers whether the approach and algorithm in your solution is correct. This is determined by visual inspection of the code. It is possible to get a good grade on this part even if you have bugs that cause your code to fail some of the tests. Code Clarity: “Is it well written?” This considers whether the solution is properly formatted, well documented, and follows coding style guidelines. A single overall mark will be assigned for clarity. Please see the Style Guide in the Assignment section of the course in Brightspace. The following grading scheme will be used: Task Functionality (20 marks) Problem 1 Solution Quality (10 marks) Problem 1 Solution Quality (5 marks) Problem 3 Solution Quality (5 marks) Code Clarity (10 marks) Indentation, formatting, naming, comments 100% 80% 60% 40% 20% Equal to the number of tests passed. Appropriate approach used. No apparent bugs. Code is robust. Appropriate approach used. No apparent bugs. Code is robust. Appropriate approach used. No apparent bugs. Code is robust. Code looks professional and follows all style guidelines Appropriate approach used. Minor bugs in implementation. Code is robust. Appropriate approach used. Minor bugs in implementation. Code is robust. Appropriate approach used. Minor bugs in implementation. Code is robust. Code looks good and mostly follows style guidelines. Appropriate Appropriate approach used. approach for Major bugs present. used. Reasonable attempt has been made. Appropriate Appropriate approach used. approach for Major bugs present. used. Reasonable attempt has been made. Appropriate Appropriate approach used. approach for Major bugs present. used. Reasonable attempt has been made. Code is mostly readable and mostly follows some of the style guidelines Code is hard to Code is not read and follows legible few of the style guidelines. Hints and Suggestions • • • • Start early. The sample solution is under 120 lines of code, but if this is your first time coding in C, it will take a little longer. It took me about under an hour to write the solution, so expect at least 5 – 8 hours of work, if you do not have a lot of experience with C. Create a 2D char array in your main function to store the board. The Standard Library functions I found most useful are: scanf(), printf(), strlen(), and possibly memset(). For this assignment, I implemented everything inside the main() function because passing 2D arrays to other functions can be a little tricky in C. Assignment Testing without Submission Testing via submission can take some time, especially if the server is loaded. You can run the tests without submitting your code by using the provided runtests.sh script. Running the script with no arguments will run all the tests. Running the script with the test number, i.e., 00, 01, 02, 03, … 29, will run that specific test. Please see below for how run the script. Get your program ready to run If you are developing directly on the unix server, 1. SSH into the remote server and be sure you are in the scrabble directory. 2. Be sure the program is compiled by running make. 0% If you are using CLion 1. Run your program on the remote server as described in the CLion tutorials. 2. Open a remote host terminal via Tools → Open Remote Host Terminal If you are using VSCode 1. Run your program on the remote server as described in VSCode tutorials. 2. Click on the Terminal pane in the bottom half of the window or via Terminal → New Terminal Run the script 3. Run the script in the terminal by using the command: ./runtest.sh to run all the tests, or specify the test number to run a specific test, e.g. : ./runtest.sh 07 You will see the test run in the terminal window. Purchase answer to see full attachment