In this worksheet, the word field is used in place of the word member.
1. What is the data type of the structure? (Not the data type of its fields) acctT
2. What are the variable names for the instances of the structure? chkAcct, savAcct
3. Give all the unique field names of both instances of the
structure.
(to be unique, the variable name of the structure must be included with the name of the
field)
chkAcct.acctNum savAcct.acctNum chkAcct.acctName savAcct.acctName chkAcct.acctBal savAcct.acctBal
Write the name you would use to reference each specific field from main.
4. The name field of the checking account. chkAcct.acctName
5. The balance field of the checking account. chkAcct.acctBal
6. The name field of the savings account. savAcct.acctName
7. The account number field of the savings account. savAcct.acctNum
8. The savings account. savAcct
9. Use three statements to initialize the savings account so the account number is 5-1357648, the name is John Smith, and the balance is $1000.00.
strcpy(savAcct.acctNum, "5-1357648"); strcpy(savAcct.acctName, "John Smith"); savAcct.acctBal = 1000.00;
10. Use one statement that declares and initializes the checking account so the account number is 98765432, the name is Betsy Ross, and the balance is $2500.00.
acctT chkAcct = {"98765432", "Betsy Ross", 2500.00};
11. What is the data type of savAcct? acctT
12. Write one statement to copy all the fields from chkAcct to savAcct.
savAcct = chkAcct;
EXAMPLE 1
1. data type is product
2. structure names are tool and book
3. field names: tool.IDnum book.IDnum tool.ProdDesc book.ProdDesc tool.quantity book.quantity tool.costEA book.costEA
9. Your solution should be similar to below.
tool.IDnum = 123;
because it is an integer, not a char array
strcpy(tool.ProdDesc, "Phillips screwdriver");
tool.quantity = 1200;
tool.costEA = 14.95;
10. product tool = {123, "Phillips screwdriver", 1200, 14.95};
EXAMPLE 2
1. data type is bird
2. structure names are robin, subject1 and subject 2
3. field names for robin: robin.ColorDesc robin.song robin.clutchsize robin.wingspan
9 & 10 similar to above examples. Remember to use strcpy for robin.ColorDesc and robin.song because they are char arrays.