Chapter 6

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter 6 Chapter Writing a Program Bjarne Stroustrup www.stroustrup.com/Programming Abstract Abstract This lecture and the next describe the process This of designing a program through the example of a simple “desk calculator.” simple Stroustrup/Programming 2 Overview Overview Some thoughts on software development The idea of a calculator Using a grammar Expression evaluation Program organization Stroustrup/Programming 3 Building a program Building Analysis Refine our understanding of the problem Design Create an overall structure for the program Implementation Think of the final use of our program Write code Debug Test Go through these stages repeatedly Stroustrup/Programming 4 Writing a program: Strategy Writing What is the problem to be solved? Is the problem statement clear? Is the problem manageable, given the time, skills, and tools available? Try breaking it into manageable parts Do we know of any tools, libraries, etc. that might help? Build a small, limited version solving a key part of the problem To bring out problems in our understanding, ideas, or tools Possibly change the details of the problem statement to make it manageable If that doesn’t work Yes, even this early: iostreams, vector, etc. Yes, iostreams, vector Throw away the first version and make another limited version Keep doing that until we find a version that we’re happy with Build a full scale solution Ideally by using part of our initial version Stroustrup/Programming 5 Writing a program: Example Writing I’ll build a program in stages, making lot of I’ll “typical mistakes” along the way “typical Even experienced programmers make mistakes Designing a good program is genuinely difficult It’s often faster to let the compiler detect gross mistakes It’s than to try to get every detail right the first time than Lots of mistakes; it’s a necessary part of learning Concentrate on the important design choices Building a simple, incomplete version allows us to Building experiment and get feedback experiment Good programs are “grown” Stroustrup/Programming 6 A simple calculator simple Given expressions as input from the keyboard, Given evaluate them and write out the resulting value evaluate For example Expression: 2+2 Result: 4 Expression: 2+2*3 Result: 8 Expression: 2+3-25/5 Result: 0 Let’s refine this a bit more … Stroustrup/Programming 7 Pseudo Code Pseudo A first idea: int main() { variables while (get a line) { analyze the expression evaluate the expression print the result } } // pseudo code // pseudo // what’s a line? // what’s // what does that mean? // what How do we represent...
View Full Document

This note was uploaded on 02/18/2012 for the course CSCE 121 taught by Professor Walter daugherity during the Fall '09 term at Texas A&M.

Ask a homework question - tutors are online