SlideShare a Scribd company logo
1 of 13
Here is the grading matrix where the TA will leave feedback. If
you scored 100%, you will most likely not see any feedback
J
Question
# points
Feedback
Max
Scored
1
Tracing
3
2
Testing
2
3
Refactoring
2
4
Debugging
3
Question #1 – Tracing Programs
We are going to trace the following program, i.e. simulate in
your head how it would execute on a computer. To help you, a
trace table is provided for you to fill.
For each “execution step” of the program, write down in the
table the line being executed along with the value of each
variable which was modified.
Please note that we omitted the usual
main
function definition and other #include statements. We assume
the following fragment to be inside a
main
function.
Program to Trace
1
int something = 5;
2
int data = 42;
3
int n = 0;
4
5
for( n = 0 ; data > 0 ; n++){
6
data -= something;
7
}
8
9
if( data < 0) n--;
Trace Table to Fill
Feel free to add / remove rows if necessary
Step #
Line #
Variables Values
Remarks
something
data
n
1
2
3
…
Question #2 – Testing Programs
You are going to write tests for the following program fragment
which we assume to be inside a
main
function. Its requirements are to
-
Prompt the user for two int numbers X and Y
-
If Y is zero the program should display “Error #1” then exit.
-
Otherwise, if any of the two input value is less or equal to zero,
it should display “Error #2” then exit.
-
Otherwise, it should display how many times Y goes into X.
This is the equivalent of the integer division of X by Y.
Your objective is to write tests which will guarantee
-
The program conforms to the requirements
-
All possible execution paths have been tested
-
Your program does not feature any errors
Program to Test
1
int div = 0;
2
int data = 0;
3
int n = 0;
4
printf("Enter positive int to divide: ");
5
scanf("%d", &data);
6
7
printf("Enter positive int to divide it by: ");
8
scanf("%d", &div);
9
10
if(div == 0){
11
printf("Error #1n");
12
exit(EXIT_FAILURE);
13
}
14
15
if((data <= 0) || (div <= 0)){
16
printf("Error #2n");
17
exit(EXIT_FAILURE);
18
}
19
20
for( n = 0 ; data > 0 ; n++){
21
data -= div;
22
}
23
24
if( data < 0) n--;
25
26
printf("Ouput value is %dn", n);
Tests Table to Fill
Feel free to add / remove rows if necessary
Test #
Inputs’ Values
Expected Results
Explanations;
What did you use this test for?
Why is it not redundant with others?
div
data
n
Error
1
2
3
…
Question #3 – Refactoring Programs
Refactor the following code to improve it in terms of
readability, documentation, redundancy. Regarding redundancy,
we really don’t like having twice the same printf/scanf but we
don’t want a solution where the loop’s condition would be
repeated twice either.
You will provide your version in the “Your Modified Version”
subsection which is already pre-filled with the original. Then,
for each thing you modified, use the table in the “Summary”
subsection to summarize what you did & why you did it.
Program to Refactor
int grade = 0, total = 0, number = 0;
printf("Grade Average Programn");
printf("Enter grade outside of [0..100] to stopn");
printf("Enter a grade between 0 and 100 inclusive: ");
scanf("%d", &grade);
while((grade >0) && (grade <=100)){
total += grade; number += 1;
printf("Enter a grade between 0 and 100 inclusive: ");
scanf("%d", &grade);
}
Your Improved Version
int grade = 0, total = 0, number = 0;
printf("Grade Average Programn");
printf("Enter grade outside of [0..100] to stopn");
printf("Enter a grade between 0 and 100 inclusive: ");
scanf("%d", &grade);
while((grade >0) && (grade <=100)){
total += grade; number += 1;
printf("Enter a grade between 0 and 100 inclusive: ");
scanf("%d", &grade);
}
Summary of Improvements
Feel free to add rows to, or remove rows from, this table as
needed;
What did you modify
How did you modify it?
Why did you modify it?
Question #4 – Debugging Programs
The following program has build-time errors – i.e. syntax,
linker – along with runtime errors – i.e. logic of the program,
crashes. Some statements might also be simply useless.
We need you to list all of these in the table below along with
how you would fix them.
Program to Debug
1#include "stdio.c"
2#include "stdlib.c"
3
4int main(){
5
int mystery = 5;
6
int tmp = 0;
7
double data = 0.0;
8
9
do{
10
prinf("Enter a floating point value: ");
11
scanf("%d", data);
12
13
tmp = (int)data;
14
if( tmp % 2)
15
prinf("The int part of %d", data);
16
prinf(" is an even numbern");
17
else
18
prinf("The int part of %d", data);
19
prinf(" is an odd numbern");
20
21
prinf("Enter 1.0 to enter another value:");
22
scanf("%d", data);
23
}while( data = 1.0 )
24 }
25
Bugs Table
Identify each bug you find & provide the lines # where it
happens. In addition, explain what the problem was, then how
you fixed it. If the same bug appears at different line, just enter
it one time in the table but specify all the lines where it
happens.
Bug #
Lines #
Problem you identified
How you fixed it
Your Fixed Version
Apply all the fixes you listed in the table to the code below to
make it your fixed version. Please note that if a bug is fixed
below but not in the table, or the other way around, you won’t
get credit for it. You need to have both the bug and its
explanations in the table and have it fixed below.
#include "stdio.c"
#include "stdlib.c"
int main(){
int mystery = 5;
int tmp = 0;
double data = 0.0;
do{
prinf("Enter a floating point value: ");
scanf("%d", data);
tmp = (int)data;
if( tmp % 2)
prinf("The int part of %d", data);
prinf(" is an even numbern");
else
prinf("The int part of %d", data);
prinf(" is an odd numbern");
prinf("Enter 1.0 to enter another value:");
scanf("%d", data);
}while( data = 1.0 )
}

