Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Assignment 1 In this assignment you will be writing a tool to help you play the word puzzle game AlphaBear. In the game, certain letters

Assignment 1

In this assignment you will be writing a tool to help you play the word puzzle game AlphaBear. In the game, certain letters must be used at each round or else they will turn into rocks! Therefore, we want to create a tool that you can provide with a list of letters you MUST use and a list of available letters and the program returns a list of all the words that contain required letters and only contain available letters.

Starter Code:

  • main.cpp - main function to run your program.
  • BearHelper.h - Header file with function prototypes.
  • BearHelper.cpp - Your code goes in this file. must write the code as instructed to practice disk access and properly allocating C strings. The next assignment will look at ways we can improve the efficiency,

The Program:

The program (main) reads in a dictionary file, uses a list of required letters and a list of available letters. Then it goes through the dictionary and removes all words that do not contain required letters and all words that contain unavailable letters. Finally, the program prints the words that were not deleted

Structs and Functions to Implement:

The following functions should be implemented by the student.

  • int GetNumEntriesInFile(const char* f);
  • char** ReadWords(const char* f, int count);
  • bool AllLettersInSet(const char* letters, const char* group);

Header File

#ifndef __FunctionTemplates__bearHelper__

#define __FunctionTemplates__bearHelper__

#include

int GetNumEntriesInFile(const char *f);

char **ReadWords(const char *f, int count);

bool AllLettersInSet(const char *letters, const char *set);

#endif /* defined(__FunctionTemplates__bearHelper__) */

#include

#include

#include

#include

#include

#include

#include

#include "bearHelper.h"

/*

* Counts the number of words in a file named f

* parameter: file name

* return: number of words in file

*/

int GetNumEntriesInFile(const char *f)

{

//1. Open the file for reading

//2. Count the number of words in file. Hint: You can count the number of ' ' characters in file. Use fgetc to read one character at a time.

//3. close file

//4.return count

}

/*

* Creates an array of strings of size count and populates it with words in file named f

* parameter: f - file name, cout - number of words in file

* return: An array of c-strings

*/

char **ReadWords(const char *f, int count)

{

//1. Open file for reading

//2. Allocate the array of c-strings

//3. For each word in the file

//3.a Determine the length of word

// (hint: use ftell to determine the location of the pointer in file before you start counting the letters, use fgetc to read a single character, then fseek to the location of the start of the word and read it).

//3.b Allocate a string long enough to store word

//3.c store word in array of words

//4. close file

//5. return array of words

}

/*

* Returns true if all letters in "letters" are in group of letters "group" (duplicates should be accounted for)

* therefore the letters: "ee" are in group "tree" but not in group "tea"

*

* parameter: letters - list of letters, group - a collection of letter

* return: true of all letters are in set

*/

bool AllLettersInSet(const char *letters, const char *group)

{

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions