SlideShare ist ein Scribd-Unternehmen logo
1 von 15
E1 – Fundamentals
Please refer to announcements for details about this exam. Make
sure you fill the information below to avoid not being graded
properly;
Last Name
Thalheimer
First Name
Kristoffer
Student ID #
Thalheimer
Here is the grading matrix where the TA will leave feedback. If
you scored 100%, you will most likely not see any feedback (
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
4
int 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 )
}

Weitere ähnliche Inhalte

Ähnlich wie E1 – FundamentalsPlease refer to announcements for details about.docx

Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans incnayakq
 
Control structure of c
Control structure of cControl structure of c
Control structure of cKomal Kotak
 
Core programming in c
Core programming in cCore programming in c
Core programming in cRahul Pandit
 
COM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingCOM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingHemantha Kulathilake
 
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 CSowmya Jyothi
 
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.docxshandicollingwood
 
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.docxjacksnathalie
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7alish sha
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptxDEEPAK948083
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programsPrasadu Peddi
 
C Programming Lab.pdf
C Programming Lab.pdfC Programming Lab.pdf
C Programming Lab.pdfMOJO89
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxtristans3
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...DR B.Surendiran .
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdfYashMirge2
 

Ähnlich wie E1 – FundamentalsPlease refer to announcements for details about.docx (20)

Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
COM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingCOM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & Branching
 
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
 
Decision Making and Branching
Decision Making and BranchingDecision Making and Branching
Decision Making and Branching
 
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
 
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
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Control structures(class 02)
Control structures(class 02)Control structures(class 02)
Control structures(class 02)
 
C important questions
C important questionsC important questions
C important questions
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
C code examples
C code examplesC code examples
C code examples
 
C Programming Lab.pdf
C Programming Lab.pdfC Programming Lab.pdf
C Programming Lab.pdf
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docx
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
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 Example
C Programming Example C Programming Example
C Programming Example
 

Mehr von jacksnathalie

OverviewThe US is currently undergoing an energy boom largel.docx
OverviewThe US is currently undergoing an energy boom largel.docxOverviewThe US is currently undergoing an energy boom largel.docx
OverviewThe US is currently undergoing an energy boom largel.docxjacksnathalie
 
OverviewThe United Nations (UN) has hired you as a consultan.docx
OverviewThe United Nations (UN) has hired you as a consultan.docxOverviewThe United Nations (UN) has hired you as a consultan.docx
OverviewThe United Nations (UN) has hired you as a consultan.docxjacksnathalie
 
OverviewThis project will allow you to write a program to get mo.docx
OverviewThis project will allow you to write a program to get mo.docxOverviewThis project will allow you to write a program to get mo.docx
OverviewThis project will allow you to write a program to get mo.docxjacksnathalie
 
OverviewThis week, we begin our examination of contemporary resp.docx
OverviewThis week, we begin our examination of contemporary resp.docxOverviewThis week, we begin our examination of contemporary resp.docx
OverviewThis week, we begin our examination of contemporary resp.docxjacksnathalie
 
OverviewProgress monitoring is a type of formative assessment in.docx
OverviewProgress monitoring is a type of formative assessment in.docxOverviewProgress monitoring is a type of formative assessment in.docx
OverviewProgress monitoring is a type of formative assessment in.docxjacksnathalie
 
OverviewThe work you do throughout the modules culminates into a.docx
OverviewThe work you do throughout the modules culminates into a.docxOverviewThe work you do throughout the modules culminates into a.docx
OverviewThe work you do throughout the modules culminates into a.docxjacksnathalie
 
OverviewThis discussion is about organizational design and.docx
OverviewThis discussion is about organizational design and.docxOverviewThis discussion is about organizational design and.docx
OverviewThis discussion is about organizational design and.docxjacksnathalie
 
OverviewScholarly dissemination is essential for any doctora.docx
OverviewScholarly dissemination is essential for any doctora.docxOverviewScholarly dissemination is essential for any doctora.docx
OverviewScholarly dissemination is essential for any doctora.docxjacksnathalie
 
OverviewRegardless of whether you own a business or are a s.docx
OverviewRegardless of whether you own a business or are a s.docxOverviewRegardless of whether you own a business or are a s.docx
OverviewRegardless of whether you own a business or are a s.docxjacksnathalie
 
OverviewImagine you have been hired as a consultant for th.docx
OverviewImagine you have been hired as a consultant for th.docxOverviewImagine you have been hired as a consultant for th.docx
OverviewImagine you have been hired as a consultant for th.docxjacksnathalie
 
