Professional Documents
Culture Documents
Assignment 1 and 2
Assignment 1 and 2
Assignment 1 and 2
Discuss in detail the difference in the process of sequential file access and random file
access.
Also, explain the advantage of fixed-sized data fields over variables sized fields.
Explain a situation where you would use the unget function while reading data from a
text file. (Only 150 words)
Part 2 of 2
Part A
1. Write C++ code to open a document with the name Hello.txt, place the
message Hello, World! in the document, and exit the document. Re open
the file you closed, and read the message into a string variable. Exit out of
the file.
2. When do you open the file as an ifstream, as an ofstream, or as an fstream?
Could you simply open all files as an fstream?
Part B
The caeser cipher, which shifts all letters by a certain amount, is easy to decipher. Try this,
instead of numbers use letters. Consider this, the word is FEATHER. Remove duplicate letters,
making FEATHR, and append the rest of the letters of the alphabet in reverse order.
See exhibit A
Now, write a program that encrypts or decrypts a file using this cipher.
For example,
Part 1 of 2
Discuss what an Exception is, both the sense of the occurrence and the object.
How are Exceptions used to aid in recovering from an error and avoiding a crash?
Part 2 of 2
Stack object data structures do not contain code to throw an exception when a stack.pop()
function is called on an empty stack. This is due to the fact that it is easy to establish this
exception handing elsewhere. Create a class named SafeStack that implements a stack of strings.
Use an instance of stack from <string> to hold string values and implement the same
interface as the data type. However, your implementation (class) should throw an
exception if an attempt is made to remove a value from an empty stack.