CSE 1341 Honors Exam 2 Practice: Key topics: Functions in ctype library Functions in cstring library Functions in string library Vector functions Sequential file processing Random file processing Reading/writing text files Reading/writing binary files Short coding exercises: Change an application that uses an array to a vector. Count the number of times the word ‘the’ appears in a sentence entered from the keyboard Test to see if a word entered from the keyboard is a valid C++ identifier Validate a social security number entered from the keyboard in the format xxx-xx-xxxx Long design/coding exercise: Be prepared to spend half of the class period designing a solution (using pseudocode) to a stated problem. Multiple choice: 3 points each 1. True/False: A test using the isupper function will return 0 if the argument is an uppercase character. 2. True/False: The isdigit function will return a 1 (one) if its argument is a digit between 0 and 9. 3. The ________ function accepts a pointer to a string as an argument, and it returns the length of the string (not including the null terminator). a. numchar b. strlength c. strlen d. countstring e. None of these 4. True/False: When using the strcat function, you must be careful not to overwrite the bounds of an array. 5. The strcpy function's arguments are: a. two character arrays b. two pointers to characters c. three pointers d. one array and one pointer e. None of these 6. The _____ function accepts a string as an argument and converts the string to a long integer. a. atol b. c. d. e. 7. strlong strtolong stringlong None of these A practical application of the _________ function is to allow a user to enter a response of 'y' or 'Y' to a prompt. a. tolower b. toupper c. a or b d. ignorecase e. None of these 8. The output of the statement cout << tolower(toupper('Z')); is a. upper case Z b. lower case z c. a lower case z followed by an upper case Z d. a compiler error e. None of these 9. After int num = atoi("1000"); executes, what value is stored in the variable num? a. 1000 b. 999 (1000 minus 1 for the null terminator) c. "1000" d. "thousand" e. None ; it is an incorrect statement 10. A ________ is required after the closing brace of the structure declaration. a. square bracket b. period c. semicolon d. colon e. None of these 11. True/False: A struct can contain members with varying data types. 12. True/False: Structure variables may be passed as arguments to functions. 13. When a structure is passed _________to a function, its members are not copied. a. by reference b. by value c. Neither of these 14. True/False: The expression s->m; indicates that s is a structure pointer and m is a structure member. 15. Which of the following assigns a value to the hourlyWage member of the third employee structure array element? a. employee[2]->hourlyWage = 50.00; b. employee2.hourlyWage = 7.50; c. hourlyWage[2].employee = 29.75 d. employee[2].hourlyWage = 100.00; e. None of these 16. In order, the process of using a file in a C++ program involves: a. b. c. d. e. Declare a file variable, open a file, use the file, close the file Create the file contents, close the file, name the file Put a diskette in the drive and open the file Name the file, open the file, delete the file None of these 17. True/False: When you store data in a variable, it is automatically saved in a file. 18. The _______ data type can be used to create files and write information to them but cannot be used to read information from them. a. ofstream b. ifstream c. afstream d. outstream e. None of these 19. True/False: Only one file stream object can be declared per C++ program. 20. The statement file.open("values.dat", ios::in); indicates a. the file should not be opened if it already exists b. if the file exists, it should be replaced with a new copy of values.dat c. if the file exists, it can be opened and read but not modified d. the file can be written to but not read from e. None of these 21. True/False: An alternative to using the open function is to use the file stream declaration itself to open the file. Example: fstream DataFile("names.dat", ios::in | ios::out); 22. The statement dataFile.close(); a. is illegal in C++ b. needs a filename argument to execute correctly c. closes a file d. is legal but risks losing valuable data e. None of these 23. The _________ marker is the character that marks the end of a file, and is automatically written when the file is closed. a. <EOF> b. <FINISH> c. <DONE> d. <STOP> e. None of these 24. 25. True/False: File output may be formatted the same way as screen output. The ________ member function reports when the end of a file has been found. a. b. c. d. e. end() stop() done() eof() None of these 26. The function, _____, reads a single character from a file. a. read b. get c. put d. input e. None of these 27. True/False: By default, files are opened in Binary mode. 28. The ___________ function can be used to store Binary data to a file. a. binary.out b. write c. put << d. dataout(binary) e. None of these 29. To access files from a C++ program, you must #include: a. <fileaccess.h> b. <filestream.h> c. <fstream.h> d. <iostream.h> e. None of these 30. The __________ data type can be used to read information from a file. a. ofstream b. istream c. ifstream d. instream e. None of these II. Short answer: 6 points each 1. Look at the following code and state what value will be stored in s after the code executes. char name[20]; strcpy(name, “Jimmy”); // there are no spaces with the “ “ strcat (name, “Jones”); int s = strlen(name); 2. Declare a character pointer str that is initialized to “237.39” and a variable of type double called value. Write the code that converts the string in str to a double and stores the result in value. III. Coding exercise 23 points You are to write a complete program that will read a binary file called Stocks.bin that contains stock information about a person’s stock. The structures within the file look like struct Stock { char Symbol[6]; double OpenPrice; doube ClosingPrice; long int volume; }; Your program should read the file and display all the information about all stocks whose OpenPrice was lower than ClosingPrice.