CSE 305 Programming Languages Spring, 2010 Homework 5 Maximum Points: 24 Due 10:30 AM, Friday, February 26, 2010

Similar documents
Example. Section: PS 709 Examples of Calculations of Reduced Hours of Work Last Revised: February 2017 Last Reviewed: February 2017 Next Review:

Scheduling. Scheduling Tasks At Creation Time CHAPTER

INFORMATION TECHNOLOGY SPREADSHEETS. Part 1

Basic Device Management

Note: The enumerations range from 0 to (number_of_elements_in_enumeration 1).

September 2015 Calendar This Excel calendar is blank & designed for easy use as a planner. Courtesy of WinCalendar.com

AIMMS Function Reference - Date Time Related Identifiers

Calendar PPF Production Cycles Non-Production Activities and Events

Sequential Search (Searching Supplement: 1-2)

Calendar Excel Template User Guide

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Institute For Arts & Digital Sciences SHORT COURSES

Arrays and Pointers (part 2) Be extra careful with pointers!

Exercises Software Development I. 02 Algorithm Testing & Language Description Manual inspection, test plan, grammar, metasyntax notations (BNF, EBNF)

MBTA Semester Pass Program User Guide

Complex data structures. Cedric Saule

Schedule/BACnet Schedule

YEAR 8 STUDENT ASSESSMENT PLANNER SEMESTER 1, 2018 TERM 1

ControlLogix/Studio 5000 Logix Designer Course Code Course Title Duration CCP143 Studio 5000 Logix Designer Level 3: Project Development 4.

CALENDAR OF FILING DEADLINES AND SEC HOLIDAYS

Arrays and Pointers (part 2) Be extra careful with pointers!

Common Mistakes with Functions. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

LIHP Monthly Aggregate Reporting Instructions Manual. Low Income Health Program Evaluation

KENYA 2019 Training Schedule

Lesson 1: Creating a Worksheet and a Chart Microsoft Excel 2016 IN THIS CHAPTER, YOU WILL LEARN HOW TO

SOUTH DAKOTA BOARD OF REGENTS. Board Work ******************************************************************************

name name C S M E S M E S M E Block S Block M C-Various October Sunday

QI TALK TIME. Run Charts. Speaker: Dr Michael Carton. Connect Improve Innovate. 19 th Dec Building an Irish Network of Quality Improvers

Why arrays? To group distinct variables of the same type under a single name.

Arrays. What if you have a 1000 line file? Arrays

Nortel Enterprise Reporting Quality Monitoring Meta-Model Guide

typedef int Array[10]; String name; Array ages;

B.2 Measures of Central Tendency and Dispersion

Homework 1. Reading. Problems. Handout 3 CSCI 334: Spring, 2012

by the evening of Tuesday, Feb 6

Undergraduate Admission File

Programming Date and Time APIs

Table of Contents 1 Basic Configuration Commands 1-1

TEMPLATE CALENDAR2015. facemediagroup.co.uk

CSE 115. Introduction to Computer Science I

Aerospace Software Engineering

Student Information Systems (SIS) Updates

%Addval: A SAS Macro Which Completes the Cartesian Product of Dataset Observations for All Values of a Selected Set of Variables

Homework 1. Notes. What To Turn In. Unix Accounts. Reading. Handout 3 CSCI 334: Spring, 2017

CS349/SE382 A1 C Programming Tutorial

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Arrays. Arrays (8.1) Arrays. One variable that can store a group of values of the same type. Storing a number of related values.

DATE OF BIRTH SORTING (DBSORT)

Zodiac Link QUICKSTART GUIDE

Year 1 and 2 Mastery of Mathematics

Backup Exec Supplement

CSE 142, Autumn 2007 Midterm Exam, Friday, November 2, 2007

HP Project and Portfolio Management Center

Conditional Formatting

1 of 8 10/10/2018, 12:52 PM RM-01, 10/10/2018. * Required. 1. Agency Name: * 2. Fiscal year reported: * 3. Date: *

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Read and fill in this page now

Important Upcoming Rotary Dates FY July 2017-June 2018 ( )

SOUTH DAKOTA BOARD OF REGENTS PLANNING SESSION AUGUST 8-9, Below is a tentative meeting schedule for the Board meetings in 2013:

Substitute Quick Reference (SmartFindExpress Substitute Calling System and Web Center)

Crystal Reports. Overview. Contents. Cross-Tab Capabilities & Limitations in Crystal Reports (CR) 6.x

Exercise: Insert New Blank Worksheet

SOUTH DAKOTA BOARD OF REGENTS. Board Work ******************************************************************************

Animals Alphabet. Price: 3.00 (incl. VAT) Cross Stitch Charts. da: Pensieri Animali. Modello: SCHPEA-alphabet_DD

ID-AL - SCHEDULER V2.x - Time-stamped & dated programming Scheduler - Manual SCHEDULER. V2.x MANUAL

What s next? Are you interested in CompTIA A+ classes?

MAP OF OUR REGION. About

TREES Lecture 12 CS2110 Spring 2019

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Homework 3 (document version 1.2) Multi-threading in C using Pthreads

Warmup January 9th, What is the value of the following C expression? 8*9 % 10/ 2

MONITORING REPORT ON THE WEBSITE OF THE STATISTICAL SERVICE OF CYPRUS DECEMBER The report is issued by the.

VTC CO-OP GOOGLE QUALIFICATIONS PARAMETERS & REIMBURSEMENT DOCUMENTATION HOW-TO

ADVANCED ALGORITHMS TABLE OF CONTENTS

Moody Radio Network 1st Quarter data dates are February, th Quarter Reports are due to SoundExchange by Tuesday, 15-May, 2018

COMPUTER TRAINING CENTER

Friday, September 16, Lab Notes. Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week

Drawing Courses. Drawing Art. Visual Concept Design. Character Development for Graphic Novels

EEN118 22nd November These are my answers. Extra credit for anyone who spots a mistike. Except for that one. I did it on purpise.

09/08/2017 CS2530 INTERMEDIATE COMPUTING 9/8/2017 FALL 2017 MICHAEL J. HOLMES UNIVERSITY OF NORTHERN IOWA TODAY S TOPIC: Exceptions and enumerations.

CSE413 Midterm. Question Max Points Total 100

CS11002 Programming and Data Structures Spring Introduction

Other conditional and loop constructs. Fundamentals of Computer Science Keith Vertanen

Class Information ANNOUCEMENTS

Introduction to Computing Lecture 05: Selection (continued)

MAP OF OUR REGION. About

This homework is due by 11:59:59 PM on Thursday, October 12, 2017.

Cambridge English Dates and Fees for 2018

EECE.2160: ECE Application Programming Spring 2018 Programming Assignment #6: Using Arrays to Count Letters in Text Due Wednesday, 4/4/18, 11:59:59 PM

BHARATI VIDYAPEETH`S INSTITUTE OF MANAGEMENT STUDIES AND RESEARCH NAVI MUMBAI ACADEMIC CALENDER JUNE MAY 2017

CRIME ANALYSIS SACRAMENTO COUNTY SHERIFF S DEPARTMENT

View a Students Schedule Through Student Services Trigger:

Chapter 6 Reacting to Player Input

2018 Pummill Relay problem statement

CS 1803 Pair Homework 4 Greedy Scheduler (Part I) Due: Wednesday, September 29th, before 6 PM Out of 100 points

Table of Contents 1 Basic Configuration Commands 1-1

CLOVIS WEST DIRECTIVE STUDIES P.E INFORMATION SHEET

San Diego Unified School District Substitute Reference Guide

NetworX Series. NX-507E RELAY EXPANDER NX-508E OUTPUT EXPANDER Installation and Startup

just a ((somewhat) safer) dialect.

Transcription:

CSE 305 Programming Languages Spring, 2010 Homework 5 Maximum Points: 24 Due 10:30 AM, Friday, February 26, 2010 Professor Shapiro February 12, 2010 Write the answers in a file named hw5.txt. Put your name and user name at the top of the file, and submit the file, using the UNIX command, submit cse305 hw5.txt. You are also to submit five additional files as instructed below. 1. (4) You may wonder if there is any advantage to using a symbol rather than a string; for example whether there s any difference in Ruby between using the string "jpbona" vs. the symbol :jpbona. Both, after all, are objects. One question is, are multiple occurrences of the same string automatically stored in the same memory location; what about multiple occurrences of the same symbol. If two strings are stored in the same memory location, they may be tested for pointer (reference) equality, but if they re in different locations, the equality tester would have to compare them character by character. Use irb, the interactive Ruby shell to investigate this issue. You start irb by entering irb as a Unix command, and leave it by entering quit to the irb prompt. The Ruby pointer equality method is equal?. For example, <timberlake:test:1:176> irb irb(main):001:0> 4.equal?(3+1) => true irb(main):002:0> quit <timberlake:test:1:177> (a) (3) Put in your submission file a transcript of a run of irb in which you investigate whether two occurrences of the same string are stored in the same memory location, and whether two occurrences of the same symbol are. Also put your input lines in a file named hw5.rb, and submit that file. (b) (1) What do you conclude about the question from this test? 1

2. (7) Can you use strings as the cases in a C switch statement? Is the following C program legal? What does it do? #include <stdio.h> char* dayschild(char* d) // Rhyme from Lisa Yannucci, Mama Lisa s World, // http://www.mamalisa.com/?t=hes&p=1420&l=s, 2009. switch(d) case "Sunday": return " Sundays child is full of grace."; case "Monday": return "Monday s child is full in the face."; case "Tuesday": return "Tuesday s child is solemn and sad."; case "Wednesday": return "Wednesday s child is merry and glad."; case "Thursday": return "Thursday s child is inclined to thieving."; case "Friday": return "Friday s child is free in giving."; case "Saturday": return "Saturday s child works hard for a living."; default: return "Unknown day s child is a mystery."; int main() char* d = "Wednesday"; printf("%s\n", dayschild(d)); return 0; (a) (2) Try to compile this program (using gcc -Wall...), and, if it compiles, run it. Insert a transcript of the compile and run (if it runs) here in your submission file. (b) (3) Change the program to use an enumeration type instead of strings for the days. Put that changed program in a file named dayschild.c and submit it. Also insert your changed program here in the submission file. (c) (2) Compile this program (using gcc -Wall...) and run it. Insert a transcript of the successful compile and run here in your submission file. 2

3. (5) One use of jagged arrays is to store triangular arrays without wasting space on the empty cells. Just as maps (associative arrays) are a generalization of arrays, so are jagged maps, which are maps of maps, a generalization of jagged arrays, and we could use jagged maps to store triangular maps. A common use of triangular maps is for mileage charts. For example, the following is a small mileage chart 1 showing distances between a few US cities: Buffalo Chicago Los Angeles New York Atlanta 859 674 2182 841 Buffalo 522 2554 372 Chicago 2054 802 Los Angeles 2786 To use this chart to find the distance between two cities, take the alphabetically smaller city, and read across its row until you find the column of the other city. The number you find there is the distance in miles between the two cities. Write a Python program to read the names of two cities and print the distance between them. You should represent the mileage chart as a jagged dictionary (Python s name for an associative array), using strings of city names as the keys. Here s an example run of such a program, showing what your program should be able to do: <timberlake:test:1:206> python mileage.py Starting city (bye to quit): Buffalo Destination city: New York It is 372 miles from Buffalo to New York. Starting city (bye to quit): Los Angeles Destination city: Chicago It is 2054 miles from Los Angeles to Chicago. Starting city (bye to quit): Atlanta Destination city: Baltimore I don t know how far it is between Atlanta and Baltimore. Starting city (bye to quit): Albany Destination city: Buffalo I don t know anything about Albany. Starting city (bye to quit): Good bye. bye Note that the basic structure of this program is the same as that of echo.py. (a) (3) Put your program in a file named mileage.py and submit it. Also put it here in your submission file. (b) (2) Put a transcript of your run of your program here in your submission file. 1 Data taken from Rand McNally Road Atlas & Major City Guide, 1994 3

4. (5) Fortran 77 and earlier versions of Fortran do not have pointers. However, pointers may be simulated by parallel arrays. Edit the following program to replace the question marks (? ) with appropriate integers so that when you compile and run the program, it prints the 12 months in the correct order starting with "January". Copy the edited program into a file named months.f. Compile the program with the Unix command f77 -o months months.f and then run it with the Unix command./months Here s the program: Program months Character*9 monname(12) Integer i, firstmonth, nextmonth(12) Data monname/"november", "April", "September", "May", C "December", "June", "February", "October", C "January", "July", "March", "August" / Data firstmonth/?/ Data nextmonth/?,?,?,?,?,?,?,?,?,?,?,?/ i = firstmonth 10 If (i.ne. 0) Then Print *, monname(i) i = nextmonth(i) Goto 10 EndIf End (a) (3) Submit your months.f file, and put it here in your submission file. (b) (2) Put a transcript of your run of your program here in your submission file. 4

5. (3) The Lisp function mapcar takes a first argument of type function, and n additional additional arguments, which must be lists, and where n is the number of argments that the function takes. mapcar returns a list of the value of the function applied to the first element of each list, the second element of each list, etc. Here is an example of an interactive run of Common Lisp in which mapcar is used to compute a list of sums: <timberlake:test:1:208> composer International Allegro CL Enterprise Edition 8.1 [Linux (x86)] (Aug 21, 2009 10:13) Copyright (C) 1985-2007, Franz Inc., Oakland, CA, USA. All Rights Reserved. This development copy of Allegro CL is licensed to: [4549] University at Buffalo ; Autoloading for package "asdf": ; Fast loading /util/acl81/code/asdf.fasl ;; Optimization settings: safety 1, space 1, speed 1, debug 2. ;; For a complete description of all compiler switches given the ;; current optimization settings evaluate (explain-compiler-settings). ;;--- ;; Current reader case mode: :case-sensitive-lower cl-user(1): (mapcar # + (1 2 3 4) (5 6 7 8)) (6 8 10 12) cl-user(2): :ex ; Exiting <timberlake:test:1:209> Put a transcript of an interactive Common Lisp run in which you use mapcar to compute a list of averages here in your submission file. (Hint: the form you have Lisp evaluate will look like (mapcar (1 2 3 4) (5 6 7 8)) but with the blank filled in with a lambda expression.) Also put that input in a file called hw5.cl, and submit it. 5