logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

CS2315 Computer Programming <protocol> indicates the operation. For webpage access, usually it is http:// (Hyper Text Transfer Protocol) or the secure version https://

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Executable code for output 3answer.doc And do not change main

CS2315 Computer Programming

Assignment Three (2021-22 Sem. A)

  (Week 13 Sat) No Late submission will be accepted

In this assignment you may use only the functions from <iostream>, <iomanip> and

<cstring> when appropriate (i.e. no other libraries like <string>, <cmath> or <cstdlib>).

Parsing of URL

URL (Universal Resource Locator), commonly known as “web address” is a string which

specifies the location of a file/resource, together with the (optional) query string. The

basic form of a URL is shown as follow:

<protocol> :// <domain> [/<path>] [/<file>] [? <query string>]

<protocol> indicates the operation. For webpage access, usually it is http://

(Hyper Text Transfer Protocol) or the secure version https://

<domain> is basically the “server name” like www.google.com . It could also be the IP

address, possible with port number like 127.0.0.1:80 .

<path> is optional, which indicates the directory/folder location of the <file> . For

instance, in https://abc.com/def/ghi/file.html , the <path> is def/ghi and the <file>

name is file.html

<file> name is also optional. For instance https://abc.com/def/ghi/ contains no <file>

name (after the last / ). Usually the web server will load some default name (like

index.html) but we will not consider default names in this assignment.

From time to time, the URL may contain (optional) <query string> for purpose like

login and online form (e.g. google search). The query string (which could be empty) is

separated from the address using the ? character.

The <query string> contains zero or more parameters in the form of <name>=<value>

pair. If there exist two or more parameter pairs, they will be separated by the &

character. For instance, in https://www.google.com/search?q=cityu&uact=5

After the <file> (resource) name search, there are 2 parameters: The first one has

<name> q and it’s <value> is cityu, the second one has <name> uact and it’s <value>

is 5. 

A URL contains no space character, space character (e.g. in query string) will be

replaced by the + character. Also, a character could be replaced by a triplet which

contains % followed by two hexadecimal digit. For instance, character ‘K’ is ASCII code

75 in decimal (4B in hexadecimal), therefore ‘K’ character could be represented as K or

%4b or %4B . Let’s try: https://www.google.com/search?q=H+%4b

(It will search “H K” (<H> <space> <K>))

In this assignment you will finish the implementation of the URL class based on a given

template and main() function.

 Students have to implement all constructors and functions exactly as listed in the

table on the next page.

 Students could not change the behavior (e.g. return type, public/private) of the

stated constructors and functions, but students could add in new data members and

functions for internal use if necessary.

 Students could not change the provided main() function.

 Students may assume that:

 the given URL is syntactically valid. No error checking is needed

 the URL length is at most 1024 characters

 characters : / ? & and = are not represented in hex encoding

(except in parameter names and values)

 The protocol field is not represented in hex encoding

 the URL and query string do not contain foreign character (e.g. Chinese)

 parameter names in query string are unique

 a parameter may have empty value but the parameter name itself is non-empty

 the last word after domain name is treated as <file> if it’s not preceded by /.

For instance, in http://abc.com/def/ghi/jkl , <path> is def/ghi and <file> is jkl

In http://abc.com/def/ghi/jkl/ , <path> is def/ghi/jkl and <file> is empty

Structure of the URL class:

Students should download the template from Canvas and continue development.

Private data members / methods:

char str[1025]; cString which stores the content of the URL

Public data members / methods:

URL() Default constructor which sets cString str[] to empty

URL(char S[]) Parameterized constructor which copies the input cString S[] to

private member str[]

void set(char S[]) Copies the input cString S[] to private member str[]

void printURL() Display the content of URL. Print “URL is Empty” if str[] has no

content (e.g. just created with default constructor).

void printURL() Display the protocol in uppercase

Print “URL is Empty” if str[] has no content

void printDomain() Display the domain/server name

Print “URL is Empty” if str[] has no content

void printPath() Display the path name without leading and trailing / character

Print “URL is Empty” if str[] has no content

Print “Path is Empty” if URL contains no path

void printFile() Display the file/resource name

Print “URL is Empty” if str[] has no content

Print “Filename is Empty” if URL contains no filename

void printAllParam() Display the number of parameters on the first line, then display

