Dale - Computer Science Illuminated 285

Dale - Computer Science Illuminated 285 - 258 Chapter 8...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 258 Chapter 8 High-Level Programming Languages read in a name, an age, and an hourly wage. The three items could be bound together into a record. Let’s look at how a record type is declared in our three languages. Language Ada Record Type Declaration X‘S" )e "7JX= 9 o JX= 9 ?"hh"YBi X‘S" * SlD‘""7F‘S" o ="PD= )e " , )e "7JX= 9 i . " , I9X" "= =e9 " Yhh"YYi 5D\=l‘7we " , lDeX =e9 " "hYhh:YYYhYi "9 ="PD= i JX=\PX\=" * SlD‘"" W )e " .o JX= 9 W . " .o I9X" "= W 5D\=l‘we " .o J 9 l" *9 JX=\PX\=" oX=\PX * SlD‘""F‘S" C oX= 9 9e "i 9X e "i —lDeX zD\=l‘we "i Di VB.NET C++ Although the syntax is quite different, three elements are present: A record type is defined with a name and three variable names are defined with their data types. Notice that Ada allows the programmer to declare a range of a numeric data types. The . " field is defined as a reasonable subrange of the integers. If the program tries to store a value outside that range into . ", an error occurs. 5D\=l‘7we " is defined as a reasonable subrange of the reals. This is a very nice safety feature in the language. How do you access the fields within a record? Well, first you have to declare a record to be of the record type, and then you can access the fields within the record variable. The syntax for declaring a record variable and the accessing mechanism for the variables is shown on the next page. ...
View Full Document

Ask a homework question - tutors are online