Questions
In Java.This program will translate a word into pig-latin. Pig-latin is a language game in which...

In Java.This program will translate a word into pig-latin. Pig-latin is a language game in which words in English are altered, usually by removing letters from the beginning of a word and arranging them into a suffix. The rules we will use for the pig-latin in this program are as follows: If a word starts with a consonant, split the word at the first instance of a vowel, moving the beginning consonants to the end of the word, following a '-'. Then add 'ay' at the end of the word. Vowels are: a, e, i, o, u (Notice: We are not considering y a vowel for this program) If a word starts with a vowel add the word "yay" at the end of the word following a '-'. Examples: hello translates to ello-hay flare translates to are-flay it translates to it-yay A more detailed explanation of the requirements for each method will be in the method header comments - please follow these closely. Suggested order of completion: isVowel() then pigLatin().

In: Computer Science

Need this in C++: Suppose that you are given a set of words; and two words...

Need this in C++:

Suppose that you are given a set of words; and two words from the set: word 1 and word 2.

Write a program which will transform word 1 into word 2 by changing a single letter in word 1 at a time.

Every transition that word 1 takes will have to be in the set of words.

You must output the smallest sequence of transitions possible to convert word 1 into word 2.

You may assume that all the words in the dictionary are the same length.

The first line will be word 1 and word 2 separated by a comma, followed by the set of words. The set of words will be terminated by a ‘-1’.

Input:

DOG,GOD

DOG

BOG

GOG

ABH

GOD

THU

IOP

-1

Output:

DOG -> GOG -> GOD

Input:

HOUSE,JOUKS

MOUSE

HIUKE

HIUKS

HOUSH

LOUSE

HOZKS

SOUSE

HOUKS

HOUSE

HOUKE

JOUKZ

JOUKS

HOIKE

-1

Output:

HOUSE -> HOUKE -> HOUKS -> JOUKS

In: Computer Science

Problem: Read in a word and display the requested characters from that word in the requested...

Problem: Read in a word and display the requested characters from that word in the requested format. Write a Java program that

● prompts the user for a word and reads it,

● converts all characters of the input word to uppercase and displays every other character starting from the 1st one,

● converts all characters of the input word to lowercase and displays every other character in reverse order starting from the last character,

● finally displays the original word as it was entered by the user.

In: Computer Science

I'm having problems with my java code not correctly spellchecking certain words. 1) Determine if a...

I'm having problems with my java code not correctly spellchecking certain words.

1) Determine if a word entered by the user is spelled correctly. A word is considered correct if it's found in dictionary.txt (see required output to get file).

these are the input and output that are suppose to come out i already have the dictionary.txt i just don't know hoe to set it up someone please help me

Standard Input                 Files in the same directory
glimmer
hello
world
test
tommorrow
tomorrow
recluse
habittat
exit
  • dictionary.txt
Output
Enter word to spellcheck (or exit to end)\n
glimmer is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
hello is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
world is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
test is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
tommorrow is not spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
tomorrow is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
recluse is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
habittat is not spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
Ending program...\n

Test Case 2

Standard Input                 Files in the same directory
fries
abc
apple
zzzzzzzzz
a
exit
  • dictionary.txt
Output
Enter word to spellcheck (or exit to end)\n
fries is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
abc is not spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
apple is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
zzzzzzzzz is not spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
a is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
Ending program...\n

Test Case 3

Standard Input                 Files in the same directory
rocking
chair
rocking chair
hieroglyphics
lie
detector
lie detector
exit
  • dictionary.txt
Output
Enter word to spellcheck (or exit to end)\n
rocking is not spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
chair is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
rocking chair is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
hieroglyphics is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
lie is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
detector is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
lie detector is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
Ending program...\n

Test Case 4

Standard Input                 Files in the same directory
mailbox
mailing
miling list
mailan
mail order
maim
exit
  • dictionary.txt
Output
Enter word to spellcheck (or exit to end)\n
mailbox is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
mailing is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
miling list is not spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
mailan is not spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
mail order is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
maim is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
Ending program...\n