OverviewDevelop a 4–6-page position about a specific health care.docx
OverviewDevelop a 4–6-page position about a specific health care.docxOverviewDevelop a 4–6-page position about a specific health care.docx
OverviewDevelop a 4–6-page position about a specific health care.docxjacksnathalie
 
Overview This purpose of the week 6 discussion board is to exam.docx
Overview This purpose of the week 6 discussion board is to exam.docxOverview This purpose of the week 6 discussion board is to exam.docx
Overview This purpose of the week 6 discussion board is to exam.docxjacksnathalie
 
Overall Scenario Always Fresh Foods Inc. is a food distributor w.docx
Overall Scenario Always Fresh Foods Inc. is a food distributor w.docxOverall Scenario Always Fresh Foods Inc. is a food distributor w.docx
Overall Scenario Always Fresh Foods Inc. is a food distributor w.docxjacksnathalie
 
OverviewCreate a 15-minute oral presentation (3–4 pages) that .docx
OverviewCreate a 15-minute oral presentation (3–4 pages) that .docxOverviewCreate a 15-minute oral presentation (3–4 pages) that .docx
OverviewCreate a 15-minute oral presentation (3–4 pages) that .docxjacksnathalie
 
Overall CommentsHi Khanh,Overall you made a nice start with y.docx
Overall CommentsHi Khanh,Overall you made a nice start with y.docxOverall CommentsHi Khanh,Overall you made a nice start with y.docx
Overall CommentsHi Khanh,Overall you made a nice start with y.docxjacksnathalie
 
Overall CommentsHi Khanh,Overall you made a nice start with.docx
Overall CommentsHi Khanh,Overall you made a nice start with.docxOverall CommentsHi Khanh,Overall you made a nice start with.docx
Overall CommentsHi Khanh,Overall you made a nice start with.docxjacksnathalie
 
Overall feedbackYou addressed most all of the assignment req.docx
Overall feedbackYou addressed most all  of the assignment req.docxOverall feedbackYou addressed most all  of the assignment req.docx
Overall feedbackYou addressed most all of the assignment req.docxjacksnathalie
 
Overall Comments Overall you made a nice start with your U02a1 .docx
Overall Comments Overall you made a nice start with your U02a1 .docxOverall Comments Overall you made a nice start with your U02a1 .docx
Overall Comments Overall you made a nice start with your U02a1 .docxjacksnathalie
 
Overview This purpose of the week 12 discussion board is to e.docx
Overview This purpose of the week 12 discussion board is to e.docxOverview This purpose of the week 12 discussion board is to e.docx
Overview This purpose of the week 12 discussion board is to e.docxjacksnathalie
 
Over the years, the style and practice of leadership within law .docx
Over the years, the style and practice of leadership within law .docxOver the years, the style and practice of leadership within law .docx
Over the years, the style and practice of leadership within law .docxjacksnathalie
 

Mehr von jacksnathalie (20)

OverviewThe US is currently undergoing an energy boom largel.docx
OverviewThe US is currently undergoing an energy boom largel.docxOverviewThe US is currently undergoing an energy boom largel.docx
OverviewThe US is currently undergoing an energy boom largel.docx
 
OverviewThe United Nations (UN) has hired you as a consultan.docx
OverviewThe United Nations (UN) has hired you as a consultan.docxOverviewThe United Nations (UN) has hired you as a consultan.docx
OverviewThe United Nations (UN) has hired you as a consultan.docx
 
OverviewThis project will allow you to write a program to get mo.docx
OverviewThis project will allow you to write a program to get mo.docxOverviewThis project will allow you to write a program to get mo.docx
OverviewThis project will allow you to write a program to get mo.docx
 
OverviewThis week, we begin our examination of contemporary resp.docx
OverviewThis week, we begin our examination of contemporary resp.docxOverviewThis week, we begin our examination of contemporary resp.docx
OverviewThis week, we begin our examination of contemporary resp.docx
 
OverviewProgress monitoring is a type of formative assessment in.docx
OverviewProgress monitoring is a type of formative assessment in.docxOverviewProgress monitoring is a type of formative assessment in.docx
OverviewProgress monitoring is a type of formative assessment in.docx
 
OverviewThe work you do throughout the modules culminates into a.docx
OverviewThe work you do throughout the modules culminates into a.docxOverviewThe work you do throughout the modules culminates into a.docx
OverviewThe work you do throughout the modules culminates into a.docx
 
