The Student Room Group

Help computer science

1.

ReportSo basically, or teacher gave us a task to do a few weeks ago on visual basic. However, we habe now moved on to our coursework and have forgotten about our task. But the task is still bugging me and i would like if someone wrote it amd explained it. No one in the class has complete it.

Task:
Develop a program that identifies individual words in a sentence, stores these in a list and replaces each word in the original sentence with the position of that word in the list.

For example, the sentence:
Ask not whay your country can do for you ask what you can do for your country
Contains the words: ask, not, whay, your, country, can, do, for, ypu

The sentence can be recreated from the positions of these words in this list using the sequence 1,2,3,4,5,6,7,8,9,1,3,9,6,7,8,4, 5

Save the list of words and the positions of these words in the sentence as seperate files or as a single file.

Basically:
Identify the individual words in a sentence and store them in a list
Create a list of positions for words in that list
Save these lists as a single file or as separate file

Thanks in advance to whoever can solve this task

Read each word in the sentence and copy it to a file (after checking is inst already on there) each time you do this add a the word to an array. e.g. word(1) =ask , word(2)=not etc. when it reaches a repeat word, it would just skip it
Then read the original sentence again comparing it to the words in the array, if a match is found, you can just add the position of the word in the array to an output string.

I'm second year Alevel computing student and think this would work, but there's probs a more efficient way to do it...sorry if I've typed it up poorly.
Original post by Aydin7
Read each word in the sentence and copy it to a file (after checking is inst already on there) each time you do this add a the word to an array. e.g. word(1) =ask , word(2)=not etc. when it reaches a repeat word, it would just skip it
Then read the original sentence again comparing it to the words in the array, if a match is found, you can just add the position of the word in the array to an output string.

I'm second year Alevel computing student and think this would work, but there's probs a more efficient way to do it...sorry if I've typed it up poorly.


See, this is the second part of the task... I have the first array etc. This is basically the code for the first task which was to find one specific word in the sentence and to display it or an error message will appear if the word isnt ther:biggrin:im words() = myString.Split({". ", ", ", " "}, StringSplitOptions.None)Dim indexes = From i In Enumerable.Range(0, words.Length) Where String.Equals(words(i), "programs", StringComparison.CurrentCultureIgnoreCase) Select iFor Each i In indexes Console.WriteLine(i)NextThis is the basic code for that without the variable and if statement. How would this array be used with the new array to store the positionSorry if that makes no sense
It's hard to understand the code in that format, are you saying that you already have an array which stores the words from the sentence and you need another to store the position of the words?
I replied on the other thread
Original post by Aydin7
It's hard to understand the code in that format, are you saying that you already have an array which stores the words from the sentence and you need another to store the position of the words?



See, this is the second part of the task... I have the first array etc. This is basically the code for the first task which was to find one specific word in the sentence and to display it or an error message will appear if the word isnt there
Dim words() = myString.Split({". ", ", ", " "},StringSplitOptions.None)

Dim indexes = From i In Enumerable.Range(0, words.Length) Where String.Equals(words(i), "programs", StringComparison.CurrentCultureI gnoreCase)

Select i For Each i In indexes
Console.WriteLine(i)
Next

This is the basic code for that without the variable and if statement. How would this array be used with the new array to store the positionSorry if that makes no sense

Quick Reply

Latest

Trending

Trending