Programming and Problem Solving with Ada 95, Second Edition
Nell Dale Chip Weems John McCormick
Jones and Bartlett
Programming and Problem Solving with Ada 95 Second Edition
Programming and Problem Solving with Ada 95 Second Edition Nell Dale University of Texas, Austin
Chip Weems University of Massachusetts, Amherst
John McCormick University of Northern Iowa, Cedar Falls
World Headquarters Jones and Bartlett Publishers 40 Tall Pine Drive Sudbury, MA 01776 978-443-5000
[email protected] www.jbpub.com
Jones and Bartlett Publishers Canada 2406 Nikanna Road Mississauga, Ontario CANADA L5C 2WG
CHIEF EXECUTIVE OFFICER: Clayton Jones CHIEF OPERATING OFFICER: Don W. Jones, Jr. V.P., SALES AND MARKETING: Tom Manning V.P., COLLEGE EDITORIAL DIRECTOR: Brian L. McKean V.P., MANAGING EDITOR: Judith H. Hauck V.P., DESIGN AND PRODUCTION: Anne Spencer NATIONAL SALES MANAGER: Paul Shepardson SENIOR MARKETING MANAGER: Jennifer M. Jacobson SENIOR ACQUISITIONS EDITOR: J. Michael Stranz PRODUCTION EDITOR: Rebecca S. Marks DIRECTOR OF MANUFACTURING AND INVENTORY CONTROL: COVER DESIGN: Stephanie Torta TEXT DESIGN: George McLean COMPOSITION: PageMasters & Company PRINTING AND BINDING: Courier Companies COVER PRINTING: Courier Companies
Jones and Bartlett Publishers International Barb House, Barb Mews London W6 7PA UK
Therese Bräuer
Copyright 2000 by Jones and Bartlett Publishers, Inc. All rights reserved. No part of the material protected by this copyright notice may be reproduced or utilized in any form, electronic or mechanical, including photocopying, recording, or any information storage or retrieval system, without written permission from the copyright owner. Library of Congress Cataloging-in-Publication Data Dale, Nell B. Programming and problem solving with ADA / Nell Dale, Chip Weems, John McCormick.—2nd ed. p. cm. Includes index. ISBN: 0-7637-0792-9 1. Ada (Computer program language) I. Weems, Chip II. McCormick, John (John W.) III. Title. QA76.73.A35 D36 2000 005.13'3—dc21
Printed in the United States of America 04 03 02 01 00 10 9 8 7 6 5 4 3 2 1
99-049488
This book is dedicated to you, and to all of our students, for whom it was begun and without whom it could never have been completed. N. D. C. W. J. M. To Naomi, wife and best friend. J. M.
Contents P R E FA C E
xxi
AC K N O W LE D G M E NTS
1
O V E R V I E W O F P R O G R A M M I N G A N D P R O B LE M S O LV I N G Overview of Programming
xxix
1 2
What Is Programming? What Is a Computer? Background Information: Mainframes, Micros, and Minis How Do We Write a Program? Theoretical Foundations: Data Representation What Is a Programming Language?
2 3 9 13 18 19
Problem-Solving Techniques
23
Ask Questions Look for Things That Are Familiar Solve by Analogy Means-Ends Analysis Divide and Conquer The Building-Block Approach Merging Solutions How to Start Algorithmic Problem Solving
Software Engineering Programming at Many Scales
25 25 26 27 27 28 29 29 30
30 31
viii
Contents
The Ada Programming Language Background Information: The Origins of Ada Problem-Solving Case Study: A Company Payroll
33 35 37
Summary
42
Quick Check Answers Exam Preparation Exercises Programming Warm-up Exercises
2
A DA SYNTAX, S E M A NTI C S, A N D TH E P R O G R A M D E V E LO P M E NT P R O C E S S The Elements of Ada Programs
43 44 44 46
47 48
Syntax and Semantics Identifiers Matters of Style: Using