Questions
Create a program that reports whether each word in a set of words appears in a...

Create a program that reports whether each word in a set of words appears in a paragraph. Here are the requirements: a. Ask the user to enter a set of words, one at a time. Use an appropriate prompt to keep asking for words until a blank line is entered. The set of words should be in a dictionary, where the word is the key, and “yes” or “no” is the value. The value represents whether the word appears in the paragraph. As the words are entered, the value should initially be “no”. b. Ask the user to enter a paragraph. Use an appropriate prompt to keep asking for lines/sentences of the paragraph. The lines/sentences should be in a list (of strings). When the user enters a blank line, the paragraph is complete. c. Once the paragraph is entered, check to see if each word in the dictionary is in the paragraph. If it is, then set the value of that key (word) to “yes”. It is sufficient to determine if the word is in the paragraph. You do not need to find all instances, nor count the number of instances. d. Present the results by writing the results of the dictionary using a loop. (Do not simply print the dictionary as a whole.) This should appear as two columns of data, with the key in the first column, and the corresponding value of “yes” or “no” in the second column.

In: Computer Science

Map word scanning in C++ For some context, I've been working on a program in which...

Map word scanning in C++

For some context, I've been working on a program in which I must enter in words and clear them of any potential punctuations. If a word has punctuation in the middle of the word, I must ignore the letters AFTER the punctuation and delete the punctuation as well. For example if I enter in "fish_net" I will only get "fish" back. I must also keep track of the occurrence of each word as well as number of words.

Here's my problem, I'm using a do while loop to continuously enter in words and break from it when needed. When I do, my output is supposed to be separate words, but they are getting merged with each other and counting it as one word. For example, lets say I enter in the words: "hello" "there" "done". The INTENDED output should be the following: hello 1 (newline) there 1 (newline) done 1. However, the output CURRENTLY goes like this: hello 1 (newline) hellothere 1 (newline) hellotheredone 1. Mind you that the numbers after the words are the number of occurrences that word is entered.

#include <iostream>
#include<map>
#include<string>
#include <algorithm>
using namespace std;

void get_words(map<string, int>&);
void print_words(const map<string, int>&);
void clean_entry(const string&, string&);

int main()
{
   map<string,int>m;
   get_words(m);
   print_words(m);
}

void get_words(map<string, int>&m)
{
   string word, cleaned_words = "";
   cout << "Enter in a string of text: ";
   do
   {  
       cin >> word;
       clean_entry(word, cleaned_words);

       if (cleaned_words.length() != 0)
       {
           m[cleaned_words]++;//inserting clean words into map
       }
  
   } while (word != "done");
}

void print_words(const map<string, int>&m)
{  
   int non_empty_words = 0;
   for (auto it = m.begin(); it != m.end(); it++)
   {
       cout << it->first << " " << it->second << endl;
       non_empty_words += it->second;
   }
   cout << "Non-empty words: " << non_empty_words << endl;
   cout << "Words: " << m.size();
}

void clean_entry(const string&words, string&cleaned_words)
{
   int len = words.length();
   int i = 0;
   while (i < len && ispunct(words[i])) i++;//parse through initial punctuation (make sure that punctuation is deleted while leaving word intact if in front or back)
   while (i < len && !ispunct(words[i]))//while we come across any words with no punctuation, we add it to cleaned words
   {
       cleaned_words += words[i];
       i++;
   }
}

In: Computer Science

Need to design a program in C++ that plays hangman using classes (polymorphism and inheritance) Below...

Need to design a program in C++ that plays hangman using classes (polymorphism and inheritance)

Below is the code only need to add the classes and make the program run with at least one class of Polymorphism and Inheritance.

CODE:

#include <iostream>
#include <cstdlib>
#include<ctime>
#include <string>
using namespace std;

int NUM_TRY=8; //A classic Hangman game has 8 tries. You can change if you want.
int checkGuess (char, string, string&); //function to check the guessed letter
void main_menu();
string message = "Play!"; //it will always display