More Related Content

Similar to Here is the grading matrix where the TA will leave feedback. If you .docx

Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
nayakq
 
Dti2143 lab sheet 9
Dti2143 lab sheet 9Dti2143 lab sheet 9
Dti2143 lab sheet 9
alish sha
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
alish sha
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
alish sha
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
shandicollingwood
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
jacksnathalie
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdf
YashMirge2
 

Similar to Here is the grading matrix where the TA will leave feedback. If you .docx (20)

Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 
Dti2143 lab sheet 9
Dti2143 lab sheet 9Dti2143 lab sheet 9
Dti2143 lab sheet 9
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
Write a program to check a given number is prime or not
Write a program to check a given number is prime or notWrite a program to check a given number is prime or not
Write a program to check a given number is prime or not
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcements.docx
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
 
Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in c
 
C code examples
C code examplesC code examples
C code examples
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
C important questions
C important questionsC important questions
C important questions
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdf
 
C Programming Lab.pdf
C Programming Lab.pdfC Programming Lab.pdf
C Programming Lab.pdf
 
17 Jo P May 08
17 Jo P May 0817 Jo P May 08
17 Jo P May 08
 

More from trappiteboni

Hi, I need help with my Sociology ETHNOGRAPHIC project.here is the.docx
Hi, I need help with my Sociology ETHNOGRAPHIC project.here is the.docxHi, I need help with my Sociology ETHNOGRAPHIC project.here is the.docx
Hi, I need help with my Sociology ETHNOGRAPHIC project.here is the.docx
trappiteboni
 
Hi, can someone answer these questions for me please Please let it .docx
Hi, can someone answer these questions for me please Please let it .docxHi, can someone answer these questions for me please Please let it .docx
Hi, can someone answer these questions for me please Please let it .docx
trappiteboni
 

More from trappiteboni (20)

HI, Im taking a speach class and this assingment is an essay and th.docx
HI, Im taking a speach class and this assingment is an essay and th.docxHI, Im taking a speach class and this assingment is an essay and th.docx
HI, Im taking a speach class and this assingment is an essay and th.docx
 
Hi,Hope all is well.  Can you please complete questions send via.docx
Hi,Hope all is well.  Can you please complete questions send via.docxHi,Hope all is well.  Can you please complete questions send via.docx
Hi,Hope all is well.  Can you please complete questions send via.docx
 
Hi,can you please do essay for me,,the essay is going to be.docx
Hi,can you please do essay for me,,the essay is going to be.docxHi,can you please do essay for me,,the essay is going to be.docx
Hi,can you please do essay for me,,the essay is going to be.docx
 
Hi,I have a project in smart energy grid which is due December 2.docx
Hi,I have a project in smart energy grid which is due December 2.docxHi,I have a project in smart energy grid which is due December 2.docx
Hi,I have a project in smart energy grid which is due December 2.docx
 
Hi,I am taking Java II and I have a project about a restuarant s.docx
Hi,I am taking Java II and I have a project about a restuarant s.docxHi,I am taking Java II and I have a project about a restuarant s.docx
Hi,I am taking Java II and I have a project about a restuarant s.docx
 
Hi, i need to write a introduction part of my research paper.1-It .docx
Hi, i need to write a introduction part of my research paper.1-It .docxHi, i need to write a introduction part of my research paper.1-It .docx
Hi, i need to write a introduction part of my research paper.1-It .docx
 
