------------------------------------------------------------------------------
MC logo
CSc 220 Assignment 5
[^] CSc 220 Programming Assignments
------------------------------------------------------------------------------

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:

URL u(string host, string path = "")

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.

u.mkftp()
u.mkhttp()

For a URL object u, set the protocol as indicated.

u.creds(string userid, string password)

Set the userid and password parts of of URL object u to the indicated strings. Either one may be empty.

u.port(unsigned int port)

Set the port number of of URL object u.

u.up()

For a URL object u, remove the last component of the path, if there is one. If not, u is unchanged.

u.extend(string morepath)

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.

u.move(string dest)

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.

u.as_string()

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

string as_string() const;

This means that it does not change the object to which it belongs.

All methods return void except as_string, which returns string. The constructor, as all constructors, has no return type.

When your program works, submit over the web here.
<<CSc 220 Assignment 4