Test Case 5

Standard Input                 Files in the same directory
NE
neard
nearby
nearly
nearsghted
neat
exit
  • dictionary.txt
Output
Enter word to spellcheck (or exit to end)\n
NE is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
neard is not spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
nearby is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
nearly is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
nearsghted is not spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
neat is spelled correctly.\n
Enter word to spellcheck (or exit to end)\n
Ending program...\n

Here's the current java code that I am using (in IntelliJ):

import java.lang.*;
import java.util.*;
import java.io.*;

public class PS6LoopsPart2Q5p2 {

    public static void main(String[] args) throws Exception
    {
        RandomAccessFile br=new RandomAccessFile("dictionary.txt","r");
        Scanner input = new Scanner(System.in);
        String s;


        while(true)
        {

            System.out.println("Enter word to spellcheck (or exit to end)");

            String key=input.nextLine();
            if (key.equalsIgnoreCase("exit"))
            {
                System.out.println("Ending program...");
                System.exit(0);
            }

            else
            {
                while ((s=br.readLine())!=null){
                    if(!s.contains(key))
                    {
                        System.out.println(key+" is spelled correctly.");
                        break;
                    }
                    else
                    {
                        System.out.println(key+" is not spelled correctly.");
                        break;
                    }


                }
            }
        }
    }
}

In: Computer Science

# Do not delete this cell. You have to run this cell to test your code...

# Do not delete this cell. You have to run this cell to test your code in the test cases.
score = dict()

# This function will search the given text in order to find a given word

def is_word_there(text, word):
  
    """
        What it takes?
            a text to be searched
            a word to be searched within a text
          
        what it does?
            searches if a word occurs in a text
          
        What it returns?
            returns 1 if word is in the text.
            returns -1 if word is not in the text
    """
  
    # your code goes in here
  
    return
   

Test Case for Question 1. Do not delete or alter the cell below

score = dict()

text = """ Python is an amazing programming language.
            Python is also one of the primary languages in the data analysis field"""

word = "amazing"

try:
    if is_word_there(text, word) ==1:
        score['question 1'] = 'pass'
    else:
        score['question 1'] = 'fail'
except:
    score['question 1'] = 'fail'
  
is_word_there(text, word)

In: Computer Science

Python Coding Question (Data Science) Hello I am having difficulty writing a code in python to...

Python Coding Question (Data Science)

Hello I am having difficulty writing a code in python to do a specific task. I have two text files, Positive.txt and Practice_forhw1.txt. I want to write a script that will check if any words in Practice_forhw1.txt match any of the words in Positive.txt then the word would get replaced with a "+1" in the Practice_forhw1.txt and then print out the Practice_forhw1.txt.  (i.e if the word "happy" is in both Positive.txt and Practice_forhw1.txt then I want the word "happy" to get replaced with a +1 in the Practice_forhw1.txt file.

My poor attempt below:

pos_file = open("Positive.txt", 'r')
#positive words are now in a list
pos_list = pos_file.readlines()
p_file = open("Practice_forhw1.txt", 'r')
p_list = p_file.readlines()


for word in p_list:
if word in p_list == word in pos_list:
word = word.replace(word, '+1')
print (word)

In: Computer Science

C++ Add a function that finds & displays all the words that begin with the letter...

C++

Add a function that finds & displays all the words that begin with the letter 's'.

The text file "dickens.txt" is as follows:

It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair...

Display this at the end of the program which should look like this:

WORDS THAT BEGIN WITH 'S': season, spring

"spring" appears twice, duplicate works should only appear once.

The code is as follows:

#include <iostream>
#include <fstream>
#include <string>
#include <set>

using namespace std;

multiset<string> display_and_load_words(string filename);
set<string> get_unique_words(multiset<string>& words);

int main() {
cout << "The Word Counter program\n\n";

string filename = "dickens.txt";

   cout << "FILE TEXT: ";

auto words = display_and_load_words(filename);
   cout << "WORD COUNT: " << words.size() << endl << endl;

   auto unique_words = get_unique_words(words);

cout << unique_words.size() << " UNIQUE WORDS: ";
   for (string word : unique_words) {
       cout << word << ' ';
   }

cout << endl << endl;

cout << "COUNT PER WORD: ";
   for (string word : unique_words) {
       cout << word << '=' << words.count(word) << ' ';
   }
  
cout << endl << endl;
}

multiset<string> display_and_load_words(string filename) {
multiset<string> words;
ifstream infile(filename);

if (infile) {
string word;
while (infile >> word) {
           cout << word << ' ';

string new_word = "";
for (char c : word) {
if (c == '.' || c == ',') {
continue;
}
else if (isupper(c)) {
new_word += tolower(c);
}
else {
new_word += c;
}
}
words.insert(new_word);
}
       cout << endl << endl;
infile.close();
}
return words;
}

set<string> get_unique_words(multiset<string>& words) {
   set<string> unique_words;

   for (string word : words) {
       auto search = unique_words.find(word);
       if (search == unique_words.end()) {
           unique_words.insert(word);
       }
   }
   return unique_words;
}

In: Computer Science

Suppose that you are given a set of words; and two words from the set: word...

Suppose that you are given a set of words; and two words from the set: word 1 and word 2.

Write a program which will transform word 1 into word 2 by changing a single letter in word 1 at a time.

Every transition that word 1 takes will have to be in the set of words.

You must output the smallest sequence of transitions possible to convert word 1 into word 2.

You may assume that all the words in the dictionary are the same length.

The first line will be word 1 and word 2 separated by a comma, followed by the set of words. The set of words will be terminated by a ‘-1’.

Input:

DOG,GOD

DOG

BOG

GOG

ABH

GOD

THU

IOP

-1

Output:

DOG -> GOG -> GOD

I have a code that does this but its all done in a textfile, I need it to be all on the console(using cin,cout and not the fstream)

#include
#include
#include
#include
#include
#include
#include

using namespace std;

class WordLadder {

private:
list dict; //list of possible words in ladder
void printstack(stack stack, ofstream &outfile);
bool wordcompare(string word, string dictword);

public:
WordLadder(const string &file);
void outputLadder(const string &start, const string &end, const string &outputFile);
};
WordLadder::WordLadder(const string &file) {
string word;
ifstream infile;
infile.open(file.c_str());
if (infile.is_open()) {
while (!infile.eof()) {
getline(infile,word);
if (word.size() != 5) {
cout << "Warning: Word longer than 5 characters detected in dictionary." << endl;
}
dict.push_back(word.c_str());
}
infile.close();
return;
} else {
cout << "Error opening input file." << endl;
return;
}
}
void WordLadder::outputLadder(const string &start, const string &end, const string &outputFile) {

cout << "Finding word ladder from " << start << " to " << end << ": ";
ofstream outfile;
outfile.open(outputFile.c_str());
if (!outfile.is_open()) {
cout << "Opening output file failed." << endl;
return;
}
// set up the stuff
queue< stack > queue;
stack< string > stack;
string word;
list::iterator it;
bool startgood = false, endgood = false;

// initial validity tests
for (it=dict.begin();it!=dict.end();++it) {
if (*it == start) {
startgood = true;
}
if (*it == end) {
endgood = true;
}
}
if (!startgood || !endgood) {
cout << "Starting or ending word was not found in the dictionary." << endl;
return;
}
if (start == end) {
outfile << start;
return;
}
stack.push(start);
queue.push(stack);

// find the first word, delete it
dict.remove(start);
while(!queue.empty()) {
// get the word off of the top of the front stack
word = queue.front().top();
for (it=dict.begin();it!=dict.end();++it) {
// wordcompare will decide if the word is off by one from the dictionary word.
if (wordcompare(word,*it)) {
if (*it == end) {
// if the off by one word is the last word
// the ladder contains the entire stack -- output and return.
queue.front().push(end);
//print the stack
printstack(queue.front(),outfile);
//cout << "Operations: " << opers << endl << endl;
return;
}
// otherwise, create a copy of the front stack and push the
// off by one word from dictionary
stack = queue.front();
stack.push(*it);
queue.push(stack);
it = dict.erase(it);
// decrement iterator by one to correct for the advanced iterator
// returned by the std::list::erase function
it--;
}
}
queue.pop();
}
// if a word ladder is not found, then do this
if (outfile.is_open()) {
outfile << "No Word Ladder Found!!";
cout << "No Word Ladder Found!!";
}
}


bool WordLadder::wordcompare(string word, string dictword) {
int hits = 0;
for (int i=0; i<5; i++) {
if (word[i] == dictword[i]) { hits++; }
}
if (hits == 4) {
return true;
} else {
return false;
}
}

void WordLadder::printstack(stack stack, ofstream &outfile) {

int i = 0;
vector ladder;
while (!stack.empty()) {
ladder.push_back(stack.top());
stack.pop();
i++;
}

if (outfile.is_open()) {
while (i!=0) {
i--;
outfile << ladder.at(i);
cout << ladder.at(i);
if (i!=0) {
outfile << " ";
cout << " ";
}
}
cout << endl;
}
}

int main() {
string dictFile, wordBegin, wordEnd, outFile;
cout << "Enter the name of the dictionary file: ";
cin >> dictFile;
cout << endl;
cout << "Enter the name of the output file: ";
cin >> outFile;
cout << endl;
cout << "Enter the first word: ";
cin >> wordBegin;
cout << endl;
while (wordBegin.size() != 5) {
cout << "Word must have exactly 5 characters." << endl
<< "Please reenter the first word: ";
cin >> wordBegin;
cout << endl;
}
cout << "Enter the last word: ";
cin >> wordEnd;
cout << endl;
while (wordEnd.size() != 5) {
cout << "Word must have exactly 5 characters." << endl
<< "Please reenter the last word: ";
cin >> wordEnd;
cout << endl;
}
WordLadder wl(dictFile);
wl.outputLadder(wordBegin, wordEnd, outFile);
return 0;
}

In: Computer Science

I need convert this java code to C language. There is no string can be used...

I need convert this java code to C language. There is no string can be used in C. Thank you!

import java.util.Scanner;

public class Nthword
{
public static void main( String args[] )
{
String line;
int word;
Scanner stdin = new Scanner(System.in);

while ( stdin.hasNextLine() )
{
line = stdin.nextLine();
word = stdin.nextInt(); stdin.nextLine(); // get rid of the newline after the int

System.out.println( "Read line: \"" + line + "\", extracting word [" + word + "]" );
System.out.println( "Word #" + word + " is: " + extractWord( line, word ) );
}

stdin.close();

System.out.println( "\nEnd of processing" );
  
}

// returns the first word of the string
private static String extractWord( String theLine, int word )
{
int start;
int end;
int spaces = 1;
String result = "";

// search for the nth non-blank character
for (start = 0; start < theLine.length() && spaces < word; start++)
{
if ( Character.isSpaceChar( theLine.charAt( start ) ) )
{
spaces++;
}
}

// only need to continue if we haven't gone past the end of the string
if ( start<theLine.length() )
{
// the next blank character is the end
for ( end=start ; end<theLine.length() && !Character.isSpaceChar( theLine.charAt( end ) ) ; end++ )
;

// we now have the word
result = theLine.substring( start, end );
}

return( result );
}
  
}

In: Computer Science

Write a program that will prompt for a word with at least five letters in it...

Write a program that will prompt for a word with at least five letters in it (if not, keep asking for input). Then evaluate the word to produce a count of all the vowels in the word. Sample output appears below.

Enter a word at least 5 characters long:<SPC>cat<ENTER>
Enter a word at least 5 characters long:<SPC>dog<ENTER>
Enter a word at least 5 characters long:<SPC>concatenate<ENTER>
Letter Counts
=========
a: 2
e: 2
i: 0
o: 1
u: 0

In: Computer Science