Question

create an inheritance class to output the synonym and antonym along with meaning when the client...

create an inheritance class to output the synonym and antonym along with meaning when the client inputs the word in the dictionary. Write the C++ code and algorithm of the problem (Marks 30)

Use the following .txt files

Synonym.txt

Word: foo; Synonym: A two o s’ file

Word: fooo; Synonym: A three o s’ file

Word: foooo; Synonym: A three o s’ file

Word: fooooo; Synonym: A four o s’ file

Word: foooooo; Synonym: A five o s’ file

Word: fooooooo; Synonym: A six o s’ file

Antonym.txt

Word: foo; Antonym: A short file

Word: fooo; Antonym: A short short file

Word: foooo; Antonym: A short short short file

Word: fooooo; Antonym: A short short short short file

Word: foooooo; Antonym: A short short short short short file

Word: fooooooo; Antonym: A short short short short short short file

Homework Answers

Answer #1

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

main.cpp

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;


string trimData(string s){
   string res = "";
   bool start = false;
   for(int i=0;i<s.length();i++){
       if(s[i]!=' '){
           start = true;
       }
       if(start){
           res += s[i];
       }
   }
   return res;
}

int main( ){
   ifstream infile;
   string line;//for read line
   infile.open ("Synonym.txt"); //name of file here. plz mention Complete path if file is not at root
   string Synonym[100];
   string word[100];
   int synonymCounter =0;
   if (infile.is_open()) //if file opened
   {
       while( getline(infile, line,'\n') ) { //get row from text file
           stringstream ss(line); //stream to other variable
           int wordInd=0;
           while(getline(ss, line, ';')){ //row delimeter by space
               stringstream sss(line);
               int ind =0;
               while(getline(sss, line, ':')){ //row delimeter by space
                   if(ind==1){
                       if(wordInd==0){
                           word[synonymCounter] = trimData(line);
                       }else{
                           Synonym[synonymCounter] = trimData(line);
                           synonymCounter++;
                       }
                       wordInd++;
                   }
                   ind++;
               }
           }
       }
       infile.close(); //close file
       cout<<"Loaded "<<synonymCounter<<" synonym"<<endl;
   }
   else //if file not found show the below message
   {
       cout << "Sorry, we could not find the file." << endl;
       return 0;
   }

   infile.open ("Antonym.txt"); //name of file here. plz mention Complete path if file is not at root
   string Antonym[100];
   string word2[100];
   int AntonymCounter =0;
   if (infile.is_open()) //if file opened
   {
       while( getline(infile, line,'\n') ) { //get row from text file
           stringstream ss(line); //stream to other variable
           int wordInd=0;
           while(getline(ss, line, ';')){ //row delimeter by space
               stringstream sss(line);
               int ind =0;
               while(getline(sss, line, ':')){ //row delimeter by space
                   if(ind==1){
                       if(wordInd==0){
                           word2[AntonymCounter] = trimData(line);
                       }else{
                           Antonym[AntonymCounter] = trimData(line);
                           AntonymCounter++;
                       }
                       wordInd++;
                   }
                   ind++;
               }
           }
       }
       infile.close(); //close file
       cout<<"Loaded "<<AntonymCounter<<" Antonym"<<endl;
   }
   else //if file not found show the below message
   {
       cout << "Sorry, we could not find the file." << endl;
       return 0;
   }

   cout<<"Enter a word to find it's synonym and antonym : ";
   string findMe;
   cin>>findMe;
   for(int i=0;i<synonymCounter;i++){
       if(word[i]==findMe){
           cout<<"Synonym of "<<findMe<<" is : "<<Synonym[i]<<endl;
       }
   }

   for(int i=0;i<AntonymCounter;i++){
       if(word2[i]==findMe){
           cout<<"Antonym of "<<findMe<<" is : "<<Antonym[i]<<endl;
       }
   }

}

Synonym.txt

