Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A) Write a program to produce a cube. Input from the user the length of a side.

ID: 2085626 • Letter: A

Question

A) Write a program to produce a cube. Input from the user the length of a side. Compute the area of the base of the cube, the surface area, and the volume. Display these values to the user.

B) Write a program to produce a cylinder. Input from the user the radius and height of the desired cylinder. Compute the area of the base, the surface area, and the volume. Display these values to the user.

C) Write a program to produce a square pyramid. Input the length of the side of the base and the height. Compute the area of the base, the surface area, and the volume. Display these values to the user.

Explanation / Answer

program to produce a cube

#include iostream
#include string
using namespace std;

int areaofcubecube(int lngth, int wdth = 25, int hght = 1);

int main()

{

string name;
int length;
int width;
int height;
int area;
int guessing1;
int guessing2;

cout This program computes the area. ;
cout This program also uses defaults. ;
cout Is your job to figure out the defaults. ;


cout Enter the number bw 1 & 10: ;
cin length;
cout Enter another number between 1 and 10: ;
cin width;
cout Enter a 3rd num bewteen 1 and 10: ;
cin height;

area = areaofcube(length, width, height);
cout First run area equals: area ;

area = areaofcube(length, width);
cout 2nd run area equals: area ;

area = areaofcube(length);
cout 3rd run area equals: area ;

do {
cout enter the default number for height? ;
cin guessing1;
cout enter the default number for width? ;
cin guessing2;
if ((guessing1 == 1) (guessing2 == 25)) cout answer is Correct! ;
else cout answer is Incorrect! ;
} while ((guessing1 != 1) (guessing2 != 25));

return 0;
}

int areaofcube(int length, int width, int height) {
return (length * width * height);
}

=======================================================================================

B) program to produce a cylinder

/* this code is to  find Volume and Surface Area of a Cylinder */

#include<stdio.h>

#include<math.h>

int main()

{

  float radius, height;

  // L = Lateral Surface Area of the Cylinder, T = Top Surface Area of the cylinder

  float sa,Volume, L, T;

  printf(" Request you to kindly enter radius and height of a cylinder ");

  scanf("%f %f", &radius, &height);

  sa = 2 * M-PI * radius * (radius + height);

  Volume = M-PI * radius * radius * height;

  L = 2 * M_PI * radius * height;

  T = M-PI * radius * radius;

  printf(" Surface Area of a cylinder = %.2f", sa);

  printf(" THE Volume of the Cylinder = %.2f", Volume);

  printf(" THE Lateral Surface Area of the cylinder = %.2f", L);

  printf(" THE Top / Bottom Surface Area of the cylinder = %.2f", T);

  

  return 0;

}

C) program to produce a square pyramid.

public class Pyramid

{

private double height;

private double baseLength;

...

}

This methods of computing the volume and surface area are now straightforward.

public double getVolume()

{

return height * baseLength * baseLength / 3;

}

public double theSurfaceArea()

{

double sideLength = Math.sqrt(height * height

+ baseLength * baseLength / 4);

return 2 * baseLength * sideLength;

}

There is a minor issue with the constructor. As described in Step 3, the parameters of the

constructor are identical to those of the instance variables:

public Pyramid(double height, double baseLength)

One answer is just to rename the constructor parameters:

public Pyramid(double aHeight, double aBaseLength)

{

height = aHeight;

baseLength = aBaseLength;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote