CS1371 Introduction to Computing for Engineers - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

CS1371 Introduction to Computing for Engineers

Description:

Homework 4 Posted due this Thursday. START THIS ONE EARLY!!!! Reading: ... first album's artist is 'usher' ' album(1).artist = 'usher' STRUCTURES. 7 ... – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 13
Provided by: david3049
Category:

less

Transcript and Presenter's Notes

Title: CS1371 Introduction to Computing for Engineers


1
CS1371Introduction to Computing for Engineers
  • Inhomogeneous Data
  • Structs (ah, much better)

2
Administrivia
  • Check announcements page!!
  • ("When are finals?")
  • Homework 4 Posted due this Thursday.
  • START THIS ONE EARLY!!!!
  • Reading
  • Cell Arrays Smith, Chapter 8
  • Structs Smith, Chapter 9

3
Some Useful Functions
  • fix, floor, mod, ceil

4
Show Useful Functions
  • fix, floor, mod, ceil
  • do HELP CEIL

5
Remember simple but stupid idea
  • elm 3,2,1,35000,'Jones')
  • Or even
  • elm1 3,2,1,35000,'Jones')
  • elm2 4,2,4,55000,'Smith')
  • These are called "Cells" or "Cell arrays"
  • You WILL read about them and you WILL use them
    (see HW4) but they are sort of a kludge.

6
New Example Simple Database
  • Suppose wanted to be able to store your CD
    collection database
  • Variety of data genre, artist, title, year,
    stars, price
  • Variety of types
  • Stars should be 4 not ''
  • Would like to say something like
  • " first album's artist is 'usher' "
  • album(1).artist 'usher'

STRUCTURES
7
Why are struct(ure)s so much better
  • Structs use the "name" of a "field" to access the
    dataso the name can be useful things like
    'artist'. Compare to "3rd element"
  • Structs can be thought of as a "data structure"
    organizes the data in a logical way that can be
    applied many times.
  • Structs can be put into arrays as long as the
    structs all have the same, uh, structure. That
    is, the same fields. This makes having many
    "objects" of the same type easy.

8
Simple struct
  • First do simple example
  • myhouse.people 5
  • myhouse.income 150000
  • myhouse.name 'Jones'
  • Do yourhouse
  • houses(1) myhouse
  • houses(2 ) yourhouse
  • Now have an array of houses.

9
Now build CDs
  • Imagine a function makeCD(gen, art, titl, yr,
    strs, prc)
  • function CD makeCD( gen, art, titl, yr, strs,
    prc )
  • build CD record
  • CD makeCD( gen, art, titl, yr, strs, prc )
  • where gen is the genre ...
  • CD.genre gen
  • CD.artist art
  • CD.title titl
  • CD.year yr
  • CD.stars strs
  • CD.price prc

10
Create a collection
  • Look at and execute buildCDs.m
  • Look at the variable collection
  • Now let's think about using this to get at
    things.

11
Getting at all the fields
  • function printAll(CDs)
  • flds fieldnames(CDs(1))
  • for CD CDs
  • str '!!'
  • for index 1length(flds)
  • attrib fldsindex
  • str str ' ' strValue(CD.(attrib))
  • end
  • disp(str)
  • end

12
Rest of Mess with
  • Traversal
  • disp('all CDs')
  • printCDs(collection, 'artist')
  • pause
  • Filter
  • noRay filterCDs( collection, 'artist',
    'Charles, Ray' )
  • disp('CDs with no Ray Charles')
  • printCDs(noRay,'artist')
  • Map
  • addedCDs addValue(noRay)
  • printCDs(addedCDs, 'value')
  • Fold
  • theCD bestValue(addedCDs)
  • Search
Write a Comment
User Comments (0)
About PowerShow.com