1 / 14

Class 14 Honors

Class 14 Honors. Objectives. Declare, initialize and use an array of structures Create a union. P. 641 Pgrm.11-5. Array of Structures.

brigit
Download Presentation

Class 14 Honors

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Class 14 Honors

  2. Objectives • Declare, initialize and use an array of structures • Create a union

  3. P. 641Pgrm.11-5 Array of Structures struct PayInfo{ int Hours; float PayRate; };int main (){ PayInfo Workers[5];cout << “Enter the hours worked by 5 employees” << “ and their hourly rates”;

  4. P. 641Pgrm.11-5 Array of Structures for (int Index = 0; Index < 5; Index++) {cout << “Enter hours worked for employee” << (Index + 1); cin >> Workers[Index].Hours; cout << “Enter pay rate for employee” << (Index + 1); cin >> Workers[Index].PayRate; }

  5. P. 641Pgrm.11-5 Array of Structures float Gross; cout << “here is the gross pay for each employee”; for (int Index = 0; Index < 5; Index++) {Gross =Workers[Index].Hours * Workers[Index].PayRate; cout << “Employee ” << Index << “ Gross” << Gross; }

  6. P. 642 Array of Structures struct PayInfo{ int Hours; float PayRate; };int main (){ PayInfo Workers[5] = { {10, 9.75}, { 15, 8.62}, { 20, 10.50}, { 40, 18.75}, { 40, 15.65} };// initializing an array of structures

  7. P. 643Pgrm.11-6 Nested Structures struct Date { int Month; int Day; int Year; }; struct Place{ char Address[50]; char City[20]; char State[15]; char Zip[11]; }; struct EmpInfo { char Name[50]; int EmpNumber; Date BirthDate; Place Residence; };

  8. P. 644Pgrm.11-6 Nested Structures int main () { EmpInfo Manager; ….. } EmpNumber Name Residence BirthDate struct Place{ char Address[50]; char City[20]; char State[15]; char Zip[11]; }; struct Date { int Month; int Day; int Year; };

  9. P. 644Pgrm.11-6 Nested Structures struct EmpInfo { int EmpNumber; Date BirthDate; Place Residence; } int main (){ EmpInfo Manager; cout << “Enter manager’s employee number”; cin >> Manager.EmpNumber; cout << “Enter employee’s name; cin.getline(Manager.Name,50);

  10. P. 659-661 Unions are like structures: union PaySource {short hours; float sales; }; main() { PaySource employee1; Either/oremployee1.hours ORemployee1.sales short hours float sales

  11. void main() { PaySopurce employee1;char payType;float payRate, grossPay; cout << “enter H for hourly wages or C for commission”;cin >> payType; if (payType == ‘H’) { cout << “What is the hourly pay rate?”; cin >> payRate; cout << “How many hours were worked?”; cin >> employee1.hours; grossPay = employee1.hours * payRate; }else

  12. if (payType == ‘C’) { cout << “What are the total sales for this employee?”; cin >> employee1.sales; grossPay = employee1.sales * .10; }

  13. Q & A

  14. Conclusion of Class 14

More Related