Show full handtracing of the following code and describe what it accomplishes.//
ID: 3804244 • Letter: S
Question
Show full handtracing of the following code and describe what it accomplishes.//The input file, dataofunknownorigin. In, contains the following data://1 2 2 4 3 6//-8 2 0 0 6 3 # include # including using namespace std; struct aThing {double one; double two;}; bool theseAreGreenEggsAndham (aThing, a Thing); aThing fromHorton (ifstreams); void drumingOnADrum (aThing); int main () {ifstream somewho; somewho. open ("detaofUnknownorigin.in"'); aThing thingone, thingTwo, thingThree; thingone = fromHorton (somewho); while (! Somewho. eof ()) {thingTwo = fromHorton (somewho); thingThree = fromHorton (somewho); if (theseAreGreenEggsAndHam (thingone, thingTwo, thingThree)) coutExplanation / Answer
each line of file contains 6 inpus, (3 points in 2D plane).
1) While file is not end
2) We are reading these 6 variable in 3 aThing struct variable.
3) Function theseAreGreenEggsAndHam checks if these three points are collinear, that is
if slope of (A, C) is same as slope of (A, B)
so, if (A.one - C.one) / (A.two - C.two) == (A.one - B.one) / (A.two - B.two)) return true;
else return false.
for the 1st input A(1, 2), B(2, 4), C(3, 6)
(A.one - C.one) / (A.two - C.two) = (1 - 3) / (2 - 6) = 2 / 4 = 1 / 2
(A.one - C.one) / (A.two - C.two) = (1 - 2) / (2 - 4) = 1 / 2
equal so, it returns false,
for the 2nd input A(-8, 2), B(0, 0), C(6, 3)
(A.one - C.one) / (A.two - C.two) = (-8 - 6) / (2 - 3) = -14 / -1 = 14 / 1
(A.one - C.one) / (A.two - C.two) = (-8 - 0) / (2 - 0) = -8/ 2 = -4 / 1
not equal, so it returns false
4) Print yes if lines are collinear, along with points
Print no if lines are not collinear, along with points
output:
sanjiv@sanjiv-VirtualBox:~$ g++ file1.cpp -o file1
sanjiv@sanjiv-VirtualBox:~$
sanjiv@sanjiv-VirtualBox:~$ ./file1
YES :1 2,2 4,3 6.
NO :-8 2,0 0,6 3.