240 WORKSHEET - STRUCTURES 1

This worksheet is for practicing the notation related to structures and their fields.  In this worksheet, the word field is used in place of the word member.

The following description of a structure is located before main().

	struct acctT
	{
	char	acctNum[10];		// account number
	char	acctName[40];		// owner of account
	float	acctBal;		// account balance
	};

The following declarations are located in main.

	acctT	chkAcct;		// checking account
	acctT	savAcct;		// savings account

1. What is the data type of the structure? (Not the data type of its fields)

2. What are the variable names for the instances of the structure?

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)

Write the name you would use to reference each specific field from main.

4. The name field of the checking account.

5. The balance field of the checking account.

6. The name field of the savings account.

7. The account number field of the savings account.

8. The savings account.

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.

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.

11. What is the data type of savAcct?

12. Write one statement to copy all the fields from chkAcct to savAcct.

Below are 2 more examples of structures. For more practice, apply questions 1,2,3,9,&10 to these examples.

EXAMPLE 1	BEFORE main
	struct product
	{
	int	IDnum;		// product ID number
	char	ProdDesc[40];	// product description
	int	quantity;	// number in stock
	float	costEA;		// cost for each
	};
		IN main
	product	tool;
	product	book;
EXAMPLE 2	BEFORE main
	struct bird
	{
	char	ColorDesc[40];	// description of bird's colors
	char	song[50];	// description of song or call
	int	clutchsize;	// Number of eggs laid per season
	float	wingspan;	// Distance between spread wingtips
	};
		IN main
	bird	robin;
	bird	subject1;
	bird	subject2;