int main(int argc, char *argv[])
{
string name;
char letter;
string word;
  

string words[] = //These are the list of 10 three lettered words.
{ //You can change them as per your requirement.
"man",
"van",
"tan",
"hop",
"pop",
"two",
"six",
"may",
"low",
"out",
};
  
srand(time(NULL));
int n=rand()% 10; //Random function to genterate random words from the given list
word=words[n];
  
  
string hide_m(word.length(),'X'); // This function is used to hide the actuall word to be guessed.
//The mask selected is 'X' so the word will show as 'XXX' till you guess the correct letters.
  
  
  
while (NUM_TRY!=0)
{
main_menu();
cout << "\n" << hide_m;
cout << "\nGuess a letter: ";
cin >> letter;
  
if (checkGuess(letter, word, hide_m)==0)
{
message = "Wrong letter.";
NUM_TRY = NUM_TRY - 1;
}
else
{
message = "NICE! You guessed a letter";
}
if (word==hide_m)
{
message = "Congratulations! You got it!";
main_menu();
cout << "\nThe word is : " << word << endl;
break;
}
}
if(NUM_TRY == 0)
{
message = "NOOOOOOO!...you've been hanged.";
main_menu();
cout << "\nThe word was : " << word << endl;
}
cin.ignore();// used to discard everything in the input stream
cin.get();
return 0;
}


int checkGuess (char guess, string secretword, string &guessword)
{
int i;
int matches=0;
int len=secretword.length();
for (i = 0; i< len; i++)
{
  
if (guess == guessword[i])
return 0;
  
if (guess == secretword[i])
{
guessword[i] = guess;
matches++;
}
}
return matches;
}

void main_menu()
{
system("cls");
cout<<"\nHangman Game!";
cout << "\nYou have " << NUM_TRY << " tries to try and guess the word.";
cout<<"\n"+message;
}

//*end of code*

Hangman Game

*** Need at least to add one Class to the game code that uses Polymorphism and Inheritance.

In: Computer Science

Discuss for and against compensating victims of medical injuries via tort liability. What does the question...

Discuss for and against compensating victims of medical injuries via tort liability. What does the question above mean and paragraphs to include in an 2000 word essay. The 2000 word is mandatory

In: Economics

What is the difference between MARR(100 word), Discount Rate(100 words), and Interest Rate(100 word )? Do...

What is the difference between MARR(100 word), Discount Rate(100 words), and Interest Rate(100 word )? Do not write more than 100 words for each concept.

In: Economics

The five most common words appearing in spam emails are shipping!, today!, here!, available, and fingertips!....

The five most common words appearing in spam emails are shipping!, today!, here!, available, and fingertips!. Many spam filters separate spam from ham (email not considered to be spam) through application of Bayes' theorem. Suppose that for one email account, in every messages is spam and the proportions of spam messages that have the five most common words in spam email are given below.

shipping!        0.050      

today!             0.047

here!              0.034

Available       0.016

fingertips!      0.016


Also suppose that the proportions of ham messages that have these words are

shipping!

0.0016

today!

0.0021

here!

0.0021

available

0.0041

fingertips!

0.0010

Round your answers to three decimal places.

If a message includes the word shipping!, what is the probability the message is spam?

If a message includes the word shipping!, what is the probability the message is ham?

Should messages that include the word shipping! be flagged as spam?

b. If a message includes the word today!, what is the probability the message is spam?

If a message includes the word here!, what is the probability the message is spam?

Which of these two words is a stronger indicator that a message is spam?

Why?

Because the probability is

c. If a message includes the word available, what is the probability the message is spam?

If a message includes the word fingertips!, what is the probability the message is spam?

Which of these two words is a stronger indicator that a message is spam?

Why?

Because the probability is

d. What insights do the results of parts (b) and (c) yield about what enables a spam filter that uses Bayes' theorem to work effectively?

Explain.

It is easier to distinguish spam from ham when a word occurs in spam and less often in ham.

In: Statistics and Probability

The five most common words appearing in spam emails are shipping!, today!, here!, available, and fingertips!....

The five most common words appearing in spam emails are shipping!, today!, here!, available, and fingertips!. Many spam filters separate spam from ham (email not considered to be spam) through application of Bayes' theorem. Suppose that for one email account, in every messages is spam and the proportions of spam messages that have the five most common words in spam email are given below.

shipping!        0.050      

today!             0.047

here!              0.034

Available       0.016

fingertips!      0.016


Also suppose that the proportions of ham messages that have these words are

shipping!

0.0016

today!

0.0021

here!

0.0021

available

0.0041

fingertips!

0.0010

