solve the following problem...

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Advertisements

Parameter Passing Mechanisms Reference Parameters.
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
Computer Programming 1 Problem Solving and Software Engineering.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Programming is instructing a computer to perform a task for you with the help of a programming language.
Software Engineering 1 (Chap. 1) Object-Centered Design.
The switch Statement Selection Revisited. Problem Using OCD, design and implement a program that allows the user to perform an arbitrary temperature conversion.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
1 Programming and Problem Solving — Software Engineering (Read Chap. 2)
Programming and Problem Solving — Software Engineering (Read Chap. 2) 1.
Problem Solving and Software Engineering Chapter 1.
1 C++ Loop Statements Repetition Revisited. 2 Problem Using OCD, design and implement a function that, given a menu, its first valid choice, and its last.
Using Classes Classes and Function Members. Review We’ve seen that the iostream library provides the objects cin, cout and cerr: These objects were not.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Controlling Function Behavior Sequence, Selection and Repetition.
1 Chapter-01 Introduction to Software Engineering.
File I/O ifstreams and ofstreams Sections 11.1 &
File I/O ifstreams and ofstreams. Some istream Operations istream function Description cin >> ch; Extract next non-whitespace character from cin and store.
C++ Loop Statements Repetition Revisited. Problem Using OCD, design and implement a function that, given a menu, its first valid choice, and its last.
1 CS161 Introduction to Computer Science Topic #3.
1 Simple Functions Writing Reuseable Formulas. In Math Suppose f (x) = 2 x 2 +5Suppose f (x) = 2 x 2 +5 f(5)=?f(5)=? f(5) = 2* =55f(5) = 2*
1 An Example. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian Rules Football field, which.
1 An Example. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian Rules Football field, which.
1 Chapter-01 Introduction to Software Engineering.
File I/O 1 ifstreams and ofstreams Sections 11.1 & 11.2.
COSC1557: Introduction to Computing Haibin Zhu, PhD. Professor Department of Computer Science Nipissing University (C) 2014.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Chapter 2: Introduction to C++. Language Elements Keywords Programmer-defined symbols (identifiers) Operators Punctuation Syntax Lines and Statements.
Software Engineering Object-Centered Design. Problem Solving Does anyone scuba dive? Let’s solve this scuba-diving problem: Write a program that, given.
Practice Building Classes Modeling Objects. Problem Write a program that computes the Dean’s List (full-time students whose GPA 3.0), using a student.
1 8/31/05CS150 Introduction to Computer Science 1 Hello World!
Vectors One-Dimensional Containers. Problem A file contains a sequence of names and scores: Ann92 Bob84 Chris89... Using OCD, design and implement a program.
Problem Session Working in pairs of two, solve the following problem...
Simple Functions Writing Reuseable Formulas. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian.
Libraries Making Functions Reuseable. Review Last time, we wrote a program to compute the area and circumference of an ellipse. a a bb.
1 What is a Named Constant? A named constant is a location in memory that we can refer to by an identifier, and in which a data value that cannot be changed.
Chapter 3 – Variables and Arithmetic Operations. First Program – volume of a box /************************************************************/ /* Program.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
1 Chapter-01 Introduction to Software Engineering.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
Introduction to C++ (Extensions to C)
ifstreams and ofstreams
Chapter Topics The Basics of a C++ Program Data Types
Introducing Inheritance
Basic Elements of C++.
Functions Manipulating Files
Chapter 2 Assignment and Interactive Input
Writing Reuseable Formulas
Basic Elements of C++ Chapter 2.
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
Screen output // Definition and use of variables
Starting Out with C++: From Control Structures through Objects
Programming with Data Files
Code::Block vs Visual C++
No I/O is built into C++ instead, a library provides input stream and output stream Keyboard Screen executing program istream ostream 1.
Functions, Part 4 of 4 Topics: Coding Practice Reading: None
Lecture 8-2 : STL Iterators and Algorithms
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Life is Full of Alternatives
Arithmetic Operations
ifstreams and ofstreams
Modifying Objects Assignment operation Assignment conversions
Programming Strings.
Object-Centered Design
CSE Module 1 A Programming Primer
Presentation transcript:

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!