QUIZ

CHAPTER 7

Your Name:


7.1 The difference in response to an error in interactive input and file input should be:

(a) nothing
(b) interactive input should raise an exception, file input should continue
(c) file input should raise an exception, interactive input should continue
(d) file input should raise an exception, interactive input should try to continue

7.2 If a file called guidance.dat does not exist, what happens if we attempt to create a stream object with the following statement?

	StreamReader input = new StreamReader("guidance.dat");

(a) An empty file called guidance.dat is created and opened for reading
(b) A window pops up and the user is asked to browse for the location of the file and press OK
(c) A FileNotFoundException is raised
(d) A FileLoadException is raised

7.3 If a file called secret.dat exists, and we attempt to create a stream object with the following statement

	StreamWriter out = new StreamWriter("secret.dat");
what happens?

(a) The contents of secret.dat are cleared and the stream readied for new output
(b) Any new output is added (appended) onto the end of the existing data in the file
(c) A FileLoadException is raised
(d) A file called secret1.dat is opened instead


7.4 To read one character at a time from a file, we use the Read method. This method returns

(a) the next character, and the null character if there are no more
(b) a string, from which characters can be split off, and null if there is no more data
(c) an integer representing the next character and 0 if there are no more
(d) an integer representing the next character and -1 if there are no more

7.5 If the following is written in a program and executed, what will be printed?

   1	StringBuilder b = new StringBuilder();
   2	b.Append("abcdefgh");
   3	b.Remove(3,2);
   4	b.Append("xyz");
   5	b.Insert(4,*);
   6	Console.WriteLine(b.ToString());
(a) abe*fghxyz
(b) abcfg*hxyz
(c) abcf*ghxyz
(d) abc*fghxyz