Round your answers to three decimal places.

If a message includes the word shipping!, what is the probability the message is spam?

If a message includes the word shipping!, what is the probability the message is ham?

Should messages that include the word shipping! be flagged as spam?

b. If a message includes the word today!, what is the probability the message is spam?

If a message includes the word here!, what is the probability the message is spam?

Which of these two words is a stronger indicator that a message is spam?

Why?

Because the probability is

c. If a message includes the word available, what is the probability the message is spam?

If a message includes the word fingertips!, what is the probability the message is spam?

Which of these two words is a stronger indicator that a message is spam?

Why?

Because the probability is

d. What insights do the results of parts (b) and (c) yield about what enables a spam filter that uses Bayes' theorem to work effectively?

Explain.

It is easier to distinguish spam from ham when a word occurs in spam and less often in ham.

In: Statistics and Probability

PLEASE DO IN JAVA 4.15 Palindrome A palindrome is a string that is the same spelled...

PLEASE DO IN JAVA

4.15 Palindrome

A palindrome is a string that is the same spelled forward as it is spelled backward. So, "abcba" is a palindrome, as are "eye" and "madam". This program takes as input from the user, a string and outputs whether the string is a palindrome.

(1) Modify the given program to use a loop to output the string one character at a time. (1 pt)

Example output for word = radar:

Word Entered:  radar
r
a
d
a
r

(2) Now modify the program to use a loop to output the string in reverse order one character at a time. (2 pt)

Example output for word = read:

Word Entered:  read
r
e
a
d
Word Reversed:
d
a
e
r

(3) Finally, modify the program to check character-by-character the string given by the user to see whether or not the string is a palindrome, and then prints either "Yes" or "No". For example, if the input string is "abba" or "rotator", the output would be "Yes". If the input string is "cat" or "garbage", the output would be "No". You may ignore punctuation, in that the test strings used for this program do not contain any. You may also assume all lowercase letters will be used in the test strings.

Note: The strings may be of odd or even length, as in "cat", "dad", "racecar", or "hannah". (8 pt)

Example output for word = radar:

Word Entered:  radar
r
a
d
a
r
Word Reversed:
r
a
d
a
r
Yes

import java.util.Scanner;

public class Palindrome {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
  
/* Your Code Here */
  
return;
}

THANK YOU SO MUCH

In: Computer Science

Consumer Type PowerPoint Excel Word Accountants $60 $175 $75 Marketing/Sales $125 $80 $135 Administrative Assistants $75...

Consumer Type

PowerPoint

Excel

Word

Accountants

$60

$175

$75

Marketing/Sales

$125

$80

$135

Administrative Assistants

$75

$100

$140

The above table contains the maximum prices different types of consumers are willing to pay for three software titles: PowerPoint, Excel and Word. Suppose there are 100 consumers of each type.

a. (6 pts) Which of the following three strategies has the chance of generating the highest revenue for Microsoft?

Support your answers with revenue estimates for each strategy.
Strategy A. Charge a single price of $315 for the bundle of PowerPoint, Excel and Word
Strategy B. Charge $60 for PowerPoint, $80 for Excel and $75 for Word
Strategy C. Charge $125 for PowerPoint, $175 for Excel and $140 for Word

The best strategy among A, B, and C is…

b. (4 pts) Can you suggest a strategy that would produce higher revenue that any of the above three strategies? Support your answer with numbers.

In: Economics

Using SQL, write a table-valued function that: -- takes a space delimited string as input (Input...

Using SQL, write a table-valued function that:

-- takes a space delimited string as input (Input string will be a sentance ex: "The cat is on the chair and the bear is on the chair")

-- returns a table (word varchar(max), count int) (Output is a table that shows how many times each word appeared in the sentance)

Where each space-delimited “word” in the string appears in the table along with the number of times it appeared in the input string.

Additional Instructions: Don’t follow punctuation or language rules; a word is any sequence of non-spaces.

Space-delimited means “all spaces are ignored”, no word may contain spaces

There should not be a length 0 string.

Please include screenshots of the code and output, thanks so much!

Example Input: "The cat is on the chair and the bear is on the chair"

Example Output:

The 4

cat 1

is 2

on 2

chair 2

and 1

bear 1

Note: The user will input the sentence each time. (It is not hard coded)

In: Computer Science