each [name]=[value] pair on a line of its own.

Parameters should be sorted by [name] in ascending order

Field width of [name] should be set according to the longest

name and the field should be left-aligned.

Print “URL is Empty” if str[] has no content. 

Sample Input / Output:

Example 1: (User Input is underlined)

Enter URL: https://www.microsoft.com/en-hk/

URL is https://www.microsoft.com/en-hk/

Protocol: HTTPS

Domain: www.microsoft.com

Path: en-hk

Filename is Empty

Number of parameter(s): 0

Example 2: (User Input is underlined)

Enter URL: http://abc.com/def/ghi/index.html?

URL is http://abc.com/def/ghi/index.html?

Protocol: HTTP

Domain: abc.com

Path: def/ghi

Filename: index.html

Number of parameter(s): 0

Example 3: (User Input is underlined)

Enter URL: https://www%2Egoogle.c%6fm/se%61rch?q=cityu+%48k&uact=5

URL is https://www%2Egoogle.c%6fm/se%61rch?q=cityu+%48k&uact=5

Protocol: HTTPS

Domain: www.google.com

Path is Empty

Filename: search

Number of parameter(s): 2

[q ] is [cityu Hk]

[uact] is [5]

Example 4: (User Input is underlined)

Enter URL: https://www.bing.com/search?q=us&qs=n&form=QBRE&sp=-1&pq=us&sc=8-2&sk=&cvid=0F

URL is https://www.bing.com/search?q=us&qs=n&form=QBRE&sp=-1&pq=us&sc=8-2&sk=&cvid=0F

Protocol: HTTPS

Domain: www.bing.com

Path is Empty

Filename: search

Number of parameter(s): 8

[cvid] is [0F]

[form] is [QBRE]

[pq ] is [us]

[q ] is [us]

[qs ] is [n]

[sc ] is [8-2]

[sk ] is []

[sp ] is [-1] 

Marking criteria

Submitted program will be tested repeatedly with PASS. Marks will be graded objectively

based on the number of correct outputs reported by PASS.

 If the program is not compilable, zero mark will be given.

 Make sure that the output format (spelling, spacing…etc) follows exactly the sample

output above otherwise PASS will consider your answer incorrect. Note that the marker

will make NO manual attempt to check or re-mark program output.

Unlike tutorial exercises, for assignment, PASS will NOT make ALL test cases visible online. (i.e.

there are hidden test cases). Email request on opening hidden test case(s) will not be

entertained. It is the responsibility of a programmer to design own test cases in order to

verify the correctness of the written program.

Note that the marking in PASS is automatic, therefore the following situations may lead to

extremely low or zero marks:

 Input/output does not match the requirements as defined.

(e.g. incorrect spacing, incorrect spelling, letter cases or punctuations)

 Submission of non .cpp files (e.g. .exe or .zip files)

 Submission with the “test” function rather than the “submit” function

(Only the last upload with “submit” will be marked)

Please also note that the PASS plagiarism check will also be turned on. The same disciplinary

action will be applied without distinguishing which one is the source / copier. Please

safeguard your files if you work on your assignment using public computers (e.g. CityU Lab)

Testing and Submission

Students should submit separate cpp files for part a) and part b) to PASS before the deadline.

No other submission method (e.g. hardcopy, email…etc) is accepted. Students may use

whatever IDE/compiler for development, but programming using non-standard, platform

specific features (which is not compilable in MS Visual Studio) will lead to zero mark. The

marker will make no attempt to fix the syntax error and make the code compilable.

Hint: If you observe that the answer in PASS is different from the one you get in your PC,

most likely it is caused by programming bugs like uninitialized variables or array access with 

invalid indexes. The result by PASS will be used for marking without consideration of what

you observed in your local PC.

It is advised that students test the programs with PASS (using the function)

before final submission (with the “submit” button). Be warned that the system could be

extremely busy and may become sluggish in responding near deadline. Only .cpp files are

accepted. Do not submit .obj , .exe or any other files.

To protect yourself, it is advised that you write down your particulars (full name, student

 

number, eid…) in the beginning of your source code as comment. 

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

897 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

813 Answers

Hire Me
expert
Husnain SaeedComputer science

581 Answers

Hire Me
expert
Atharva PatilComputer science

941 Answers

Hire Me