Sei sulla pagina 1di 1

Project 1 Report Shrea Chari 005318456

Step 5
Input 1: I first inputted 100 survey participants with 50 supporters of impeachment and 50
opposers. The program printed the correct percentages of supporters and opposers but incorrectly
said that there is a higher percentage of those that oppose impeachment as the code did not detail
what to print in the case of a draw.
Input 2: I then inputted 5 survey participants with 6 supporters of impeachment and 0 opposers.
Again, the program correctly printed percentages, 120.0% supported impeachment and 0.0%
opposed. It also correctly reported that a higher percentage of participants support rather than
oppose impeachment.
Input 3: Next I inputted 8 survey participants, -2 supporters of impeachment and -4 opposers.
The calculated percentages were correct, -25.0% and -50.0% respectively. The program
concluded that there was a higher percentage of supporters since -25.0 is greater than -50.0.

Step 6
I introduced the logic error in line 16 where I substituted forImpeachment with antiImpeachment.
Thus, when the user inputs the number of people who support impeachment, it is actually
assigned to the variable antiImpeachment. Later, this same variable gets assigned the inputted
number of people who oppose impeachment. As a result, the number of people who support
impeachment is not assigned to any variable; furthermore, the variable forImpeachment is never
initialized. This program compiles but when the percentage of supporters and opposers are
printed, only that of the opposers is correct; the percentage of supporters is a random number due
to the uninitialized variable. As a result, the outcome concluded by the program may be either
incorrect or correct depending on the random value assigned to the uninitialized
forImpeachment. The program builds successfully but does display the error “Variable
'forImpeachment' is uninitialized when used here.”

Step 7
I introduced three compiler errors into the source code. The first error was in line 21 where I
removed the semicolon from the end of the line. Xcode showed an error essentially telling me to
add a semicolon in order to fix the code. The second error I introduced was in line 27 where I
removed << from behind the variable pcFor. This results in incorrect syntax and Xcode produced
an error asking if I meant to call the overloaded function. Additionally Xcode also produced an
error asking me to insert a semicolon at the end of the line. The last error I introduced was in line
30 where I removed the closing parenthesis from the end of the conditional in the if-else
statement. Xcode showed the error message on line 31 stating that that the expected ’)’ was
missing. G++ displayed similar error messages as well.

Potrebbero piacerti anche