Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 1 of this week’s lab will give you an opportunity to use the debugging capa

ID: 3628952 • Letter: P

Question

Part 1 of this week’s lab will give you an opportunity to use the debugging capabilities of Visual Studio. Part 2 will present a problem for which you will need to create a test plan and actually test an executable program to determine if it behaves correctly.
Part 1 – Using the Debugger
To begin this exercise, create a VC++ project and copy the following code into your project. Make sure that the project compiles successfully.
#include <iostream>

using namespace std;

int main()
{
int input;
int back1 = 1, back2 = 0;
int current = 1;

cout << "Enter which number in the Fibonacci number sequence you want to find." << endl;
cout << "The first and second Fibonacci numbers are 1." << endl;
cin >> input;

while (input < 1)
{
cout << "You must enter a value greater than 0, try again." << endl;
cin >> input;
}

if (input > 2)
{
for(int i = 2; i < input; i++)
{
back2 = back1;
back1 = current;
current = back1 + back2;
}
}

cout << "The value of Fibonacci number " << input << " is " << current << endl;

cin.ignore(2);
return 0;
}

Make sure that this program executed correctly by running it and entering the value 12. You should get the number 144 as the 12th number of the Fibonacci sequence.
1. Set a breakpoint at the beginning of the for loop (the line containing for(….)) by clicking in the far left column of the edit frame. A red dot should appear when the breakpoint has been set.
2. Run the program and enter the value 46. The program should halt at the breakpoint. Click on the Locals tab at the bottom of the window to see the value of the local variables. What are the values of the program variables at this point?
i current back1 back2 input


3. Remove the breakpoint that was set in step 1 (by clicking on the red dot). Place a breakpoint on the line containing the closing curly bracket of the for loop. Right click on the breakpoint (red dot) and select Condition from the menu. Set the condition for this breakpoint to i == 9. Run the program. When it stops, record the value of the variables below.
i current back1 back2 input


4. Single step your program 4 times. Record the value of the variables below.
i current back1 back2 input


5. Using your conditional breakpoint, record the values of the variables in the table below for the values of i that are specified.
i current back1 back2 input
19
29
39
45

6. Allow the program to run to completion. Clear all breakpoints (by clicking on the red dot) except the conditional breakpoint at the end of the for loop. Run the program again, only this time with the input of 47. When the program stops, the variables should still have the same values as in the last line of the table from step 5, except the input variable should show 47. Now, single step your program 5 times and record the values of the variables.
i current back1 back2 input


7. Does anything seem wrong with your results? Explain what happened.



8. Change the data type of the back1, back2, and current variables to unsigned. Redo step 6 and record the values of the variables.
i current back1 back2 input


9. Explain why changing the data type corrected the problem.


Part 2 – Black Box Testing
A customer has requested a program be developed to meet the following criterion:
1. The program needs to convert from celcius temperatures to fahrenheit temperatures.
2. The user should be able to enter temperatures containing fractional degrees (ie. 12.3)
3. The converted temperatures should be accurate to within 1/10th of a degree.
4. The user should be able to enter the number of temperatures to be converted up to a maximum of 10.
5. The output should be tabular with each row including the input and converted temperature.

Write a test plan to thoroughly test this program. The executable for this program is included in with this lab. You should have test cases which verify that the program does all of what is required in the problem specification above. You should also test to see how robust the program is, that is, how does it handle inputs outside the expected ranges.
Document your test plan in a table. For each test case, document the expected program behavior and the actual program behavior. If the program does not behave according to your prediction, write a brief explanation of what the program did wrong.
For Part 1, answer all the questions, including filling in all the tables. For Part 2, write a test plan in a separate Word document, documenting each test case including predicted and actual results along with explanations. Turn in both documents to complete the lab assignment for this week.

Explanation / Answer

please rate - thanks

1. Set a breakpoint at the beginning of the for loop (the line containing for(….)) by clicking in the far left column of the edit frame. A red dot should appear when the breakpoint has been set.
2. Run the program and enter the value 46. The program should halt at the breakpoint. Click on the Locals tab at the bottom of the window to see the value of the local variables. What are the values of the program variables at this point?
i =-858993460   current =1    back1=1 back2= 0    input= 46


3. Remove the breakpoint that was set in step 1 (by clicking on the red dot). Place a breakpoint on the line containing the closing curly bracket of the for loop. Right click on the breakpoint (red dot) and select Condition from the menu. Set the condition for this breakpoint to i == 9. Run the program. When it stops, record the value of the variables below.
i current back1 back2 input
9     34     21      13     46

4. Single step your program 4 times. Record the value of the variables below.
i current back1 back2    input
9      55      34        21         46

5. Using your conditional breakpoint, record the values of the variables in the table below for the values of i that are specified.
i          current      back1    back2 input
19         6765        4181         2584         46
29        832040    514229        317811       46
39       102334155    63245986           39088169      46
45      1836311903    1134903170     701408733        46

6. Allow the program to run to completion. Clear all breakpoints (by clicking on the red dot) except the conditional breakpoint at the end of the for loop. Run the program again, only this time with the input of 47. When the program stops, the variables should still have the same values as in the last line of the table from step 5, except the input variable should show 47. Now, single step your program 5 times and record the values of the variables.
i current    back1    back2              input
45      1836311903    1134903170     701408733        47

46      1836311903    1134903170     701408733        47

46      1836311903    1134903170     1134903170        47

46      1836311903 1836311903      1134903170        47

46     -1323752223 1836311903      1134903170        47

7. Does anything seem wrong with your results? Explain what happened.
current is nexative. there was overflow and the number doesn't fit in the integer


8. Change the data type of the back1, back2, and current variables to unsigned. Redo step 6 and record the values of the variables.
i     current                      back1    back2                   input

45      1836311903    1134903170     701408733        47

46      1836311903    1134903170     701408733        47

46      1836311903    1134903170     1134903170        47

46      1836311903 1836311903      1134903170        47

46       2927215073 1836311903      1134903170        47



9. Explain why changing the data type corrected the problem.

you had more bits to represent the variable so no overflow

-------------------------------

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{double cel[10],fah[10];
int n,i;
cout<<"how many temperatures? ";
cin>>n;
while(n<1||n>10)
     {cout<<"must be between 1 and 10 ";
     cout<<"how many temperatures? ";
     cin>>n;
     }
for(i=0;i<n;i++)
    {cout<<"enter the temperature in Celsius: ";
    cin>>cel[i];
    fah[i]=9./5.*cel[i]+32.;
    }
cout<<"Celsius fahrenheit ";
for(i=0;i<n;i++)
    cout<<setprecision(1)<<fixed<<cel[i]<<" "<<fah[i]<<endl;
system("pause");
return 0;
}