Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)

Post on 04-Jan-2016

217 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

Transcript

Programming with Visual C++: Concepts and Projects

Chapter 2B:Reading, Processing and Displaying Data

(Tutorial)

Tutorial: Addition Program• Problem Analysis– Create an addition program for double precision

numbers• Design– Sketch the interface– Identify required controls for input, processing

and output– Identify the variables to store two numbers and

their sum– Construct an algorithm for input, processing and

output

Programming with Visual C++: Concepts and Projects

Tutorial: Addition Program

• Development– Create the interface– Code the event handlers

• Testing

Programming with Visual C++: Concepts and Projects

Design

Programming with Visual C++: Concepts and Projects

• Interface sketch– Position each control object on the form as it

should look in the finished product– Name each control object

Design (continued)

Programming with Visual C++: Concepts and Projects

Design (continued)

Programming with Visual C++: Concepts and Projects

• Control table – List the control objects from the interface sketch – Identify their usage (input, processing, output) – List any events associated with them

Design (continued)

Programming with Visual C++: Concepts and Projects

• Data Table– Identify variables that will be required, by name– Assign a data type to each variable (double in this case)– Describe the purpose of the variable

Design (continued)

• After the interface has been designed algorithms must be written for each event handler

• This program has a button• The button has a click event handler requiring

an algorithm

Programming with Visual C++: Concepts and Projects

Design (continued)

• Algorithm1. Declare variables2. Read num13. Read num24. Compute sum5. Display sum

Programming with Visual C++: Concepts and Projects

Development

Programming with Visual C++: Concepts and Projects

• Create the actual interface based on the preliminary sketch you did in the Design stage– Place control objects on the form– Set the properties of these objects

Development (continued)

Programming with Visual C++: Concepts and Projects

Development (continued)

Programming with Visual C++: Concepts and Projects

Development (continued)

Programming with Visual C++: Concepts and Projects

Development (continued)

• The Development stage is where the code must be written for each event handler

• Before writing any Visual C++ code you must have a plan (an low-level algorithm)

• Ideally, from each line of the algorithm a Visual C++ statement can be constructed

Programming with Visual C++: Concepts and Projects

Development (continued)

Programming with Visual C++: Concepts and Projects

Development (continued)

Programming with Visual C++: Concepts and Projects

Development (continued)

• Comments should be added to your code at regular intervals

• Comments are ignored by the compiler• Comment syntax– Line comment

• Used for one line, or a portion of a line• //

– Block comment• Used for multiple lines of comments• /* … */

Programming with Visual C++: Concepts and Projects

Development (continued)

Programming with Visual C++: Concepts and Projects

Testing

• Run the program and enter various numbers into the Textboxes– Check the displayed result for accuracy

Programming with Visual C++: Concepts and Projects

Testing (continued)

Programming with Visual C++: Concepts and Projects

On Your Own

• Modify the interface– Rearrange the control objects

• Add more operations– Implement addition, subtraction, multiplication

and division– Additional buttons are required for each operation

Programming with Visual C++: Concepts and Projects

On Your Own (continued)

Programming with Visual C++: Concepts and Projects

On Your Own (continued)

Programming with Visual C++: Concepts and Projects

top related