联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2019-03-24 10:26

Coursework 2

Introduction

This coursework requires you to write a C++ program that solves the task

described below.

Read the entire document before beginning the exercise.

Submission

You must submit two files: a report and a single C++ source code file containing

all your code for this exercise. The code file must be called fuzzysearch.cpp and it

should contain all the source code.

The program must compile without warnings or errors when I use the command

g++ -std=c++11 fuzzysearch.cpp -o fuzzysearch

This command will be run on Linux. If it does not compile, for any reason, then

you will lose all the marks.

Task

Your task is to write a C++ program that makes inaccurate search. Given an

arbitrary string and a text file, your program should output how many occurrence if

the string is contained in the file. If the string is not contained in the file, your

program should output the most similar string contained in the file.

The filename of the text file will be specified as a command line argument. Your

program should load this file and then prompt the user to enter a string to search

for. There should not be limitation on the length of input string.

After the user has entered a string, the program should output the occurrence of the

string or the most similar string contained in the file. It should repeatedly do this

until the user enters an empty string.

If the program is run without the correct number of command line parameters, it

should exit with the message

"Invalid command line arguments. Usage: ./fuzzysearch textfile”. If the file cannot

be opened, print the error message "Cannot open file".

In your report, you should explain what method or algorithm is used for string

comparison, how you implement the algorithm in class/objects, how your program

performs in making fuzzy search. The report should be in pdf format and it should

be not more than one page.

Example input/output

Given the following text file (assume that the filename is helloworld.txt, with the

file in the current directory)

This is an example text file.

Hello World! Hello C++! Hello China!

Running the program and just pressing return:

zlizpd3 $ ./fuzzysearch

Invalid command line arguments. Usage: ./fuzzysearch textfile

zlizpd3 $

Running the program:

zlizpd3 $ ./ fuzzysearch helloworld.txt

Search for:

zlizpd3 $

Running the program:

zlizpd3 $ ./ fuzzysearch helloworld.txt

Search for: Hello

3 occurance found in the file

Search for: hello

0 occurance found in the file.

Most similar string: Hello

Search for: Hello C++

1 occurance found in the file

Search for: hello world

0 occurance found in the file.

Most similar string: Hello World

Search for: I like C++ programming

0 occurance found in the file.

Most similar string: Hello C++! Hello

Search for:

zlizpd3 $

If the text file cannot be opened:

zlizpd3 $ ./ fuzzysearch missing.txt

Cannot open file

zlizpd3 $

Note: The above examples simply show one of possible solutions. It is not

necessary that a ‘correct’ program must output the same results as the above

examples.

Marking

Your program should correctly implement the task requirements. A number of tests

will be run against your program with different input data designed to test if this is

the case for each individual requirement. The marking criteria include:

? Does the program find similar strings effectively?

? Does the program deal with different input correctly?

? Does the program output match the required format?

? Does the program work with class, object, pointer, and reference properly?

If your program does not compile then you will lose all marks. Each warning

message leads to -1 mark.

Tips

1. In order to simplify the task, you can simply consider two strings of equal length

when developing your algorithm to measure similarity between two strings. For

example, if the input string is "hello" and the file contains "hel-lo", your program

does not have to compare "hello" with "hel-lo", instead simply compare "hello"

with a string of length 5 in the file.

2. How do you think the similarity between "hello world" and "world hello"? So

comparing corresponding chars in both strings only provide one criterion for

similarity.

3. There are many methods to make decision by using multiple criteria. The

simplest one amongst them is called weighted average.

4. '\n' is also a character.

5. If all text contained in the file is shorter than input string, the output is obvious,

the whole text in the file.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp