MIS 120 Structures.

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

1 Records C++ Structs Chapter 14 2 What to do with records?  Declaring records  Accessing records  Accessing the field of a record  What is a union?
1 Chapter 11 Introducing the Class Pages ( )
Structure.
Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 10: Records ( structs )
Chapter 11: Records (structs)
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 11: Records (structs)
EGR 2261 Unit 10 Records (structs)
Chapter 10: Records (structs)
Structured Data Types array array union union struct struct class class.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 11: Records ( struct s)
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 10: Records ( struct s)
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 11. The Struct Data Type.
Chapter 10: Records (structs)
Edited from Powerpoint Slides provided by Thomson Learning
Arrays & Structures II Chapter 9. 2 Organizing Heterogeneous Data  Arrays allow a programmer to organize values of the same type  Homogeneous data 
1 Chapter 11 Structured Data. 2 Topics 10.1 Abstract Data Types 10.2 Combining Data into Structures 10.3 Accessing Structure Members 10.4 Initializing.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11: Structured Data.
Structured Data Chapter 11. Combining Data Into Structures Structure: C++ construct that allows multiple variables to be grouped together Format: struct.
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
11/5/2016CS150 Introduction to Computer Science 1 Announcements  Assignment 6 due on Wednesday, December 3, 2003  Final Exam on Tuesday, December 9,
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 11: Records ( struct s)
Multiple Items in one Data Object Arrays are a way to store more than one piece of data in a data object, provided that all the data is of the same type.
1 11/30/05CS150 Introduction to Computer Science 1 Structs.
1 Applied Arrays Lists and Strings Chapter 12 2 Applying What You Learn Searching through arrays efficiently Sorting arrays Using character arrays as.
EGR 2261 Unit 9 One-dimensional Arrays
Chapter 10-1: Structure.
Chapter 7: Introduction to Classes and Objects
Exam 3 Review.
Records C++ Structs Chapter 10.1.
CS150 Introduction to Computer Science 1
C++ Structs.
Records C++ Structs Chapter 12.
Structures.
Structures Lesson xx In this module, we’ll introduce you to structures.
CS 2308 Exam I Review.
Heterogeneous aggregate datatypes
CS150 Introduction to Computer Science 1
Structures putting data together.
Structs And Arrays.
Arrays and Strings Chapter 9.
Linked List Lesson xx   In this presentation, we introduce you to the basic elements of a linked list.
Chapter 9: Records (structs)
Chapter 9: Records (structs)
Chapter 10: Records (structs)
Chapter 9: Records (structs)
CS 2308 Exam I Review.
Arrays November 8, 2017.
Review for Final Exam.
Chapter 11: Structured Data.
Arrays An array is a collection of variables that all have the same name and the same data type. Each member of the array is known as an element of the.
CS148 Introduction to Programming II
Structures putting data together.
Structured Data Types array union struct class.
Topics discussed in this section:
EGR 2261 Unit 12 structs Read Malik, Chapter 9.
Multidimensional Arrays
Objectives In this chapter, you will: - Learn about records (structs) - Examine operations on a struct - Manipulate data using a struct - Learn about the.
Review for Final Exam.
Chapter 11: Records (structs)
Suggested self-checks: Section 7.11 #1-11
Standard Version of Starting Out with C++, 4th Edition
More on Structs Sometimes we use structs even when the fields are all of the same type. If the fields are different conceptually, that is, the data stands.
Structure (i.e. struct) An structure creates a user defined data type
Arrays, Casting & User Defined Variables
Chapter 9: Records (structs)
Structures, Unions, and Enumerations
Programming Fundamental
Presentation transcript:

MIS 120 Structures

The Problem Recall that elements of arrays must all be of the SAME type. In some cases, we want to group elements of DIFFERENT types. scores : 85 79 92 57 68 80 . . . employee R. Jones 123 Elm 6/12/55 $14.75

Solving with Parallel Arrays We learned in Chapter 11 that one way to solve this problem is with parallel arrays. While parallel arrays will solve the problem, they are inefficient and put a heavy burden on the developer and QA. 1 2 3 4 5 Student Name Jeff Joey Susan Joanne Dhale Becky Exam 1 Grade 104 78 92 84 52 87 Exam 2 Grade 128 91 88 110 40 115

Records RECORDS are used to group related components of different types Components of the record are called fields In C++ record called a struct (structure) fields called members

Solving with a Struct C++ struct structured data type fixed number of components elements accessed by name, not by index components may be of different types struct partStruct { string descrip, partNum; float unitPrice; int qty; };

Declaring Struct Variables Given Declare Use struct partStruct { string descrip, partNum; float unitPrice; int qty; }; partStruct myPart; myPart.descrip = “Tire”; myPart.unitPrice = 55.25; cout << myPart.descrip << “are $” << myPart.unitPrice << “each.”;

Use within Functions A struct variable can be passed as a parameter Can be passed by value or by reference. A function can return a value of the type struct

Some Limitations No aggregate Input/Output operations Data must be read one member at a time Contents must be written one member at a time. Compares must be done one member at a time if(student.firstName == newStudent.firstName && student.lastName == newStudent.lastName) ...

The True Power of Structs! You can declare an Array of Structs! First declare a struct (such as partStruct) Then specify an array of that type You can then access any member within the array partStruct partList [50]; for (x = 0; x <50; x++) cout << partList[x].descrip;

Questions?