Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Treat the arguments (excluding argv[0]) as given: make no attempt to process or otherwise normalize the strings before sorting. Note that your shell will perform some manipulation on your input before...

1 answer below »

Treat the arguments (excluding argv[0]) as given: make no attempt to process or otherwise
normalize the strings before sorting. Note that your shell will perform some manipulation on you
input before passing the strings to your program, and most punctuation marks have special meanings:
use escape sequences and/or quotation marks to avoid this.
Usage
$ ./sorta foo bar baz quuz
a
az
foo
quux
$ ./sorta aaa aAa AaA AAA
AAA
AaA
aAa
aaa
$ ./sorta XXXXXXXXXX
100
20
3
$ ./sorta " z" a
z
a
1.3 sudoku: Checking Sudoku solutions
Write a program sudoku that (part 1) checks whether a proposed Sudoku solution is co
ect and (part
2) checks whether a partially-solved Sudoku puzzle with one unknown square can be solved. sudoku
takes a single argument, which is the path to a file containing a completed or almost-completed
Sudoku puzzle.
A completed Sudoku puzzle is a 9× 9 matrix containing the digits 1–9, inclusive. The matrix is
divided into nine 3× 3 submatrixes, themselves a
anged in a 3× 3 square. A completed Sudoku
puzzle is a co
ect solution if and only if it has the following properties:
• Each digit occurs exactly once in each row (that is, no row contains any digit more than once.
• Each digit occurs exactly once in each column.
• Each digit occurs exactly once in each submatrix.
3
For example, this completed puzzle is a co
ect solution:
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX

An almost-completed Sudoku puzzle is similar, except that one or two elements are unspecified.
This portion of the assignment has two parts. For full credit, your program must co
ectly handle
oth parts. You will receive half credit if your program handles one part but not both.
Part 1 sudoku will be given a completed Sudoku puzzle, determine whether the solution is co
ect,
and print either co
ect or inco
ect.
Part 2 sudoku will be given an almost-complete Sudoku puzzle, determine whether the partial
solution can be solved, and print either solvable or unsolvable.
1.3.1 Co
ectness checking
The input file contains a completed Sudoku puzzle. The puzzle is given on nine lines, each of which
contains nine digits without any separation. Note that the digit 0 will not occur. The input file
file1.txt co
esponding to the puzzle above would contain:
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
When given such a file, sudoku must determine whether the completed puzzle is a co
ect solution
(meaning it satisfies the three properties). If so, it prints co
ect. Otherwise, it prints inco
ect.
If the input file does not exist, is not readable, or does not follow the format specified here,
sudoku may print e
or.
Usage
$ ./sudoku file1.txt
co
ect
4
1.3.2 Solvability checking
The input file contains an almost-completed Sudoku puzzle. The format is the same as above—nine
lines with nine characters each—except that up to two of the characters may be spaces instead of
digits. The spaces indicate that the digit for that element is unspecified.
The input file file2.txt contains an almost-completed puzzle with two unknown entries:
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
If the input file contains an almost-completed puzzle, sudoku must determine whether the puzzle
can be solved. If the puzzle has unspecified entries, can they be replaced by a digits such that
the completed puzzle is a co
ect solution? If so, sudoku prints solvable. Otherwise, it prints
unsolvable. If the puzzle contains no unspecified entries (that is, it is a completed puzzle), sudoku
will print co
ect or inco
ect as before.
If the input file does not exist, is not readable, does not follow the format specified above, o
contains more than two unspecified elements, sudoku may print e
or.
Usage
$ ./sudoku file2.txt
solvable
1.4 list: Linked lists
Write a program list that maintains and manipulates a sorted linked list according to instructions
eceived from standard input. The linked list is maintained in order, meaning that the items in the
list are stored in increasing numeric order after every operation.
Note that list will need to allocate space for new nodes as they are created, using malloc; any
allocated space should be deallocated using free as soon as it is no longer needed.
Note also that the list will not contain duplicate values.
list supports two operations:
insert n Adds an integer n to the list. If n is already present in the list, it does nothing. The
instruction format is an i followed by a space and an integer n.
delete n Removes an integer n from the list. If n is not present in the list, it does nothing. The
instruction format is a d followed by a space and an integer n.
After each command, list will print the length of the list followed by the contents of the list, in
order from first (least) to last (greatest).
list must halt once it reaches the end of standard input.
5
Input format Each line of the input contains an instruction. Each line begins with a letter (eithe
“i” or “d”), followed by a space, and then an integer. A line beginning with “i” indicates that the
integer should be inserted into the list. A line beginning with “d” indicates that the integer should
e deleted from the list.
Your program will not be tested with invalid input. You may choose to have list terminate in
esponse to invalid input.
Output format After performing each instruction, list will print a single line of text containing
the length of the list, a colon, and the elements of the list in order, all separated by spaces.
Usage Because list reads from standard input, you may test it by entering inputs line by line
from the terminal.
$ ./list
i 5
1 : 5
d 3
1 : 5
i 3
2 : 3 5
i 500
3 : XXXXXXXXXX
d 5
2 : 3 500
^D
To terminate your session, type Control-D at the beginning of the line. (This is indicated here by
the sequence ^D.) This closes the input stream to list, as though it had reached the end of a file.
Alternatively, you may use input redirection to send the contents of a file to list. For example,
assume list_commands.txt contains this text:
i 10
i 11
i 9
d 11
Then we may send this file to list as its input like so:
$ ./list < list_commands.txt
1 : 10
2 : 10 11
3 : XXXXXXXXXX
2 : 9 10
6
1.5 mexp: Matrix manipulation
Write a program mexp that multiplies a square matrix by itself a specified number of times. mexp
takes a single argument, which is the path to a file containing a square (k × k) matrix M and a
non-negative exponent n. It computes Mn and prints the result.
Note that the size of the matrix is not known statically. You must use malloc to allocate space
for the matrix once you obtain its size from the input file.
To compute Mn, it is sufficient to multiply M by itself n− 1 times. That is, M3 = M ×M ×M .
Naturally, a different strategy is needed for M0.
Input format The first line of the input file contains an integer k. This indicates the size of the
matrix M , which has k rows and k columns.
The next k lines in the input file contain k integers. These indicate the content of M . Each line
co
esponds to a row, beginning with the first (top) row.
The final line contains an integer n. This indicates the number of times M will be multiplied by
itself. n is guaranteed to be non-negative, but it may be 0.
For example, an input file file.txt containing
3
1 2 3
4 5 6
7 8 9
2
indicates that mexp must compute  XXXXXXXXXX
7 8 9
2 .
Output format The output of mexp is the computed matrix Mn. Each row of Mn is printed on
a separate line, beginning with the first (top) row. The items within a row are separated by spaces.
Using file.txt from above,
$ ./mexp file1.txt
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
1.6 bst: Binary search trees
Write a program bst that manipulates binary search trees. It will receive commands from standard
input, and print resposes to those commands to standard output.
A binary search tree is a binary tree that stores integer values in its interior nodes. The value fo
a particular node is greater than every value stored its left sub-tree and less than every value stored
in its right sub-tree. The tree will not contain any value more than once. bst will need to allocate
space for new nodes as they are created using malloc; any allocated space should be deallocated
using free before bst terminates.
This portion of the assignment has two parts.
7
Part 1 In this part, you will implement bst with three commands:
insert n Adds a value to the tree, if not already present. The new node will always be added as the
child of an existing node, or as the root. No existing node will change or move as as result of
inserting an item. If n was not present, and hence has been inserted, bst will print inserted.
Otherwise, it will print not inserted. The instruction format is an i followed by a decimal
integer n.
search n Searches the tree for a value n. If n is present, bst will print present. Otherwise, it will
print absent. The instruction format is an s followed by a space and an integer n.
print Prints the cu
ent tree structure, using the format in section 1.6.1.
Part 2 In this part, you will implement bst with an additional fourth command:
delete n Removes a value from the tree. See section 1.6.2 for further discussion of deleting nodes.
If n is not present, print absent. Otherwise, print deleted. The instruction format is a d
followed by a space and an integer n.
Input format The input will be a series of lines, each beginning with a command character (i, s,
p, or d), possibly followed by a decimal integer. When the input ends, the program should terminate.
Your program
Answered Same Day Mar 01, 2022

Solution

Arun Shankar answered on Mar 01 2022
111 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here