click below
click below
Normal Size Small Size show me how
Computer Science 250
Chapter 11
Question | Answer |
---|---|
What is a primitive data type? | A data type that is defined as a basic part of the language. Ex. bool, char, int, short int, long int, double, float, etc. |
What is an abstract data type? | a data type created by the programmer and is composed of one or more primitive data types |
an example of a structure declaration. | struct PayRoll { int empNumber; string name; double hours, payRate, grossPayl }; |
is it possible to definre multiple structure variables in a program? | yes. |
assume that PayRoll is a Structure Declaration, how would you define three variables to it? The three variables are deptHead, foreman, and associate. | PayRoll deptHead, foreman, associate; |
what operator allows you to access structure members in a program? | the dot operator (.) |
what does this statement do? deptHead.empNumber = 475; | the number 475 is assigned to the empNumber member of the deptHead. The dot operator connects the name of the member variable with the name of the stricture variable it belongs to. |
how could you initialize this structure? struct CityInfo { string cityName; string state; long population; int distance; }; | use an initialization list. CityInfo location = {"Asheville", "NC", 50000, 28}; |
Do you have to initialize all members of the structure variable? struct CityInfo { string cityName; string state; long population; int distance; }; | No. for example, CityInfo location = {"Tampa"}; |
Define the example as an array. struct BookInfo { string title; string author; string publisher; double price; }; | BookInfo bookList[20]; |
You can access a member of any element in an array of a structure variable. How would you write this? | bookList[5].title |
How would you initialize a structure array? | PayInfo workers[NUM_WORKERS] = { {10, 9.75}; {15, 8.62}; {20, 10.50}; }; |
True or false, It is possible for a structure variable to a member of another strucutre variable. | true |
True or False. Strucutre variables cannot be passed as arguments to functions | false |
Why should large structures be passed by reference? | Because passing by value will decrease the speed and overall performance of your code. |
what is a disadvantage of passing a structure by reference? | the function that the structure has been passed into has access to the original argument. This means that the data of the structure could potentially be altered. |
how would you define a variable that is a pointer to a structure? | data type followed by an asterisk and then the name of the pointer variable. Ex. Circle *cirPtr; |
When would you use the pointer operator (->) | it is used to dereference a pointer to a structure, not a pointer that is a member f a structure. |
What is a union? | similar to a structure except all the members occupy the same memory area |
What is an anonymous union? | it is a union without a name. however, members of the union have names. |