OverviewThis discussion is about organizational design and.docx
OverviewThis discussion is about organizational design and.docxOverviewThis discussion is about organizational design and.docx
OverviewThis discussion is about organizational design and.docx
 
OverviewScholarly dissemination is essential for any doctora.docx
OverviewScholarly dissemination is essential for any doctora.docxOverviewScholarly dissemination is essential for any doctora.docx
OverviewScholarly dissemination is essential for any doctora.docx
 
OverviewRegardless of whether you own a business or are a s.docx
OverviewRegardless of whether you own a business or are a s.docxOverviewRegardless of whether you own a business or are a s.docx
OverviewRegardless of whether you own a business or are a s.docx
 
OverviewImagine you have been hired as a consultant for th.docx
OverviewImagine you have been hired as a consultant for th.docxOverviewImagine you have been hired as a consultant for th.docx
OverviewImagine you have been hired as a consultant for th.docx
 
OverviewDevelop a 4–6-page position about a specific health care.docx
OverviewDevelop a 4–6-page position about a specific health care.docxOverviewDevelop a 4–6-page position about a specific health care.docx
OverviewDevelop a 4–6-page position about a specific health care.docx
 
Overview This purpose of the week 6 discussion board is to exam.docx
Overview This purpose of the week 6 discussion board is to exam.docxOverview This purpose of the week 6 discussion board is to exam.docx
Overview This purpose of the week 6 discussion board is to exam.docx
 
Overall Scenario Always Fresh Foods Inc. is a food distributor w.docx
Overall Scenario Always Fresh Foods Inc. is a food distributor w.docxOverall Scenario Always Fresh Foods Inc. is a food distributor w.docx
Overall Scenario Always Fresh Foods Inc. is a food distributor w.docx
 
OverviewCreate a 15-minute oral presentation (3–4 pages) that .docx
OverviewCreate a 15-minute oral presentation (3–4 pages) that .docxOverviewCreate a 15-minute oral presentation (3–4 pages) that .docx
OverviewCreate a 15-minute oral presentation (3–4 pages) that .docx
 
Overall CommentsHi Khanh,Overall you made a nice start with y.docx
Overall CommentsHi Khanh,Overall you made a nice start with y.docxOverall CommentsHi Khanh,Overall you made a nice start with y.docx
Overall CommentsHi Khanh,Overall you made a nice start with y.docx
 
Overall CommentsHi Khanh,Overall you made a nice start with.docx
Overall CommentsHi Khanh,Overall you made a nice start with.docxOverall CommentsHi Khanh,Overall you made a nice start with.docx
Overall CommentsHi Khanh,Overall you made a nice start with.docx
 
Overall feedbackYou addressed most all of the assignment req.docx
Overall feedbackYou addressed most all  of the assignment req.docxOverall feedbackYou addressed most all  of the assignment req.docx
Overall feedbackYou addressed most all of the assignment req.docx
 
Overall Comments Overall you made a nice start with your U02a1 .docx
Overall Comments Overall you made a nice start with your U02a1 .docxOverall Comments Overall you made a nice start with your U02a1 .docx
Overall Comments Overall you made a nice start with your U02a1 .docx
 
Overview This purpose of the week 12 discussion board is to e.docx
Overview This purpose of the week 12 discussion board is to e.docxOverview This purpose of the week 12 discussion board is to e.docx
Overview This purpose of the week 12 discussion board is to e.docx
 
Over the years, the style and practice of leadership within law .docx
Over the years, the style and practice of leadership within law .docxOver the years, the style and practice of leadership within law .docx
Over the years, the style and practice of leadership within law .docx
 

Kürzlich hochgeladen

ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsRommel Regala
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 

Kürzlich hochgeladen (20)

ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World Politics
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 

E1 – FundamentalsPlease refer to announcements for details about.docx

  • 1. E1 – Fundamentals Please refer to announcements for details about this exam. Make sure you fill the information below to avoid not being graded properly; Last Name Thalheimer First Name Kristoffer Student ID # Thalheimer Here is the grading matrix where the TA will leave feedback. If you scored 100%, you will most likely not see any feedback ( Question # points Feedback Max Scored 1 Tracing 3 2 Testing 2 3
  • 2. 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++){
  • 3. 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
  • 4. 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
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. … 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;
  • 9. 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?
  • 10. 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 4 int main(){ 5 int mystery = 5; 6 int tmp = 0; 7 double data = 0.0;
  • 11. 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
  • 12. 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.
  • 13. 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;
  • 14. 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");
  • 15. 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 ) }