Consider in a program segment that x 48 and y 172 z 150 I

Consider in a program segment that x = 4.8 and y = 17.2 z = 15.0 I 2 j = 7 k = 9 Trace all variable (Memory snapshot) along with showing any output at the appropriate points in the execution Table is a must here) while(I > 0){if (x > y) if (y

Solution

34.

#include <iostream>
#include <string>
#include <iomanip>

int main()
{
float x=4.8,y=17.2,z=15.0;
int i=2,j=7,k=9;
while(i>0)
{
if(x>y)
if(y<z){
k=k+1;
//std::cout << x << std::setw(3) << y << std::setw(3) << z << std::setw(3) << i << std::setw(3) << j << std::setw(3) << k;
std::cout << \"x=\" << x << \",y=\" << y << \",z=\" << z << \",i=\" << i << \",j=\" << j << \",k=\" << k << \"\ \";
}
else
j=j+3;
else
y=y-10;
x=x+10;
std::cout << \"x=\" << x << \",y=\" << y << \",z=\" << z << \",i=\" << i << \",j=\" << j << \",k=\" << k << \"\ \";
i=i-1;
//std::cout << x << std::setw(3) << y << std::setw(3) << z << std::setw(3) << i << std::setw(3)) << j << std::setw(3) << k;
std::cout << \"x=\" << x << \",y=\" << y << \",z=\" << z << \",i=\" << i << \",j=\" << j << \",k=\" << k << \"\ \";
}
}

Output:

x=14.8,y=7.2,z=15,i=2,j=7,k=9 x=14.8,y=7.2,z=15,i=1,j=7,k=9 x=14.8,y=7.2,z=15,i=1,j=7,k=10 x=24.8,y=7.2,z=15,i=1,j=7,k=10 x=24.8,y=7.2,z=15,i=0,j=7,k=10

35.

// Example program
#include <iostream>
#include <string>
using namespace std;


int main()
{
int r,h;
float vol,area;
do{
cout << \"Value of radius(in cm) r=?\ \";
cin >> r;
cout << \"Value of radius r= \" << r << \" cm\ \";
if((r>0)&&(r<50))
{
vol=(4/3)*3.14*r*r*r;
cout << \"Volume of sphere=\" << vol << \" cm3\ \";
}
else
if((r>0)&&(r>100))
{
cout << \"Value of height h=?\ \";
cin >> h;
area=(4*3.14*r*r)/h;
cout << \"Area of sphere=\" << area << \" cm2\ \";
cout << \"Value of height h=\" << h << \" cm\ \";
  
}
else
cout << \"r out of range\ \";
}while(r>0);
cout<<\"Program terminated\ \";
  

return 0;
}

Output:

Value of radius(in cm) r=? 45

Value of radius r= 45 cm

Volume of sphere=286132 cm3

Value of radius(in cm) r=? 105

Value of radius r= 105 cm

Value of height h=? 30

Area of sphere=4615.8 cm2

Value of height h=30 cm

Value of radius(in cm) r=? 60

Value of radius r= 60 cm

r out of range

Value of radius(in cm) r=? 0

Value of radius r= 0 cm

r out of range

Program terminated

 Consider in a program segment that x = 4.8 and y = 17.2 z = 15.0 I 2 j = 7 k = 9 Trace all variable (Memory snapshot) along with showing any output at the appr
 Consider in a program segment that x = 4.8 and y = 17.2 z = 15.0 I 2 j = 7 k = 9 Trace all variable (Memory snapshot) along with showing any output at the appr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site