# CMSC 104, Section 01, Fall 2016 Problem Solving and Computer Programming

## Project 5

Due Date: Tuesday, November 8th @ 5:30 PM

Point Value: This project is graded with a 75 point max score.

Objectives:

To become more familiar with:
• C program creation, compilation, and execution
• Sequence, Selection, and Repetition Control Structures
• Logical Operators
• if and while instructions in C

For question 1, copy the truth tables below and paste them in a text file named campusid_proj5.txt, then fill in the answers.

1. (16 points) Fill in the truth tables.

```+---+---+------------------------+
| a | b | (!a && b) || (a && !b) |
+---+---+------------------------+
| 0 | 0 |                        |
+---+---+------------------------+
| 1 | 0 |                        |
+---+---+------------------------+
| 0 | 1 |                        |
+---+---+------------------------+
| 1 | 1 |                        |
+---+---+------------------------+

+---+---+---+---------------------------------+
| a | b | c | (!(a || b)) && (c || (a || !b)) |
+---+---+---+---------------------------------+
| 0 | 0 | 0 |                                 |
+---+---+---+---------------------------------+
| 1 | 0 | 0 |                                 |
+---+---+---+---------------------------------+
| 0 | 1 | 0 |                                 |
+---+---+---+---------------------------------+
| 0 | 0 | 1 |                                 |
+---+---+---+---------------------------------+
| 1 | 1 | 0 |                                 |
+---+---+---+---------------------------------+
| 1 | 0 | 1 |                                 |
+---+---+---+---------------------------------+
| 0 | 1 | 1 |                                 |
+---+---+---+---------------------------------+
| 1 | 1 | 1 |                                 |
+---+---+---+---------------------------------+

+---+---+---------------------------------+
| a | b | ((a % (b + 1)) == 0) && (b = 0) |
+---+---+---------------------------------+
| 0 | 0 |                                 |
+---+---+---------------------------------+
| 1 | 0 |                                 |
+---+---+---------------------------------+
| 0 | 1 |                                 |
+---+---+---------------------------------+
| 1 | 1 |                                 |
+---+---+---------------------------------+
```

2. (59 points) Write a C program, campusid_tri.c, that will print out a triangle of *'s, where only the odd numbered lines are printed. The height of the triangle should be input by the user, and should be checked to ensure that the height is positive and odd. If the input value is inappropriate, the user should be prompted until the input value is correct.

When printing the triangle, only the odd numbered lines (i.e. 1, 3, 5, ...) should contain *'s and the even lines should be blank (but included). The number of *'s printed on the odd lines should be equal to the line number. As an example, a triangle of height 13 is given below.

```*

***

*****

*******

*********

***********

*************
```

3. (10 points optional EXTRA CREDIT) Make a copy of your completed campusid_tri.c called campusid_isosceles.c and modify it such that the printed triangle is isoceles rather than right. The other characteristics of the triangle should remain the same (even lines blank, number of *'s equal to the line number, etc). As an example, a triangle of height 13 is given below.

```      *

***

*****

*******

*********

***********

*************
```

When you have finished, submit your campusid_proj5.txt, campusid_tri.c, and (optionally) campusid_isosceles.c files using the following commands:

curl -L -F file=@campusid_proj5.txt http://userpages.umbc.edu/~reicht1/classes/cmsc104/fall16/submit.php

curl -L -F file=@campusid_tri.c http://userpages.umbc.edu/~reicht1/classes/cmsc104/fall16/submit.php

(optional) curl -L -F file=@campusid_isosceles.c http://userpages.umbc.edu/~reicht1/classes/cmsc104/fall16/submit.php

Additionally, email your campusid_proj5.txt, campusid_tri.c, and campusid_isosceles.c files as an attachment to reicht1@umbc.edu using the subject line Project Submission - 5 - Lastname, Firstname, replacing Lastname, Firstname with your name.