cs hw4
-
Upload
ege-guelcan -
Category
Documents
-
view
226 -
download
0
Transcript of cs hw4
-
8/3/2019 cs hw4
1/6
CS201 - Fall 2010 - Sabanc University
Homework #4A Simple Search EngineDue November 24, 2009, Wednesday, 19:00
Brief DescriptionIn this homework, you will write a simple program that searches for a string in another string. There aresome special searching parameters and details about it will be given in later sections. First your programwill get a string until the word END or end is present and then it will ask for a search string. Your
program should be able to do multiple searches until the search string QUIT or quit is entered.
InputsThere are two inputs respectively; Source Stringand Search String. Both inputs are strings. You shouldnote that there can be spaces between word for Source String (hint: use a while loop to read all words
using cin). However, there can be no punctuation characters (.,; etc.). For Search String, there can beno spaces or empty characters. Search Stringmust end with one of + , . , *. (See sample runs) . Your
program should take Source Stringonly once, but ask forSearch Stringuntil QUIT or quit is entered.
Input CheckAll inputs must be checked. In the case of an invalid input, the program should ask for an input again andagain until a correct input is entered (Hint: you may use while loop here). The rules of input check is given
below:
Source Stringmust be stored to the point the word END or end is present.Search Stringmust end with one of + , . , *.Search Stringcannot be empty.
Processing, Program Flow and OutputYour program should start with an introductory explanation and a prompt for the input. After all the inputsare entered correctly, your program should search for the string according to the rules and print out theindex of the searched word.
Search Rules:Search String ends with a +: The word must start or end with search string.Example:Enter source string: Cars are fast END
Enter search string: fa+
index: 9 word: fast
Search String ends with a *: Any word containing the search string.
Example:Enter source string: Cars are fast END
Enter search string: r*
index: 2 word: Cars
index: 6 word: are
Search String ends with a .:The word ends with search string.Example:Enter source string: Cars are fast END
Enter search string: s.
index: 3 word: Cars
-
8/3/2019 cs hw4
2/6
An example for same search string with different search operators:Enter source string: Cars are fast END
Enter search string: s+
Enter search string: s*
index: 3 word: Carsindex: 11 word: fast
Enter search string: s.
index: 3 word: Cars
Hint: You should use while loops and find() function of the string library. Please also note that you can
use find(string searchWord, int position) to search after a given position in the string.
Important RemarksYour program must be modular and you should avoid code duplication. Thus you have to show yourability to use functions in an appropriate way. This will affect your grade. In general, if your mainfunction or any user-defined function is too long and if you do everything in main or in another user-
defined function, your grade may be lowered.
AND PLEASE DO NOT WRITE EVERYTHING IN MAIN AND THEN TRY TO SPLIT THE
TASK INTO SOME FUNCTIONS JUST TO HAVE SOME FUNCTIONS OTHER THAN MAIN.
THIS IS TOTALLY AGAINST THE IDEA OF FUNCTIONAL DESIGN AND NOTHING BUT A
DIRTY TRICK TO GET SOME POINTS. INSTEAD PLEASE DESIGN YOUR PROGRAM BY
CONSIDERING NECESSARY FUNCTIONS AT THE BEGINNING.
Try to use parametric and non-void functions wherever appropriate. Do NOT use any global variables(variables defined outside the functions) to avoid parameter use.
In this homework (and in the coming ones) you are not allowed to use instructions such as exit and
goto. These cause difficulty to control the flow of your programs. Thus we do not approve using them.You are also not encouraged to use break and continue. The use of break and continue preventyou from forming good readable loop conditions and hence prevent you from learning how to form goodloops. Think cleverly in order not to use any of these instructions. If you don't know these commands, donot even try to learn them (we will explain break in class).
Please remark that there are two inputs described above in the Inputs part. While input order should beexactly the same as the sample runs, also no other input is allowed (such as a name for the introduction oranything else not mentioned in this homework specification). Since your submissions are processedautomatically, extra inputs cause problems and delays in the processing and grading. If you do not followthis rule, your grade may be lowered.
Sample RunsBelow, we provide some sample runs of the program that you will develop. The italic and bold phrases
are inputs taken from the user. The introductory line (This program bla bla bla) is intentionally
left incomplete. You are expected to use your imagination and creativity there to introduce your program.
You may also change the prompts and output lines, but you have to display the required information.
-
8/3/2019 cs hw4
3/6
Sample Run 1 (Normal run)
Enter source string: Cars are fast END
Enter search string: fast+
index :9 word: fast
Enter search string: r*
index: 2 word: Cars
index: 6 word: are
Enter search string: s.
index: 3 word: Cars
Enter search string: s+
Enter search string: s*
index: 3 word: Cars
index: 11 word: fast
Enter search string: s.
index: 3 word: Cars
Enter search string: QUIT
Press any key to continue . . .
Sample Run 2 (Normal run)
Enter source string: There are way too much homeworks in this class endEnter search string: are+
index: 6 word: are
Enter search string: a*
index: 6 word: are
index: 11 word: way
index: 43 word: class
Enter search string: a.
Enter search string: t+
index: 14 word: too
index: 36 word: this
Enter search string: th+
index: 36 word: this
Enter search string: QUIT
Press any key to continue . . .
-
8/3/2019 cs hw4
4/6
Sample Run 3 (Remember you should store the string up to word END)
Enter source string: there are good times
and there are bad times
END
Enter search string: are+
index :6 word: are
index :31 word: are
Enter search string: re*
index: 3 word: there
index: 7 word: are
index: 28 word: there
index: 32 word: are
Enter search string: QUIT
Press any key to continue . . .
Sample Run 4(You should only search when a suitable search operator is present. Also ask for search string until
QUIT is given)
Enter source string: this is a long long homework ENDEnter search string: homeworkEnter search string:
long
Enter search string: wrongoperator$Enter search string: quit
Press any key to continue . . .
What and where to submit (PLEASE READ, IMPORTANT)?You should prepare (or at least test) your program using MS Visual Studio 2008 C++. We will use thestandard C++ compiler and libraries of the abovementioned platform while testing your homework.It'd be a good idea to write your name and last name in the program (as a comment line of course).Submissions guidelines are below. Some parts of the grading process are automatic. Students are expected
to strictly follow these guidelines in order to have a smooth grading process. If you do not follow theseguidelines, depending on the severity of the problem created during the grading process, 5 or more penalty
points are to be deducted from the grade.Name your cpp file that contains your program as follows.
SUCourseUserName_YourLastname_YourName_HWnumber.cppYour SUCourse user name is actually your SUNet user name which is used for checking sabanciunive-mails. Do NOT use any spaces, non-ASCII and Turkish characters in the file name. For example, ifyour SUCourse user name is cago, name is alayan, and last name is zbugszkodyazarolu, thenthe file name must be:
-
8/3/2019 cs hw4
5/6
Cago_Ozbugsizkodyazaroglu_Caglayan_hw4.cppDo not add any other character or phrase to the file name.
Make sure that this file is the latest version of your homework program.
Compress this cpp file using WINZIP or WINRAR programs. Please use "zip" compression. "rar" oranother compression mechanism is NOT allowed. Our homework processing system works only with zip
files. Therefore, make sure that the resulting compressed file has a zip extension.
Check that your compressed file opens up correctly and it contains your cpp file. You will receive nocredits if your compressed zip file does not expand or it does not contain the correct file.
The naming convention of the zip file is the same as the cpp file (except the extension of the file of
course). The name of the zip file should be as follows.
-
8/3/2019 cs hw4
6/6
SUCourseUserName_YourLastname_YourName_HWnumber.zip For examplezubzipler_Zipleroglu_Zubeyir_hw2.zip is a valid name, but hw1_hoz_HasanOz.zip, HasanOzHoz.zip are
NOT valid names.
Submit via SUCourse ONLY! You will received no credits if you submit by other means (e-mail,paper, etc.).
1) Click on "Assignments" at CS201 SUCourse (not the CS201 web site).
2) Click Homework 4 in the assignments list.
3) Click on "Add Attachments" button.
4) Click on "Browse" button and select the zip file that you generated.
5) Now, you have to see your zip file in the "Items to attach" list.
6) Click on "Continue" button.
7) Click on "Submit" button. We cannot see your homework if you do not perform this step even if youupload your file.
After submission, you will be able to take your homework back and resubmit. In order to resubmit,follow the following steps.
1) Click on "Assignments" at CS201 SUCourse.2) Click Homework 2 in the assignments list.
3) Click on "Re-submit" button.
4) Click on "Add/remove Attachments" button
5) Remove the existing zip file by clicking on "remove" link. This step is very important. If you do notdelete the old zip file, we receive both files and the old one may be graded.
6) Click on "Browse" button and select the new zip file that you want to resubmit.
7) Now, you have to see your new zip file in the "Items to attach" list.
8) Click on "Continue" button.
9) Click on "Submit" button. We cannot see your homework if you do not perform this
Successful submission is one of the requirements of the homework. If, for some reason, you cannot
successfully submit your homework and we cannot grade it, your grade will be 0.
General Homework RulesLate penalty is 10% off of the full grade and only one late day is allowed.
Having a correct program is necessary, but not sufficient to get the full grade. Comments,
indentation, meaningful and understandable identifier names, informative introduction and
prompts, and especially proper use of required functions, unnecessarily long program (which is
bad) and unnecessary code duplications (which is also bad) will also affect your grade.
Please submit your own work only (even if it is not working). It is really easy to find out similarprograms!
For detailed rules and course policy on plagiarism, please check out
http://myweb.sabanciuniv.edu/gulsend/su_current_courses/cs-201-fall-2009/plagiarism/
and keep in mind that
Plagiarism will not be tolerated!
So say we all,Berk Taner and Glen Demirz