C++ Programming With Data Structures Assessment Answer

Answer:

The Command Line

#include

#include

#include

#include

#include

#define MAX_WORD 32

#define MAX_TEXT_LENGTH 10000

typedef struct word {

char *str;             

int freq;              

struct word *pNext;    

} Word;

//the code is provides with the counter to calculate frequency and line numbers//

int getNextWord(FILE *fp, char *buf, int bufsize); 

void addWord(char *pWord);                         

void show(Word *pWordcounter);       

Word* createWordCounter(char *word);

Word *pStart = NULL;

int totalcount = 0;                


int uniquecount = 0;

//loading of words from the file in a binary search tree

struct Node{

    string data;

    Node* left;

    Node* right;

};

Node* GetNewNode(string data){

    Node* newNode = new Node();

    newNode->data=data;

    newNode->left = newNode->right = NULL;

}

Node* Insert(Node* rootPtr,string data){

    if(rootPtr == NULL){

        rootPtr = GetNewNode(data);

        return rootPtr;

    }

    else if(data<= rootPtr->data){

        rootPtr->left = Insert(rootPtr->left,data);

    }

    else {

        rootPtr->right = Insert(rootPtr->right,data);

    }

    return rootPtr;

}

int main() {

string word;

ifstream inFile;

Node* rootPtr = NULL; // Pointer to the root node

inFile.open("wordtracker.txt");

if (!inFile) {

cout << "Unable to open text file";

}

while (inFile >> word) {

    rootPtr = Insert(rootPtr,word.substr(0,10));

    if (word == "#")

        break;

}

 //an exception arises when a word is not find in the file//

try

{

FILE * fp;

 fp = fopen(“wordtracker.txt","r"); // opening the file   

   if(!file.good())

    throw 56;

else {

    while (getline(file,s)) {

        if (false) {

            return true;

        }

}

// to find the searched word in the text file//

cout << "Enter the word you want to search for: ";

    cin >> SearchWord;

    cout << "nn";

    cout << "Enter the name of file you want to open: ";

    cin >> FileName;

    ifstream FileSearch(FileName);

 

// to search and print the the line number of the word found in file

    while(!FileSearch.eof())

    {

        co++;

        string temp;

        FileSearch >> temp;

        if(temp == SearchWord)

        {

            cout << SearchWord << " found on line: " << co << "nn";

else

cout<<”Word not found”;

            break;

        }

    }

//comparing all the words in the file to sort it alphabetically


for (list *i = first; i != NULL; i = i->next) {
cout << i->s << " ";
}

cout << endl;

bool ok = false;

while (!ok)

{
ok = true;
prev->next = first;

for (list *i = first; i != last; i = i->next)

{
if (i->s.compare(i->next->s) > 0)

{
prev->next = i->next;
i->next = i->next->next;
prev->next->next = i;

ok = false;
}

prev = prev->next;
}

}

cout << "Sorted List: n";

for (list *i = first; i != NULL; i = i->next) {
cout << i->s << " ";
}

cout << endl;

}

}

  // to calculate the frequency of each word found in the file

char buf[MAX_WORD];

int size = MAX_TEXT_LENGTH;

 Word *pCounter = NULL;

      while (getNextWord(fp, buf, size)) {       

addWord(buf);

 totalcount++;

    return false;

}

    }

  pCounter = pStart;

    while(pCounter != NULL)

    {

        uniquecount++;

        pCounter = pCounter->pNext;

    }

        printf("nSUMMARY:nn");

    printf("   %d wordsn", totalcount); /* Print total words */

    printf("   %d unique wordsn", uniquecount); /* Print unique words */  

pCounter = pStart;

    while(pCounter != NULL)

    {

        show(pCounter);

        pCounter = pCounter->pNext;

    }

    printf("n");  

pCounter = pStart;

    while(pCounter != NULL)

    {

        free(pCounter->str);       

        pStart = pCounter;          

        pCounter = pCounter->pNext; 

        free(pStart);                 

    }  

fclose(fp);

catch(int e)

{

    cout<<"Error number "<

}

}

    return 0;

}

void show(Word *pWordcounter)

{

printf("n%-30s   %5d", pWordcounter->str,pWordcounter->freq);

}

void addWord(char *word)

{

  Word *pCounter = NULL;

  Word *pLast = NULL;

  if(pStart == NULL)

  {

    pStart = createWordCounter(word);

    return;

  }

pCounter = pStart;

  while(pCounter != NULL)

  {

    if(strcmp(word, pCounter->str) == 0)

    {

      ++pCounter->freq;

      return;

    }

    pLast = pCounter;           

    pCounter = pCounter->pNext; 

  }

pLast->pNext = createWordCounter(word);

}