Hi,Actually I want to make a conclusion for my presentation. Attac.docx
Hi,Actually I want to make a conclusion for my presentation. Attac.docxHi,Actually I want to make a conclusion for my presentation. Attac.docx
Hi,Actually I want to make a conclusion for my presentation. Attac.docx
 
Hi, I need someone to write me a code that would read in the two att.docx
Hi, I need someone to write me a code that would read in the two att.docxHi, I need someone to write me a code that would read in the two att.docx
Hi, I need someone to write me a code that would read in the two att.docx
 
Hi, I need help with my Sociology ETHNOGRAPHIC project.here is the.docx
Hi, I need help with my Sociology ETHNOGRAPHIC project.here is the.docxHi, I need help with my Sociology ETHNOGRAPHIC project.here is the.docx
Hi, I need help with my Sociology ETHNOGRAPHIC project.here is the.docx
 
Hi, The assignment is to write a brief case for these cases listed b.docx
Hi, The assignment is to write a brief case for these cases listed b.docxHi, The assignment is to write a brief case for these cases listed b.docx
Hi, The assignment is to write a brief case for these cases listed b.docx
 
Hi, I have an Anthropology Culture and Medicine Healers and Healin.docx
Hi, I have an Anthropology Culture and Medicine Healers and Healin.docxHi, I have an Anthropology Culture and Medicine Healers and Healin.docx
Hi, I have an Anthropology Culture and Medicine Healers and Healin.docx
 
Hi, can someone please help me with these questions thanks.1- Eq.docx
Hi, can someone please help me with these questions thanks.1- Eq.docxHi, can someone please help me with these questions thanks.1- Eq.docx
Hi, can someone please help me with these questions thanks.1- Eq.docx
 
Hi, can someone answer these questions for me please Please let it .docx
Hi, can someone answer these questions for me please Please let it .docxHi, can someone answer these questions for me please Please let it .docx
Hi, can someone answer these questions for me please Please let it .docx
 
Hi there.I have a final presentation that can cover any of a .docx
Hi there.I have a final presentation that can cover any of a .docxHi there.I have a final presentation that can cover any of a .docx
Hi there.I have a final presentation that can cover any of a .docx
 
hi there im looking for someone to help me out with this homework.docx
hi there im looking for someone to help me out with this homework.docxhi there im looking for someone to help me out with this homework.docx
hi there im looking for someone to help me out with this homework.docx
 
hi there,I need a harvard reference with this assignment.My co.docx
hi there,I need a harvard reference with this assignment.My co.docxhi there,I need a harvard reference with this assignment.My co.docx
hi there,I need a harvard reference with this assignment.My co.docx
 
Hi I will attach the course project that I have started working on a.docx
Hi I will attach the course project that I have started working on a.docxHi I will attach the course project that I have started working on a.docx
Hi I will attach the course project that I have started working on a.docx
 
