# PROGRAMMING 3

**Question description**

**The ECE Department offers three depth sequences:**

**Computer System Design: ECE-15, ECE-111, ECE-141, ECE-165**

**Communications Systems: ECE-153, ECE-155, ECE-158**

**Machine Learning and Controls: ECE-171, ECE-178**

**Within every depth sequence, the ﬁrst course has no prerequisites, and each course is a prerequisite for the next. For example, ECE-153 has no prerequisites, but it is a prerequisite for ECE-155, which in turn is a prerequisite for ECE-158. There are no cross-depth prerequisites. Write a program prereq.c that prompts the user for a course name and prints the prerequisites needed to take it, and a happy message if no prerequisites are required, as shown below. Implement your program using switch-case and use fall-through.**

(˜)$ a.out

Course: ECE-15

Prereqs: Anyone can take that!

(˜)$ a.out

Course: ECE-141

Prereqs: ECE-111 <-- ECE-15

(˜)$ a.out

Course: ECE-165

Prereqs: ECE-141 <-- ECE-111 <-- ECE-15

(˜)$ a.out

Course: ECE-155

Prereqs: ECE-153

**Write a program trivia.c that prompts the user for a nonnegative integer, and prints the number of digits, the smallest and largest digits, the number of times the digit 7 appeared, and a conclusion determined by the remainder of the number mod 3: “Boring!” if the remainder is 0, “Amazing!” if the remainder is 1, and “Yahoo!” if the remainder is 2. When typing the number of digits and the number of times 7 appeared, use singular (“digit”, “time”) for 1, and plural (“digits”, “times”) for all other numbers. Assume that a nonnegative number will always be entered and that a positive number will not start with any 0’s, for example 007 will be written as just 7.**

(˜)$ a.out

Nonnegative integer: 5384

4 digits, smallest is 3, largest is 8, 7 appeared 0 times. Yahoo!

(˜)$ a.out

Nonnegative integer: 507974

6 digits, smallest is 0, largest is 9, 7 appeared 2 times. Yahoo!

(˜)$ a.out

Nonnegative integer: 7

1 digit, smallest is 7, largest is 7, 7 appeared 1 time. Amazing!

(˜)$ a.out

Nonnegative integer: 0

1 digit, smallest is 0, largest is 0, 7 appeared 0 times. Boring!

(˜)$

Hints: You will need to identify and then remove the rightmost digit, one at a time. For example for 348, you need to identify 8, then 4, then 3. The rightmost digit can be found using modulo (%), and can be peeled of using integer division (/=). You can build the program gradually by ﬁrst printing one of the requested values (say smallest digit), then revisiting the program and printing the other values (largest, prevalence of 7, etc.).

**Write a program chessboard.c that asks the user for the size of a chessboard and the locations of the King, Queen, and a rook, specified by row and column with the top row and left column being 1. Print the chessboard with horizontal and vertical lines and indicate dark squares by * as shown below. MArk the location of the King by K, the location of the Queen by q if the King can capture the queen and by Q if the king cannot capture it, and similarily for the location of the Rook, use r or R depending on whether the King can capture it. You can assume that the user will input three different locations within the board.**

Hints: One way to solve it is in stages. First** **draw the board with just the horizontal and vertical lines and without any markings. Then modify the program to also print the *'s. Then further modify to print the locations of the three pieces. Finally print Q/q and R/r correctly. Recall that a King can capture everything immediately adjacent to it horizontally, vertically, or diagonal. Hence if the King is at row Kr and column Kc, then it can capture a piece at row r and column c if Kr-1<=r<=Kr+1 and Kc-1<=c<=Kc+1.

a.out

Board size: 5

King row and column: 5 3

Queen row and column: 4 5

Rook row and column: 2 1

+-+-+-+-+-+

|*| |*| |*|

+-+-+-+-+-+

|R|*| |*| |

+-+-+-+-+-+

|*| |*| |*|

+-+-+-+-+-+

| |*| |*|Q|

+-+-+-+-+-+

|*| |K| |*|

+-+-+-+-+-+

(˜)$ a.out

Board size: 4

King row and column: 1 1

Queen row and column: 1 3

Rook row and column: 2 1

+-+-+-+-+

|K| |Q| |

+-+-+-+-+

|r|*| |*|

+-+-+-+-+

|*| |*| |

+-+-+-+-+

| |*| |*|

+-+-+-+-+

(˜)$ a.out

Board size: 3

King row and column: 2 2

Queen row and column: 1 3

Rook row and column: 3 1

+-+-+-+

|*| |q|

+-+-+-+

| |K| |

+-+-+-+

|r| |*|

+-+-+-+

(˜)$

Hints: This problem is mor

## Tutor Answer

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors