Arrays

oynxrlnaxf2

Programming

Question Description

1) Write a program hot.c that prompts the user for a word and reads it into a 50-character array. If the word contains the lower-case letters ’h’, ’o’, and ’t’, in order though not necessarily consecutively, print “Hot”, otherwise print “Not”.

EX: 

(˜)$ a.out

Word: hotelier

Hot

(˜)$ a.out

Word: hypnotist

Hot

(˜)$ a.out

Word: shoplifTer

Not

(˜)$ a.out

Word: PHILANThRoPISt

Hot

(˜)$ a.out

Word: philanderer

Not


2. Write a program rotate.c that prompts the user for the size of a matrix and then for each of its rows. Rotate the matrix one notch clockwise around its center. Use a 2-dimensional array of the same size as the matrix, and make sure you rotate all elements correctly as in the size-4 example below.

EX:

a.out

Matrix size: 1

Row 1 digits: 9

After clockwise rotation:

9

(˜)$ a.out

Matrix size: 2

Row 1 digits: 8 4

Row 2 digits: 2 7

After clockwise rotation:

2 8

7 4

(˜)$ a.out

Matrix size: 3

Row 1 digits: 5 0 4

Row 2 digits: 7 3 5

Row 3 digits: 4 1 2

After clockwise rotation:

7 5 0

4 3 4

1 2 5

(˜)$ a.out

Matrix size: 4

Row 1 digits: 7 2 3 8

Row 2 digits: 4 7 2 1

Row 3 digits: 9 1 4 0

Row 4 digits: 3 6 2 5

After clockwise rotation:

4 7 2 3

9 1 7 8

3 4 2 1

6 2 5 0

Hint: Note that the matrix rotation consists of “circles” inside the matrix. These circle rotations can be performed separately, where each circle rotation can be accomplished by four loops, one for each side of the square. Also remember that when you move elements around, you may need to temporarily save one of the elements and then restore it.

3.  Write a program escape.c that reads a 5 by 5 floor plan, one row at a time. Each row consists of ’#’, ’.’, and ’S’, where ’#’ represents a wall or an obstacle, ’.’ represents a clear location, and ’S’ represents a student who needs to escape the space. There is exactly one student on the whole floor, and he/she can walk horizontally or vertically, but not diagonally. Determine if the student can escape the building in case of fire. For a realistic view, after asking for “5X5 layout”, print a new line.

EX: 

a.out

5X5 layout:

###.#

###.#

#S..#

#####

#####

Escape!

(˜)$ a.out

5X5 layout:

#####

##S.#

#...#

#####

#####

Sorry.

(˜)$ a.out

5X5 layout:

#####

###.#

S...#

#####

#####

Escape!

(˜)$ a.out

5X5 layout:

#####

###..

#.S.#

###.#

###.#

Escape!

(˜)$ a.out

5X5 layout:

.###.

#.#.#

#.S.#

.##.#

####.

Sorry.

Hint: One relatively simple approach is to iteratively consider the square and mark more and more locations that the student get reach. In the first iteration, consider the 3X3 interior of the square (ex-3cluding the boundary). If the student is in the interior, mark all its immediate neighbors that are free (namely ’.’, but not ’#’) as ’S’ (meaning the student can go there). Then repeat the process and in each subsequent iteration again consider just the 3X3 interior, and mark all neighbors of any ’S’ (either the original student, or those marked ’S’ in previous iterations) as ’S’ as well. It is easy to see that if the student can escape, then after a small number of iterations (you can figure out how many), there will be an ’S’ on the boundary, and you could check if that has occurred.



Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Final Answer

xhxvfgnef (136)
Purdue University

Anonymous
Great! 10/10 would recommend using Studypool to help you study.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4