CSCI 240 - Quiz 12
1. (2) Write a command line that runs a program called dog and passes in a single user-supplied argument of poodle.
2. (4) Write main()'s header and code to check if a user-supplied command line argument has been passed and if so, if it is poodle or not. Set an integer variable isPoodle to 0 if there is no user-supplied command line argument or if it is not poodle; otherwise set it to 1.
3. (2) How is a struct different from an array?
4. (3) Write a definition for a struct that can hold a part name, a part weight, and a part price. Make up appropriate names and use appropriate data types.
5. (4) Declare a variable of the type defined in #4 and initialize it with valid values in two ways:
a. as part of the variable declaration
b. as several executable statements
6. (2) The 0th command line argument is
a. the first thing typed after the program name
b. the name and path of the program
c. sometimes null (i.e. sometimes missing)
d. contained in the argument usually named argc.
7. (2) Which of the following pairs are always equivalent assuming that
ar is an array
i is an integer
p is a pointer?
a. (ar + i) and ar[i]
b. *(ar + i) and ar[i]
c. *(ar + p) and *(ar + i)
d. (ar + p) and ar[p]
8. (2) The argument to main() usually named argv can best be
described as
a. the number of user-supplied command line arguments
b. a string
c. an array of char
d. an array of strings
9. (4) Suppose you have a function whose header is:
void aFunction(MyStruct *s)
where MyStruct is a struct data type, and with an integer member called num.
Write two ways (using different notations) to set num to 234 within the function:
a.
b.
10. (2) Explain what the two arguments to ifstream's read() specify.
11. (2) Declare an array of 10 TPart structs.
12. (2) Assuming the array contains 10 valid structs, write code to print out the (double) partPrice member in each.