Word* createWordCounter(char *word)

{

  Word *pCounter = NULL;

  pCounter = (Word*)malloc(sizeof(Word));

  pCounter->str = (char*)malloc(strlen(word)+1);

  strcpy(pCounter->str, word);

  pCounter->freq = 1;

  pCounter->pNext = NULL;

  return pCounter;

}

int getNextWord(FILE *fp, char *buf, int bufsize) {

    char *p = buf;

    char c;

  do {

        c = fgetc(fp);

        if (c == EOF)

            return 0;

        } while (!isalpha(c));

      do {

        if (p - buf < bufsize - 1)

        *p++ = tolower(c);

        c = fgetc(fp);

        } while (isalpha(c));

      *p = '�';

        return 1;

        }

Preparing a report of the file

To open the file using a link list comment

To load the words of the file in a binary search tree

To search for a word in the file

To display the line numbers of words in the file

To raise an exception if the word ID not found in file

To sort the words in the given file alphabetically

To calculate the word frequency of each words in the file.

 

References

Gilberg, R. and Forouzan, B. (2001). Data structures. Pacific Grove, CA: Brooks/Cole.

Smith, P. (2004). Applied data structures with C++. Sudbury, Mass.: Jones and Bartlett Publishers.

DOWNLOAD SAMPLE DOCUMENT NOW



Upload Document Document Unser Evaluion Get Money Into Your Wallet



Cite This work.

To export a reference to this article please select a referencing stye below.

Assignment Hippo (2022) . Retrive from https://assignmenthippo.com/sample-assignment/c-programming-with-data-structures-assessment-answer

"." Assignment Hippo ,2022, https://assignmenthippo.com/sample-assignment/c-programming-with-data-structures-assessment-answer

Assignment Hippo (2022) . Available from: https://assignmenthippo.com/sample-assignment/c-programming-with-data-structures-assessment-answer

[Accessed 04/10/2022].

Assignment Hippo . ''(Assignment Hippo,2022) https://assignmenthippo.com/sample-assignment/c-programming-with-data-structures-assessment-answer accessed 04/10/2022.


Buy C++ Programming With Data Structures Assessment Answers Online

Talk to our expert to get the help with C++ Programming With Data Structures Assessment Answers from Assignment Hippo Experts to complete your assessment on time and boost your grades now

The main aim/motive of the finance assignment help services is to get connect with a greater number of students, and effectively help, and support them in getting completing their assignments the students also get find this a wonderful opportunity where they could effectively learn more about their topics, as the experts also have the best team members with them in which all the members effectively support each other to get complete their diploma assignment help Australia. They complete the assessments of the students in an appropriate manner and deliver them back to the students before the due date of the assignment so that the students could timely submit this, and can score higher marks. The experts of the assignment help services at www.assignmenthippo.com are so much skilled, capable, talented, and experienced in their field and use our best and free Citation Generator and cite your writing assignments, so, for this, they can effectively write the best economics assignment help services.

Get Online Support for C++ Programming With Data Structures Assessment Answer Assignment Help Online

Want to order fresh copy of the Sample C++ Programming With Data Structures Assessment Answers? online or do you need the old solutions for Sample C++ Programming With Data Structures Assessment Answer, contact our customer support or talk to us to get the answers of it.

Assignment Help Australia
Want latest solution of this assignment

Want to order fresh copy of the C++ Programming With Data Structures Assessment Answers? online or do you need the old solutions for Sample C++ Programming With Data Structures Assessment Answer, contact our customer support or talk to us to get the answers of it.


Submit Your Assignment Here

AssignmentHippo Features

On Time Delivery

Our motto is deliver assignment on Time. Our Expert writers deliver quality assignments to the students.

Plagiarism Free Work

Get reliable and unique assignments by using our 100% plagiarism-free.

24 X 7 Live Help

Get connected 24*7 with our Live Chat support executives to receive instant solutions for your assignment.

Services For All Subjects

Get Help with all the subjects like: Programming, Accounting, Finance, Engineering, Law and Marketing.

Best Price Guarantee

Get premium service at a pocket-friendly rate at AssignmentHippo

FREE RESOURCES

  • Assignment Writing Guide
  • Essay Writing Guide
  • Dissertation Writing Guide
  • Research Paper Writing Guide

FREE SAMPLE FILE

  • Accounts
  • Computer Science
  • Economics
  • Engineering

Client Review

I was struggling so hard to complete my marketing assignment on brand development when I decided to finally reach to the experts of this portal. They certainly deliver perfect consistency and the desired format. The content prepared by the experts of this platform was simply amazing. I definitely owe my grades to them.

Tap to Chat
Get instant assignment help