17.7k views
2 votes
LAB: Thesaurus Given a set of text filesicontaining synonyms for different wards, complête the main program to output the syñonyms for a specific word. Each textfile contains synonyms forthe word specified in the file's name, and each fow within the file lists the word's synonyms that begin with the same letter separated by a space. The program reads a word anda letter from theuser and opens the text file associated with the input word. The program then stores the contents of the text file into a dictionary predefined in the program Finally the program searches the dictionary and outputs all the synonyms that begin with the inpue letter one synonym perline:-ora message if no synonyms that begin with the input letter are found. Hints: Use the first letter of a synonymas the Rey when stoting the synonym into the dictionary Assume all letters are in lowercase Ex. If the input of the program is: educate the program opens the fle educateixt whion oontains: brainwash-brief civilize coach cultivate develop digeipline drinth edify enlightentexerciise dxalain foster improve indoctrinate inform ins ituct mature nurture rear school train tutor then the program outputs =civilize coach cultivate Ex-lfthe input of the progrann is: educate a then the program outputs No synonyms for eduoate begin with a.

1 Answer

2 votes

Final answer:

This question is about a program that reads a word and a letter from a user, opens a text file associated with the word, stores the contents into a dictionary, and searches the dictionary to output all the synonyms that begin with the input letter.

Step-by-step explanation:

This question is about a program that reads a word and a letter from a user, opens a text file associated with the word, stores the contents into a dictionary, and searches the dictionary to output all the synonyms that begin with the input letter.

In order to solve this problem, you need to follow these steps:

  1. Read the word and letter from the user.
  2. Open the text file associated with the word and read its contents.
  3. Store the contents of the text file into a dictionary. Use the first letter of each synonym as the key and the synonym itself as the value.
  4. Search the dictionary and output all the synonyms that begin with the input letter, one synonym per line.
  5. If no synonyms are found, output a message stating that.

For example, if the input is 'educate' and 'a', the program should open the file 'educate.txt' and output 'No synonyms for educate begin with a'.

User SARose
by
7.8k points