Hierarchical Nested Structures - Lecture Notes | CSCI 152, Study notes of Computer Science

Material Type: Notes; Class: Programming Fundamentals II; Subject: Computer Science - CSCI; University: Texas A & M University-Commerce; Term: Spring 2005;

Typology: Study notes

Pre 2010

Uploaded on 08/17/2009

koofers-user-o7h
koofers-user-o7h 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCI 152 Hierarchical (Nested) Structures
// GLOBAL TYPE DECLARATIONS
1 struct Date
2 {
3 int month;
4 int day;
5 int year;
6 };
7 struct Machine
8 {
9 int id;
10 bool serviceContract;
11 float failRate;
12 Date lastServiced;
13 int downDays;
14 Date purchaseDate;
15 float cost;
16 float deprValue;
17 };
// LOCAL VARIABLE DECLARATIONS
18 Date yesterday,
19 today;
20 Machine press;
21 Machine station [100];
The following statements demonstrate references to fields (fully qualified names must be used
for all field identifiers):
22 cout << "Date: " << today.month << "/" << today.day << "/" << today.year
<< endl;
23 cout << "Machine # " << press.id << endl;
24 cout << "Purchase date: " << press.purchaseDate.month << "/"
25 << press.purchaseDate.day << "/"
26 << press.purchaseDate.year << endl;
27 cout << "Original cost = $" << setprecision(2) << press.cost << endl;
28 cout << "Depreciation value = $" << press.deprValue << endl;
29 cout << "Total down days since purchase = " << press.downDays << endl;
30 cout << "Last serviced: " << press.lastServiced.day << " "
31 << press.lastServiced.month << " "
32 << press.lastServiced.year << endl;
33 if (press.failRate > 0.10)
34 cout << "Excessive downtime\n";
35 if (! press.serviceContract) // or if (press.serviceContract == false)
36 cout << "Service contract has expired\n";
The only defined operations for structure variables (the entire structure) of the same type are
assignment
pass as a parameter to a function (either by value or by reference)
return by a function
37 press.lastServiced = today;
is equivalent to:
38 // press.lastServiced.month = today.month;
39 // press.lastServiced.day = today.day;
pf3
pf4

Partial preview of the text

Download Hierarchical Nested Structures - Lecture Notes | CSCI 152 and more Study notes Computer Science in PDF only on Docsity!

CSCI 152 Hierarchical (Nested) Structures

// GLOBAL TYPE DECLARATIONS

1 struct Date 2 { 3 int month; 4 int day; 5 int year; 6 }; 7 struct Machine 8 { 9 int id; 10 bool serviceContract; 11 float failRate; 12 Date lastServiced; 13 int downDays; 14 Date purchaseDate; 15 float cost; 16 float deprValue; 17 }; // LOCAL VARIABLE DECLARATIONS 18 Date yesterday, 19 today; 20 Machine press; 21 Machine station [100]; The following statements demonstrate references to fields (fully qualified names must be used for all field identifiers): 22 cout << "Date: " << today.month << "/" << today.day << "/" << today.year << endl; 23 cout << "Machine # " << press.id << endl; 24 cout << "Purchase date: " << press.purchaseDate.month << "/" 25 << press.purchaseDate.day << "/" 26 << press.purchaseDate.year << endl; 27 cout << "Original cost = $" << setprecision(2) << press.cost << endl; 28 cout << "Depreciation value = $" << press.deprValue << endl; 29 cout << "Total down days since purchase = " << press.downDays << endl ; 30 cout << "Last serviced: " << press.lastServiced.day << " " 31 << press.lastServiced.month << " " 32 << press.lastServiced.year << endl; 33 if (press.failRate > 0.10) 34 cout << "Excessive downtime\n"; 35 if (! press.serviceContract) // or if (press.serviceContract == false) 36 cout << "Service contract has expired\n"; The only defined operations for structure variables (the entire structure) of the same type are  assignmentpass as a parameter to a function (either by value or by reference)return by a function 37 press.lastServiced = today; is equivalent to: 38 // press.lastServiced.month = today.month; 39 // press.lastServiced.day = today.day;

40 // press.lastServiced.year = today.year;

The local address (a record) of the last student: students[99].localAddress The zip code of the local address of the first student: students[0].localAddress.zipCode