Presentation is loading. Please wait.

Presentation is loading. Please wait.

solve the following problem...

Similar presentations


Presentation on theme: "solve the following problem..."— Presentation transcript:

1 solve the following problem...
Problem Session Working in pairs of two, solve the following problem...

2 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

3 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.

4 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

5 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 <<

6 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.

7 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; }

8 Summary Take the time to design your programs.
Object-centered design (OCD) makes problem-solving relatively easy!


Download ppt "solve the following problem..."

Similar presentations


Ads by Google