Introduction to Programming in Turing

Total Page:16

File Type:pdf, Size:1020Kb

Introduction to Programming in Turing Introduction to Programming in Turing First Edition - Second Printing J. N. P. Hume Holt Software Associates, Inc. Toronto, Canada © 2001 by the author Toronto, Ontario, Canada All rights reserved. No part of this book may be reproduced, in any way or by any means, without permission of the author. Publisher: HOLT SOFTWARE ASSOCIATES INC. 203 College St., Suite 305 Toronto, Ontario, Canada M5T 1P9 (416) 978-6476 1-800-361-8324 http://www.holtsoft.com ISBN: 0-921598-42-4 First Edition - Second Printing Printed in Canada by the University of Toronto Press Table of Contents PREFACE ............................................................................................. IX ACKNOWLEDGMENTS....................................................................... XV 1 COMPUTING ESSENTIALS ...........................................................1 1.1 Introduction.............................................................................2 1.2 A Brief History of Computer Hardware ...................................2 1.3 A Brief History of Programming ..............................................7 1.3.1 A New Way of Organizing Large Programs.......13 1.4 What is a Computer?............................................................14 1.4.1 The Central Processing Unit..............................15 1.4.2 Memory..............................................................16 1.4.3 Output Devices ..................................................18 1.5 Number Systems: Decimal and Binary .................................18 1.6 Hardware and Networks .......................................................21 1.6.1 Different Kinds of Computers for Different Needs24 1.6.2 The Silicon Chip ................................................25 1.7 Software ...............................................................................27 1.7.1 Operating Systems ............................................27 1.7.2 Programming Environments ..............................27 1.7.3 Applications .......................................................28 1.8 The Social Impact of Computers ..........................................30 1.8.1 Employment.......................................................31 1.8.2 Privacy...............................................................32 1.8.3 Access to Information ........................................32 1.8.4 Leisure Activities................................................34 1.8.5 Illegal Activity.....................................................34 1.8.6 Computers: Good or Bad?.................................35 1.9 Exercises ..............................................................................36 1.10 Technical Terms .................................................................38 ii Introduction to Programming in Turing 2 THE TURING ENVIRONMENT .................................................... 43 2.1 Introduction .......................................................................... 44 2.2 The Editor Window............................................................... 44 2.2.1 Cut, Copy, and Paste........................................ 46 2.2.2 Undo ................................................................. 47 2.3 Saving Programs on Disk..................................................... 47 2.4 Running Programs ............................................................... 49 2.4.1 Input/Output Redirection ................................... 51 2.5 Indenting Programs and Syntax Coloring............................. 53 2.5.1 Indenting Programs........................................... 53 2.5.2 Syntax Coloring................................................. 53 2.6 Starting and Stopping the Environment ............................... 54 2.7 Opening an Existing Program .............................................. 55 2.8 Searching for Text in a File .................................................. 56 2.8.1 Finding Text in a File......................................... 57 2.8.2 Replacing Text in the File ................................. 58 2.9 Printing a Program ............................................................... 59 2.10 Example Turing Programs ................................................. 60 2.11 Exercises ........................................................................... 63 2.12 Technical Terms ................................................................ 64 3 PROGRAM DESIGN AND STYLE................................................ 66 3.1 Programming and Programmers.......................................... 67 3.2 Programming Style............................................................... 68 3.3 The Software Development Process.................................... 70 3.4 Procedure-Oriented Programming ....................................... 74 3.5 Exercises ............................................................................. 75 3.6 Technical Terms .................................................................. 76 4 SIMPLE PROGRAMS................................................................... 77 4.1 A One-Line Program ............................................................ 78 4.2 Changing the Program......................................................... 78 4.3 Substituting One String of Characters for Another............... 79 4.4 A Program that Computes ................................................... 79 4.5 Integers and Real Numbers ................................................. 80 4.6 Arithmetic Expressions......................................................... 81 4.7 Combining Calculations and Messages ............................... 82 4.8 Output of a Series of Items .................................................. 82 Table of Contents iii 4.9 A Series of Output Statements .............................................83 4.10 Exercises ............................................................................84 4.11 Technical Terms .................................................................86 5 VARIABLES AND CONSTANTS...................................................87 5.1 Storing Information in the Computer.....................................88 5.2 Declaring Variables...............................................................88 5.2.1 Names of Variables ...........................................89 5.3 Inputting Character Strings ...................................................89 5.3.1 Strings Containing Blanks..................................90 5.4 Mistakes in Programs ...........................................................91 5.5 Inputting Numbers ................................................................92 5.5.1 Mistakes in Data ................................................92 5.6 Inputting Real Numbers........................................................93 5.7 Constants .............................................................................94 5.8 Assignment of Values to Variables .......................................95 5.9 Understandable Programs....................................................96 5.10 Comments in Programs......................................................97 5.11 Exercises ............................................................................98 5.12 Technical Terms ...............................................................100 6 REPETITION...............................................................................103 6.1 Loops..................................................................................104 6.2 Conditional Loops...............................................................105 6.2.1 Comparisons ...................................................106 6.2.2 Comparing Strings...........................................107 6.2.3 An Example Conditional Loop .........................108 6.2.4 Another Conditional Loop ................................110 6.3 Counted Loops ...................................................................111 6.3.1 Counting in Multiples .......................................113 6.3.2 Indenting the Body of Loops............................114 6.3.3 Loops that Count Backwards...........................114 6.3.4 Counted Loop Examples .................................115 6.3.5 Counted Loops with Exits ................................117 6.4 Random Exit from Loop......................................................118 6.5 Compound Conditions ........................................................119 6.6 Exercises ............................................................................120 6.7 Technical Terms .................................................................124 iv Introduction to Programming in Turing 7 CHARACTER GRAPHICS.......................................................... 127 7.1 Character Locations in the Execution Window................... 128 7.2 Creating a Graphical Pattern with Characters.................... 129 7.2.1 Interactive Graphics ........................................ 130 7.2.2 Diagonal Lines and Patterns........................... 131 7.3 Drawing in Color................................................................. 133 7.4 Background Color .............................................................. 135 7.5 Hiding the Cursor ............................................................... 136 7.6 Animation with Graphics .................................................... 137 7.7 Controlling the Speed of Animation ................................... 138 7.8 Pausing for User Input ......................................................
Recommended publications
  • James Nairn Patterson Hume Fonds
    University of Toronto Archives and Records Management Services James Nairn Patterson Hume Fonds Prepared by: Marnee Gamble February 2008 © University of Toronto Archives and Records Management Services 2008 University of Toronto Archives J. N. Patterson Hume Fonds Table of Contents Biographical Sketch............................................................................................................ 2 Scope and Content .............................................................................................................. 3 Series 1 Biographical.................................................................................................... 4 Series 2 Education ........................................................................................................ 4 Series 2 Professional Correspondence.......................................................................... 4 Series 3 Publishing ....................................................................................................... 5 Series 4 Talks and Addresses ....................................................................................... 6 Series 5 Professional Activities .................................................................................... 7 Series 6 Teaching.......................................................................................................... 7 Series 7 Broadcasting and Film .................................................................................... 8 Series 8 Art and Letters Club.......................................................................................
    [Show full text]
  • Pat Hume Was Canada's Pioneer of Computer Programming
    OBITUARY Pat Hume was Canada’s pioneer of computer programming MICHAEL LENNICK (includes correction) Published Tuesday, Jul. 30 2013, 10:22 PM EDT Last updated Thursday, Aug. 01 2013, 4:48 PM EDT Pat Hume has been called a pioneer of Canadian computing – an oft-repeated description dating back to his 1952 work developing software for Canada’s first electronic computer, FERUT. Renowned as one of Canada’s innovators of computer science, he wrote his earliest programs out by hand on paper tape, which then had to be fed into the university’s massive vacuum tube computer for numerical processing. The former master of the University of Toronto’s Massey College, and writer and performer on some of the earliest episodes of the CBC show The Nature of Things, Prof. Hume was one of the university’s first faculty members to work with FERUT. In those days computers were vastly expensive, gymnasium-sized, vacuum-tube-laden monsters, designed and hand-built to order for the few universities and military organizations that could afford them. Having evolved from Second World War-era mechanical number-crunchers used to calculate gun trajectories, the first electronic computers, including ENIAC and MANIAC, were initially put to work processing subatomic reactions for the American hydrogen bomb project. Prof. Hume’s pioneering efforts were far more docile, directed toward the invention of programming and operating systems that would make the computer more of a universal tool. His research led directly to the development of some of the world’s earliest software, including TRANSCODE, a predecessor to modern computer programming.
    [Show full text]
  • A Better University Residence As of the Contest Start Date
    40065699 Onwards A president’s valediction / Eyes Everywhere When governments watch / First Contact Life beyond Earth? Duddy and Me The making of Ted Kotcheff / Grousing with Grace The art of complaint / Flights of Peace Aid from the air Remember when you had no cares in this world? 2013 41 . 1 .. 2013 Arbor Awards When no thanks are expected, they are often the most deserved. Congratulations to the 2013 winners of the Arbor Awards for volunteer service. Winston Churchill once said: “What is the use of living, if it be not to strive for noble causes and to make this muddled world a better place for those who will live in ALUMNI TERM LIFE INSURANCE it after we are gone.” From the recent grad who volunteers with Hong Kong alumni to the Second World War veteran who leads our Remembrance Day ceremony, Arbor Award It’s the same feeling you get, young or not so young, when you know winners epitomize this spirit of volunteering. Since 1989, you’re protected — especially when you have people who count on you. the Arbors have recognized extraordinary individuals Consider Alumni Term Life Insurance, whether you’re looking for new for their generosity and service to the U of T community. coverage or adding to an existing one, and enjoy exclusive low rates The 2013 recipients are no exception. We salute them for you and your family. No worries. We’ve got you covered. for their loyalty. We thank them for enriching the U of T experience for our students and faculty, alumni and staff .
    [Show full text]
  • Masseynews 2009-2010 • Life at Massey College, Toronto, Ontario
    L I F E A T M A s s E y c o L LE g E • 2 0 0 9 - 2 0 1 0 MasseyNews Julie Payette returns to Massey here are Many MeMoraBLe Photography by Anna Luengo evenings at Massey College, but few more memorablet than the one on november 5, 2009, when astronaut Julie payette, distinguished and loyal alumna (’88), visited with four of her co-pilots from Space Shuttle Endeavour, whom she introduced to the College community. the eagerly anticipated evening was described by Master John Fraser in his pre-event notice as a “complicated” one (see page 36), and it included pre-dinner drinks and a film in the Common room narrated live by the astronauts, as well as dinner in ondaatje hall. also that evening, the College’s silver teaspoon – which, as we had reported in our last issue, had travelled with Ms. payette into outer space in the summer of 2008 – was formally returned to us. Fittingly, kitchen staff member david Landaverde accepted the spoon back on behalf of the College. he had Julie Payette and Master John Fraser originally proposed the spoon as a suitable in the Common Room companion for the Endeavour trip and had gone, This huge crane appeared beside – sometimes along with then retiring pat Kennedy, to Cape College? it is the most special place i know and even above – the College this year as the Canaveral for the launch. the spoon, beautifully we are all lucky to be associated with it.” nine-storey Martin Prosperity Institute of the framed by the Canadian Space agency, now holds another special moment came when Senior Rotman School of Management, scheduled a special place of honour in the Common room.
    [Show full text]
  • Beatrice Helen Worsley: Canada's Female Computer Pioneer
    Beatrice Helen Worsley: Canada’s Female Computer Pioneer Scott M. Campbell University of Toronto When Beatrice Worsley died in 1972, Canada lost a computer pioneer and a witness to several great moments in computing history. This biography aims to provide insight into Worsley’s obscure, but remarkable and all too short, career. In the past decade, several authors have begun Oaxaca, which her grandparents had estab- to explore the history of computing in Canada. lished in the 1850s. Around 1917, the mill was A special 1994 issue (vol. 16, no. 2, April–June) destroyed by rebels, and the family moved to of the IEEE Annals of the History of Computing El Salto where Joel rose to general manager of was dedicated to the theme, and John the Rio Grande group’s CIMSA mills. Charles Vardalas’s book, The Computer Revolution in and Beatrice were home schooled by their Canada, (MIT Press, 2001) examined the devel- mother, and the children spent many years iso- opment of a Canadian computer industry. lated and physically cut off from the surround- When discussions turn to early developments ing community for general safety reasons. They at the University of Toronto, one name that fre- learned Spanish, although not fluently. quently appears is Beatrice Worsley. Although many other computer pioneers still recall her Early days quiet personality, complete accounts of her In 1929, Joel and his wife left Mexico for career and life are more disjoint. Toronto, Canada, primarily for their children’s In fact, her experiences and accomplishments education. In Toronto, Charles attended Upper were remarkable.
    [Show full text]
  • Massey News2017
    Massey 2017 2018 News Principal Segal ending five years of service 2 2017 CBC Massey Lectures 7 Celebrating Massey’s partnership with First Nations peoples 17 Symposium addresses the social implications of data-driven decision making 21 Connecting with fellow activists at Massey College 27 From the Don of Hall 47 Life at Massey College What's inside From the Principal 1 MASSEY COLLEGE is a graduate students’ residential community Degrees awarded 1 affiliated with, but independent from, the University of Toronto. Principal’s Announcement 2 It provides a unique, congenial, and intellectual environment Announcing new title 4 Contact us Junior Fellows’ Lecture Series 4 for graduate students of distinguished ability in all disciplines MASSEY COLLEGE to share in a rich and stimulating community. News from the Masters Emeriti 5 4 Devonshire Place Massey Grand Rounds 6 Toronto, Ontario, Canada M5S 2E1 CBC Massey Lectures 7 Gala Dinner: Carol Off 8 Y SINCEREST THANKS to the many < masseycollege.ca > Press Club evenings 8 From the Massey community members and friends < www.facebook.com/MasseyCollege > William Southam Journalism Fellows 9 Editor who contributed to this issue in one way M THE PRINCIPAL Journalism Outreach update 10 or another — the Principal and the Officers of the College; Masters Emeriti John Pearson’s four faces of peace 10 Hugh Segal Fraser and Ann Saddlemyer; Emily Mockler, Programs and Events Coordinator; Corporation Fellows’ Gaudy Night 11 Tel: 416-978-8448 Library report 12 Darlene Naranjo, Catering Manager; Elena Ferranti,
    [Show full text]
  • Beatrice Helen Worsley: Canada's Female
    Beatrice Helen Worsley: Canada’s Female Computer Pioneer Scott M. Campbell University of Toronto When Beatrice Worsley died in 1972, Canada lost a computer pioneer and a witness to several great moments in computing history. This biography aims to provide insight into Worsley’s obscure, but remarkable and all too short, career. In the past decade, several authors have begun Oaxaca, which her grandparents had estab- to explore the history of computing in Canada. lished in the 1850s. Around 1917, the mill was A special 1994 issue (vol. 16, no. 2, April–June) destroyed by rebels, and the family moved to of the IEEE Annals of the History of Computing El Salto where Joel rose to general manager of was dedicated to the theme, and John the Rio Grande group’s CIMSA mills. Charles Vardalas’s book, The Computer Revolution in and Beatrice were home schooled by their Canada, (MIT Press, 2001) examined the devel- mother, and the children spent many years iso- opment of a Canadian computer industry. lated and physically cut off from the surround- When discussions turn to early developments ing community for general safety reasons. They at the University of Toronto, one name that fre- learned Spanish, although not fluently. quently appears is Beatrice Worsley. Although many other computer pioneers still recall her Early days quiet personality, complete accounts of her In 1929, Joel and his wife left Mexico for career and life are more disjoint. Toronto, Canada, primarily for their children’s In fact, her experiences and accomplishments education. In Toronto, Charles attended Upper were remarkable.
    [Show full text]
  • Science Culture: Where Canada Stands
    SCIENCE CULTURE: WHERE CANADA STANDS Expert Panel on the State of Canada’s Science Culture Science Advice in the Public Interest SCIENCE CULTURE: WHERE CANADA STANDS Expert Panel on the State of Canada’s Science Culture ii Science Culture: Where Canada Stands THE COUNCIL OF CANADIAN ACADEMIES 180 Elgin Street, Suite 1401, Ottawa, ON, Canada K2P 2K3 Notice: The project that is the subject of this report was undertaken with the approval of the Board of Governors of the Council of Canadian Academies. Board members are drawn from the Royal Society of Canada (RSC), the Canadian Academy of Engineering (CAE), and the Canadian Academy of Health Sciences (CAHS), as well as from the general public. The members of the expert panel responsible for the report were selected by the Council for their special competencies and with regard for appropriate balance. This report was prepared for the Government of Canada in response to a request from the Minister of State (Science and Technology) on behalf of the Canada Science and Technology Museums Corporation, Natural Resources Canada, and Industry Canada. Any opinions, findings, or conclusions expressed in this publication are those of the authors, the Expert Panel on the State of Canada’s Science Culture, and do not necessarily represent the views of their organizations of affiliation or employment. Library and Archives Canada Cataloguing in Publication Science Culture : Where Canada Stands / The Expert Panel on the State of Canada’s Science Culture. Issued also in French under title: Culture scientifique. Includes bibliographical references and index. Issued in print and electronic formats. ISBN 978-1-926558-91-2 (bound).
    [Show full text]