L14_structs_and_array_of_structs

L14_structs_and_array_of_structs - Structured Data types...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Structured Data types Data abstraction structs Structures Structures EECS 183 University of Michigan Lecture 17 structs && arrays of structs authored by: ML Dorf Array of structs Why Structured Types? Why Structured Types? Group together multiple simple items in a single object. Examples: Entries in the campus directory Last Name FootBall Game season opponent EECS 183 University of Michigan Lecture 17 structs && arrays of structs authored by: ML Dorf First Name Phone Number Address Major Cards: rank (A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3, 2) suit (Clubs, Diamonds, Hearts, Spades) more location win/lose/tie UM score opponent score 2006 Vanderbilt" W Picturing a single game Picturing a single game Ann Arbor, MI 27 Season Opponent Location Win/Lose/Tie M Score EECS 183 University of Michigan Lecture 17 structs && arrays of structs authored by: ML Dorf game1 7 UM Score Opponent Score 2003 Ohio State University" W Picturing a single game Picturing a single game Ann Arbor, MI 35 Season Opponent Location Win/Lose/Tie M Score EECS 183 University of Michigan Lecture 17 structs && arrays of structs authored by: ML Dorf game2 21 UM Score Opponent Score struct struct (ADT (ADT record record ) A struct lets you put related data together of mixed data types struct FootballType { EECS 183 University of Michigan Lecture 17 structs && arrays of structs authored by: ML Dorf int season; string opponent; string location; char W_L_T; int UM_score, opponent_score; }; Review: Using Review: Using structs structs Declared like simple types: FootballType game1, game2; Access components of a struct using the dot operator, for EECS 183 University of Michigan Lecture 17 structs && arrays of structs authored by: ML Dorf example game1.season = 2006; game1.opponent = Valderbilt; 2006 Vanderbilt" W Picturing a single football record Picturing a single football record Ann Arbor, MI 27 EECS 183 University of Michigan Lecture 17 structs && arrays of structs authored by: ML Dorf game1 7 Can use struct members just like any other variable of that type Can use struct members just like any other variable of that type // add one to game1's UM_score game1.UM_score++; // print a formatted title cout << setw(50) << game1.opponent; EECS 183 University of Michigan Lecture 17 structs && arrays of structs authored by: ML Dorf //assign game 1 to game2 // copies ALL members game2 = game1; Passing a struct by Value...
View Full Document

This note was uploaded on 02/12/2010 for the course EECS 183 taught by Professor Dorf during the Fall '08 term at University of Michigan.

Page1 / 30

L14_structs_and_array_of_structs - Structured Data types...

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

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