Word: foo; Synonym: A two o s’ file
Word: fooo; Synonym: A three o s’ file
Word: foooo; Synonym: A three o s’ file
Word: fooooo; Synonym: A four o s’ file
Word: foooooo; Synonym: A five o s’ file
Word: fooooooo; Synonym: A six o s’ file

Antonym.txt

Word: foo; Antonym: A short file
Word: fooo; Antonym: A short short file
Word: foooo; Antonym: A short short short file
Word: fooooo; Antonym: A short short short short file
Word: foooooo; Antonym: A short short short short short file
Word: fooooooo; Antonym: A short short short short short short file

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
For this lab assignment you will need to write some code and create some graphs. You...
For this lab assignment you will need to write some code and create some graphs. You may use excel to create your graphs, or other language of your choice. Your data needs to demonstrate the experimental running time for Selection Sort (code in book), Merge Sort (code in book), and the Arrays.sort() method. Here is a basic outline of how you need to code this assignment. 1) Create several arrays of size 100, 1000, 10000, 100000, 1000000, … (you need...
PHP calculator problem Create a calculator class that will add, subtract, multiply, and divide two numbers....
PHP calculator problem Create a calculator class that will add, subtract, multiply, and divide two numbers. It will have a method that will accept three arguments consisting of a string and two numbers example ("+", 4, 5) where the string is the operator and the numbers are what will be used in the calculation. It doesn't need an HTML form, all the arguments are put in through the method. The class must check for a correct operator (+,*,-,/), and a...
Using C# Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and...
Using C# Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields. Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary. Create a Worker classes that is derived from Employee and SalaryCalculate class. In Worker...
Write a Java program that Reads baseball data in from a comma delimited file. Each line...
Write a Java program that Reads baseball data in from a comma delimited file. Each line of the file contains a name followed by a list of symbols indicating the result of each at bat: 1 for single, 2 for double, 3 for triple, 4 for home run, o for out, w for walk, s for sacrifice Statistics are computed and printed for each player. EXTRA CREDIT (+10 points); compute each player's slugging percentage https://www.wikihow.com/Calculate-Slugging-Percentage Be sure to avoid a...
Please do the following in python: Write a program (twitter_sort.py) that merges and sorts two twitter...
Please do the following in python: Write a program (twitter_sort.py) that merges and sorts two twitter feeds. At a high level, your program is going to perform the following: Read in two files containing twitter feeds. Merge the twitter feeds in reverse chronological order (most recent first). Write the merged feeds to an output file. Provide some basic summary information about the files. The names of the files will be passed in to your program via command line arguments. Use...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm to work along with a worked exercise from Chapter 5. Use two different looping strategies for different purposes. Prior Task Completion: 1. Read Chapter 05. 2. View Chapter 05’s video notes. 3. As you view the video, work along with each code sample in PyCharm using the Ch 5 Iteration PPT Code Samples.zip. Important: Do not skip the process of following along with the...
Task #4 Calculating the Mean Now we need to add lines to allow us to read...
Task #4 Calculating the Mean Now we need to add lines to allow us to read from the input file and calculate the mean. Create a FileReader object passing it the filename. Create a BufferedReader object passing it the FileReader object. Write a priming read to read the first line of the file. Write a loop that continues until you are at the end of the file. The body of the loop will: convert the line into a double value...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's algorithm to ensure mutual exclusion in the respective critical sections of the two processes, and thereby eliminate the race condition. In order to implement Peterson's Algorithm, the two processes should share a boolean array calledflagwith two components and an integer variable called turn, all initialized suitably. We will create and access these shared variables using UNIX system calls relating to shared memory – shmget,...
Suppose that you want to add items to an array such that the items are always...
Suppose that you want to add items to an array such that the items are always ordered in ascending order; e.g., [1, 2, 2, 4, 5, 8, 9, 14, 32], and any duplicate values are adjacent to each other. We haven’t talked about sorting algorithms yet, so assume you want to be able to keep the items in the array in order without having to sort them. So for example, suppose you want to add the integer value 7 to...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT