55 pts |
A Classier Web |
Due: Dec. 10 |
For this assigment, you are to repeat project 4 using a class. You are to create methods to do the same things as the top-level functions from project 4.
In this assignment, you are to create a facility for creating URLs. You must create a create two files: a header (.h) file which contains a class defintion and an implementation file (.cpp) which contains the bodies of the longer methods. For this assignment, you are required to place at least one method body in the implementation file. Generally, you should keep small functions (one or two lines) in the header, and place others in the implementation.
Implement the following public methods:
Create a class named URL which has a constructor which takes a string host name and path, the later defaulting to the empty string. It sets the protocol to HTTP, the host and path as indicated, and the other parts empty. As before, host name may contain only certain characters. If it contains anything else, either write an error message and exit, or throw an exception.
For a URL object u, set the protocol as indicated.
Set the userid and password parts of of URL object u to the indicated strings. Either one may be empty.
Set the port number of of URL object u.
For a URL object u, remove the last component of the path, if there is one. If not, u is unchanged.
Add morepath to the existing path of URL object u. If morepath does not start with a slash, add one to the front, then append it to the existing path.
This moves the URL object u to a new place nearby given by dest. If dest begins with a /, it represents a new path, and should replace the existing path. If dest does not, it replaces the last component. In that case, it behaves the same as an up followed by an extend.
This returns a string representing the URL object u. Follow all the representation and format rules given in project 4. This function should be declared constant, as
This means that it does not change the object to which it belongs.
When your program works, submit over the web here.