The following is a formal design for the density problem written using pseudocode. You need not write out your design solutions in this formal a manner; however, you SHOULD be at least sketching outlines of all your solutions.
Density: Main Program
Storage Specifications
Constants (specify global or local)
Variable
side, volume, mass : real
density: real
End Storage
Begin Density
output "Enter the length of the cube in cm "
input side
output "Enter the mass of the cube in grams"
input mass
volume <--- side * side * side
density <--- mass / volume
output "The density of a cube of side ", side,
"and mass", mass, " is ", density
end Density
The following is the C code for implementing the above very formal pseudocode outline for the problem of finding the density of a cube.
/******************************************************
* *
* Brenda Sonderegger CS120 *
* *
* Class Example - Density of a Cube Aug. 30, 1998 *
* *
* Description: This program will calculate the density*
* of a cube given the length of one side in cm *
* and the mass of the cube in grams. *
* *
******************************************************/
#include <stdio.h>
int main(void)
{
float side, mass, density, volume;
printf("\n\n\nEnter the length of a side in centimeters ");
scanf("%f", &side);
printf("\nEnter the mass of the cube in grams ");
scanf("%f", &mass);
volume = side * side * side;
density = mass/volume;
printf("\nFor a cube with side = %f and mass = %f,", side, mass);
printf(" the density is %f\n", density);
printf("\n\n\n");
return (0);
}