solve the following problem... Problem Session Working in pairs of two, solve the following problem...
Problem Using OCD, design and implement a program that, given the height, width, and depth of a rectangular solid, computes and displays its volume and surface area. depth height width
OCD: Behavior Our program should display on the screen its purpose, plus a prompt for the height, width, and depth of a rectangular solid, which it should then read from the keyboard. It should then compute and display the volume and surface area of that rectangular solid, along with a descriptive label.
OCD: Objects Description Type Kind Name screen ostream varying cout purpose string constant -- prompt string constant -- height double variable height width double variable width depth double variable depth keyboard istream varying cin volume double variable volume surface area double variable surfaceArea
OCD: Operations Description Predefined? Library? Name display strings yes iostream << read doubles yes iostream >> compute volume no -- -- - multiply doubles yes built-in * compute s.area no -- -- - multiply doubles yes built-in * - add doubles yes built-in + display doubles yes iostream <<
OCD: Algorithm 0. Display via cout the purpose of the program plus a prompt for the height, width and depth of a rectangular solid. 1. Read height, width and depth from cin. 2. Compute volume = height * width * depth. 3. Compute surfaceArea = 2.0 * (height * width + height * depth + width * depth). 4. Display volume and surfaceArea with descriptive labels.
Coding #include <iostream> using namespace std; int main() { cout << “\nTo compute the volume and surface area” << “\n of a rectangular solid, enter its” << “\n height, width, and depth: “; double height, width, depth; cin >> height >> width >> depth; double volume = height * width * depth; double surfaceArea = 2.0 * (height * width + width * depth + height * depth); cout << “\nThe volume is “ << volume << “ and the surface area is “ << surfaceArea << endl; }
Summary Take the time to design your programs. Object-centered design (OCD) makes problem-solving relatively easy!