Hi there, I need only these thing ( Strategic AlignmentCost B.docx
Hi there, I need only these thing ( Strategic AlignmentCost B.docxHi there, I need only these thing ( Strategic AlignmentCost B.docx
Hi there, I need only these thing ( Strategic AlignmentCost B.docx
 
Hi there!I have a discussion to finish as soon as possible today f.docx
Hi there!I have a discussion to finish as soon as possible today f.docxHi there!I have a discussion to finish as soon as possible today f.docx
Hi there!I have a discussion to finish as soon as possible today f.docx
 
Hi Laura,Thank you for this great information on radioactive isoto.docx
Hi Laura,Thank you for this great information on radioactive isoto.docxHi Laura,Thank you for this great information on radioactive isoto.docx
Hi Laura,Thank you for this great information on radioactive isoto.docx
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 

Here is the grading matrix where the TA will leave feedback. If you .docx

  • 1. Here is the grading matrix where the TA will leave feedback. If you scored 100%, you will most likely not see any feedback J Question # points Feedback Max Scored 1 Tracing 3 2 Testing 2 3 Refactoring 2 4 Debugging 3 Question #1 – Tracing Programs We are going to trace the following program, i.e. simulate in your head how it would execute on a computer. To help you, a trace table is provided for you to fill. For each “execution step” of the program, write down in the table the line being executed along with the value of each
  • 2. variable which was modified. Please note that we omitted the usual main function definition and other #include statements. We assume the following fragment to be inside a main function. Program to Trace 1 int something = 5; 2 int data = 42; 3 int n = 0; 4 5 for( n = 0 ; data > 0 ; n++){ 6 data -= something; 7 } 8 9 if( data < 0) n--; Trace Table to Fill Feel free to add / remove rows if necessary
  • 3. Step # Line # Variables Values Remarks something data n 1 2 3 … Question #2 – Testing Programs You are going to write tests for the following program fragment which we assume to be inside a main
  • 4. function. Its requirements are to - Prompt the user for two int numbers X and Y - If Y is zero the program should display “Error #1” then exit. - Otherwise, if any of the two input value is less or equal to zero, it should display “Error #2” then exit. - Otherwise, it should display how many times Y goes into X. This is the equivalent of the integer division of X by Y. Your objective is to write tests which will guarantee - The program conforms to the requirements - All possible execution paths have been tested - Your program does not feature any errors Program to Test 1 int div = 0; 2 int data = 0; 3
  • 5. int n = 0; 4 printf("Enter positive int to divide: "); 5 scanf("%d", &data); 6 7 printf("Enter positive int to divide it by: "); 8 scanf("%d", &div); 9 10 if(div == 0){ 11 printf("Error #1n"); 12 exit(EXIT_FAILURE); 13 } 14 15 if((data <= 0) || (div <= 0)){ 16 printf("Error #2n");
  • 6. 17 exit(EXIT_FAILURE); 18 } 19 20 for( n = 0 ; data > 0 ; n++){ 21 data -= div; 22 } 23 24 if( data < 0) n--; 25 26 printf("Ouput value is %dn", n); Tests Table to Fill Feel free to add / remove rows if necessary Test # Inputs’ Values Expected Results Explanations; What did you use this test for? Why is it not redundant with others? div data n
  • 7. Error 1 2 3 … Question #3 – Refactoring Programs Refactor the following code to improve it in terms of readability, documentation, redundancy. Regarding redundancy, we really don’t like having twice the same printf/scanf but we don’t want a solution where the loop’s condition would be repeated twice either. You will provide your version in the “Your Modified Version” subsection which is already pre-filled with the original. Then, for each thing you modified, use the table in the “Summary” subsection to summarize what you did & why you did it. Program to Refactor
  • 8. int grade = 0, total = 0, number = 0; printf("Grade Average Programn"); printf("Enter grade outside of [0..100] to stopn"); printf("Enter a grade between 0 and 100 inclusive: "); scanf("%d", &grade); while((grade >0) && (grade <=100)){ total += grade; number += 1; printf("Enter a grade between 0 and 100 inclusive: "); scanf("%d", &grade); } Your Improved Version int grade = 0, total = 0, number = 0; printf("Grade Average Programn"); printf("Enter grade outside of [0..100] to stopn"); printf("Enter a grade between 0 and 100 inclusive: "); scanf("%d", &grade); while((grade >0) && (grade <=100)){ total += grade; number += 1; printf("Enter a grade between 0 and 100 inclusive: "); scanf("%d", &grade); } Summary of Improvements Feel free to add rows to, or remove rows from, this table as needed; What did you modify How did you modify it? Why did you modify it?
  • 9. Question #4 – Debugging Programs The following program has build-time errors – i.e. syntax, linker – along with runtime errors – i.e. logic of the program, crashes. Some statements might also be simply useless. We need you to list all of these in the table below along with how you would fix them. Program to Debug 1#include "stdio.c" 2#include "stdlib.c" 3 4int main(){ 5 int mystery = 5; 6 int tmp = 0; 7 double data = 0.0; 8 9 do{ 10
  • 10. prinf("Enter a floating point value: "); 11 scanf("%d", data); 12 13 tmp = (int)data; 14 if( tmp % 2) 15 prinf("The int part of %d", data); 16 prinf(" is an even numbern"); 17 else 18 prinf("The int part of %d", data); 19 prinf(" is an odd numbern"); 20 21 prinf("Enter 1.0 to enter another value:"); 22
  • 11. scanf("%d", data); 23 }while( data = 1.0 ) 24 } 25 Bugs Table Identify each bug you find & provide the lines # where it happens. In addition, explain what the problem was, then how you fixed it. If the same bug appears at different line, just enter it one time in the table but specify all the lines where it happens. Bug # Lines # Problem you identified How you fixed it Your Fixed Version Apply all the fixes you listed in the table to the code below to
  • 12. make it your fixed version. Please note that if a bug is fixed below but not in the table, or the other way around, you won’t get credit for it. You need to have both the bug and its explanations in the table and have it fixed below. #include "stdio.c" #include "stdlib.c" int main(){ int mystery = 5; int tmp = 0; double data = 0.0; do{ prinf("Enter a floating point value: "); scanf("%d", data); tmp = (int)data; if( tmp % 2) prinf("The int part of %d", data); prinf(" is an even numbern");
  • 13. else prinf("The int part of %d", data); prinf(" is an odd numbern"); prinf("Enter 1.0 to enter another value:"); scanf("%d", data); }while( data = 1.0 ) }