1 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long.

Slides:



Advertisements
Similar presentations
1 Programming Structures COMP102 Prog. Fundamentals, Structures / Slide 2 2 Structures l A Structure is a collection of related data items, possibly.
Advertisements

Structure.
1 Techniques of Programming CSCI 131 Lecture 24 Structs.
1 Chapter Structured Types, Data Abstraction and Classes Dale/Weems.
Informática II Prof. Dr. Gustavo Patiño MJ
Dale/Weems/Headington
1 Lecture 24 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
1 Lecture 25 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
More Storage Structures A Data Type Defined by You Characteristics of a variable of a specific ‘data type’ has specific values or range of values that.
Chapter 11: Structured Data. Slide Introduction An array makes it possible to access a list or table of data of the same data type by using a single.
1 Structured Types, Data Abstraction and Classes.
Pointers CS362. Pointers A Pointer is a variable that can hold a memory address Pointers can be used to: Indirectly reference existing variables (sometimes.
1 Principles of Programming I Note Set #12. 2 Semester Overview Functions Character File I/O Arrays Pointers and Dynamic Memory Allocation Characters.
Arrays in C++ Numeric Character. Structured Data Type A structured data type is a type that stores a collection of individual components with one variable.
Structured Data Types array array union union struct struct class class.
1 Chapter 10 Simple Data Types: Built-In and User- Defined.
SEN 909 OO Programming in C++ Final Exam Multiple choice, True/False and some minimal programming will be required.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
Chapter 10: Records (structs)
Cosc237/structures1 Structures aggregate data types record - single variable name for the whole collection composed of several variables - fields,BUT,
1 Chapter Structured Types, Data Abstraction and Classes Dale/Weems.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
1 Chapter 10 Simple Data Types: Built-In and User- Defined.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
1 Lecture 19 Structs HW 5 has been posted. 2 C++ structs l Syntax:Example: l Think of a struct as a way to combine heterogeneous data values together.
Chapter 10 Simple Data Types: Built-In and User-Defined.
C++ Data Types Structured array struct union class Address pointer reference Simple IntegralFloating char short int long enum float double long double.
1 Data Structures and Algorithms Week 3 Data Abstraction: Part II Structured Types, and Classes.
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.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Structured Data Chapter 11. Combining Data Into Structures Structure: C++ construct that allows multiple variables to be grouped together Format: struct.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Structured Data Types struct class Structured Data Types array – homogeneous container collections of only one type struct – heterogeneous data type.
Structures (aka records, structs) Textbook Chapter 11 sections:
1 Structural Types, Data Abstractions and Classes.
1 Chapter 12 Arrays. 2 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating.
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
STRUCTURES. INTRODUCTION A structure is same as that of records. It stores related information about an entity. Structure is basically a user defined.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
1 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long.
1 Programming in C++ Dale/Weems/Headington Chapter 11 One-Dimensional Arrays.
1 Chapter 10 & 11 enum & Structured Types Dale/Weems.
Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and.
1 Chapter 12 Classes and Abstraction. 2 Chapter 12 Topics Meaning of an Abstract Data Type Declaring and Using a class Data Type Using Separate Specification.
1 Structured Types, Data Abstraction and Classes.
Chapter 10 Simple Data Types: Built-In and User-Defined
Chapter 12 Classes and Abstraction
LESSON 06.
chapter 11 Structured Types, Data Abstraction, and Classes
Dale/Weems/Headington
Chapter 10 Simple Data Types: Built-In and User-Defined
Structured Data (Lecture 07)
C++ Data Types Simple Structured Address Integral Floating
Introduction to Structured Data Types and Classes
Heterogeneous aggregate datatypes
User Defined Types – The Struct
Chapter 15 Pointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types
CS148 Introduction to Programming II
Structured Data Types array union struct class.
Introduction to Classes and Objects
Structures Structured Data types Data abstraction structs ---
Pointers, Dynamic Data, and Reference Types
Presentation transcript:

1 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long double

2 Structured Data Type A structured data type is a type in which each value is a collection of component items. l the entire collection has a single name l each component can be accessed individually

3 onePerson 5000.id name “John Smith”.dept ‘B’.hours 23.6

4 AnotherPerson 6000.id name “Mary Jones”.dept ‘A’.hour 35

5 struct Record struct Record// declares a struct data type {// does not allocate memory long id ; string name ; char dept ; // struct members float hour; } ; Record onePerson; // declare variables of Record Record anotherPerson ; 5

6 struct type Declaration SYNTAX struct TypeName // does not allocate memory { MemberList } ; MemberList SYNTAX DataType MemberName ;.

7 struct type Declaration The struct declaration names a type and names the members of the struct. It does not allocate memory for any variables of that type! You still need to declare your struct variables.

8 More about struct type declarations If the struct type declaration precedes all functions it will be visible throughout the rest of the file. If it is placed within a function, only that function can use it. It is common to place struct type declarations with TypeNames in a (.h) header file and #include that file. It is possible for members of different struct types to have the same identifiers. Also a non-struct variable may have the same identifier as a structure member.

9 Accessing struct Members Dot ( period ) is the member selection operator. After the struct type declaration, the various members can be used in your program only when they are preceded by a struct variable name and a dot. EXAMPLES onePerson.hour anotherPerson.name

10 Valid operations on a struct member depend only on its type onePerson.id = 7581; cin >> onePerson.hour; anotherPerson.name = “Adel”;

11 Examples of aggregate struct operations anotherPerson = onePerson ; // assignment printReocrd(onePerson); // value parameter ChangeHours(onePerson); // reference parameter anotherPerson = GetRecord( ); // return value of function NOW WE’LL WRITE THE 3 FUNCTIONS USED HERE...

12 void printRecord( /* in */ Record onePerson) // Prints out values of all members { cout <<“ID # “ << onePerson.id<<endl <<“Name:”<<onePerson.name<<endl <<“Dept:”<<onePerson.dept<< endl <<“Hours:”<<onePerson.hour<<endl; } 12

13 void ChangeHour( /* inout */ Record& onePerson, float today_hour ) { onePerson.hour += today_hour; } Passing a struct Type by Reference

14 Record GetRecord ( ) // Obtains all information from keyboard { Record thisPerson ; cout<<“ Enter ID, Name, dept, hour\n”; cin>>thisPerson.id; cin>>thisPerson.name; cin>>thisPerson.dept; cin>>thisPerson.hour; return thisPerson ; } 14

15 struct DateType {int month ; // Assume int day ;// Assume int year ; // Assume }; struct StatisticsType {floatfailRate ; DateTypelastServiced ; // DateType is a struct type intdownDays ; } ; struct MachineRec {int idNumber ; string description ; StatisticsType history ; // StatisticsType is a struct type DateType purchaseDate ; float cost ; } ; MachineRec machine ; 15

16 Abstraction l is the separation of the essential qualities of an object from the details of how it works or is composed l focuses on what, not how l is necessary for managing large, complex software projects