CS161_Topic#15

CS161_Topic#15 - CS161 CS161 Introduction to Computer...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS161 CS161 Introduction to Introduction to Computer Science Computer Science Topic #15
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS161 Topic #15 2 Today in CS161 Structures What is a structure Why would we use them How do we define structures How do we define variables of structures How do we define arrays of structures How do we pass structures as arguments Programming Questions?
Background image of page 2
CS161 Topic #15 3 What is a Structure A structure is a way for us to group different types of  data together under a common name With an array, we are limited to having only a single type  of data for each element. .. – think of how limiting this would be if we wanted to  maintain an inventory – we’d need a separate array for each product’s name,  another for each product’s price, and yet another for  each barcode!
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS161 Topic #15 4 What is a Structure • With a structure, on the other hand, we can group  each of these under a common heading So, if each product can have a description, a price, a cost, and a barcode. ...a single structure entity can consist of an array of characters for the description, two floats for the price and cost, and an int for the barcode Now, to represent the entire inventory we can have an array of these “products”
Background image of page 4
CS161 Topic #15 5 Why would we use a Structure • Some people argue that with C++ we no longer  need to use the concept of structures • And, yes, you can do everything that we will be  doing with structures, with a “class” (which we 
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

CS161_Topic#15 - CS161 CS161 Introduction to Computer...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online