STRUCTURES - { eArray[I]=readEmployee();

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

View Full Document Right Arrow Icon
STRUCTURES -sometimes need to keep data of different types together -assigning, pass to funct, array elements -can use a structure (structs) struct <structID> { <type1> <ident1>; <type2> <ident2>; …. <typeN> <identN>; }; struct Employee { char lastName[25]; char firstName[25]; double salary; }; int main() { Employee theEmployee; TheEmployee.salary=45000; Strcpy(theEmployee.lastName, “MacLean”); Strcpy(theEmployee.firstName, “james”); Cout<<theEmployee.LastName<<”, “<<theEMployee.firstName<<” $”<<theEmployee.salary<<endl; Employee e1 = theEmployee; Employee e2 = {“Fischer”, “Bobby”, 62000}; Return 0; } Employee readEmployee() { Employee e; Cin>>e.lastName; Cin>>e.firstName; Cin>>e.salary; Return e; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
Employee eArray[99]; For(int I=0;I<99;I++)
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { eArray[I]=readEmployee(); cout&lt;&lt;eArray[I].salary&lt;&lt;endl; } struct BirthDate { int year; int month; int days; }; struct Employee { char lastName[25]; char firstName[25]; double salary; BirthDate dob; }; Pointers to Structs Employee me = {Maclean, James, 220000, {1972,07,13}}; Employee *p=&amp;me; Employee *p2 = new Employee; (*p).salary+=20000;// . has higher priority than *-another simpler notation p-&gt; salary += 20000; //works Linked Lists-a list is an ordered sequence of elements-a linked list uses pointers to tie the elements together in order-dynamic data structre-grows and shrinks as needed struct ListNode { int data; ListNode *next; }; ListNode *head;...
View Full Document

This note was uploaded on 04/17/2008 for the course ECE APS105 taught by Professor Maclean during the Spring '08 term at University of Toronto- Toronto.

Page1 / 3

STRUCTURES - { eArray[I]=readEmployee();

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

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