Question: This program is supposed to output the Calkin-Wilf tree. In other words it's supposed to show the fractions such as 1/1 and then next level

This program is supposed to output the Calkin-Wilf tree. In other words it's supposed to show the fractions such as 1/1 and then next level is 1/2 and 2/1 ect

Please help with this thanks.

The code towards the bottom is similar to what i need the code to look like it just needs to be put into c++ code and I'm having problems getting it into c++ code please help.

Please do not write it out I have a hard time reading other peoples hand writing please just type it out. thanks

write a c++ program that implements and tests the following two functions related to the Calkin-Wilf enumeration of the positive fractions:

Fraction cwfrac(int p); //Returns the fraction in position p in the Calkin-Wilf enumeration.

int cwpos(Fraction f); //Returns the position of the fraction f in the Calkin-Wilf enumeration.

This is the code that is similar to what I need it just needs to be in c++ code. Thanks

Define LibPub cwfrac(p)

Func

Local d,n,q,t,i,s

s := floor(log2(p))

t := 2s

n := 1

d := 1

q := p t

For i,1,s

t := t/2

If t q Then

n := n + d

q := q - t

Else

d := n + d

EndIf

EndFor

Return n/d

EndFunc

code for the fraction part of the assignment ^

Define LibPub cwpos(n,d)

Func

Local p,nn,dd,t

nn := n

dd := d

p := 0

t := 1

While nn/dd 1

If nn < dd Then

dd := dd - nn

Else

p := P + t

nn := nn - dd

EndIf

t := 2t

EndWhile

p := p + t

Return p

EndFunc

^code for the position of the fraction in the Calkin-Wilf tree

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!