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

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

Jan 04, 2016

Download

Documents

Rhoda Dixon
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)

Programming with Visual C++: Concepts and Projects

Chapter 2B:Reading, Processing and Displaying Data

(Tutorial)

Page 2: 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

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

Tutorial: Addition Program

• Development– Create the interface– Code the event handlers

• Testing

Programming with Visual C++: Concepts and Projects

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

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

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

Design (continued)

Programming with Visual C++: Concepts and Projects

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

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

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

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

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

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

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

Design (continued)

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

Programming with Visual C++: Concepts and Projects

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

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

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

Development (continued)

Programming with Visual C++: Concepts and Projects

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

Development (continued)

Programming with Visual C++: Concepts and Projects

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

Development (continued)

Programming with Visual C++: Concepts and Projects

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

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

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

Development (continued)

Programming with Visual C++: Concepts and Projects

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

Development (continued)

Programming with Visual C++: Concepts and Projects

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

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

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

Development (continued)

Programming with Visual C++: Concepts and Projects

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

Testing

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

Programming with Visual C++: Concepts and Projects

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

Testing (continued)

Programming with Visual C++: Concepts and Projects

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

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

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

On Your Own (continued)

Programming with Visual C++: Concepts and Projects

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

On Your Own (continued)

Programming with Visual C++: Concepts and Projects