Question: C++ programming please ! Will rate ! I need the code below fixed and need a header file as well. Only able to Have one

C++ programming please ! Will rate !

I need the code below fixed and need a header file as well.

Only able to Have one data member, of type int*, which keeps track of how many times each letter appears. While this class could be implemented using a static array this requirement is designed to test your ability to implement a class that allocates and deallocates memory dynamically.

Output should be printed in the form letter number, where letter appears number times in the count. You should print the counts in alphabetical order, but you should not print a letter or count if the letter does not appear.(no spaces,!,etc)

Code Below:

// lettercount.cpp

#include

#include

using namespace std;

#include "lettercount.h"

int main()

{

//Testing default constructor and totalCount()

LetterCount lc;

cout << "Total letters in new LC: " << lc.totalCount() << endl;

//Testing print()

cout << "Letters in empty LC: ";

lc.print();

cout << endl;

//Testing single-value constructor

LetterCount area("area");

cout << "Letters in \"area\": ";

area.print();

cout << endl;

//Testing copy constructor

cout << "Making a copy of \"area\": ";

LetterCount copy(area);

copy.print();

cout << endl;

//Testing move constructor

vector vec;

cout << "Moving \"temp\": ";

vec.push_back(LetterCount("temp"));

vec[0].print();

cout << endl;

//Testing destructor

LetterCount* ydd = new LetterCount("yabba dabba doo");

cout << "Before deleting \"yabba dabba doo\": ";

ydd->print();

cout << endl;

delete ydd;

//Note: next line should cause a seg fault or print garbage data when uncommented

//cout << "After deleting: ";

//ydd->print();

//cout << endl;

//Testing equals

LetterCount are("are"), era("era");

cout << "\"are\"";

if (are.equals(era))

cout << " equals \"era\" ";

else

cout << " does not equal \"era\" ";

//Testing hasAsMany

cout << "\"area\"";

if (area.hasAsMany(are))

cout << " has as many letters as \"are\" ";

else

cout << " does not have as many letters as \"are\" ";

//Testing add

cout << "\"area\" + \"era\" = ";

area.add(era);

area.print();

cout << endl;

//Testing subtract

cout << "\"area\" - \"era\" = ";

copy.subtract(era);

copy.print();

cout << endl;

return 0;

}

output txt sample:

Total letters in new LC: 0

Letters in empty LC: none

Letters in "area": a 2 e 1 r 1

Making a copy of "area": Copy a 2 e 1 r 1

Moving "temp": Move e 1 m 1 p 1 t 1

Before deleting "yabba dabba doo": a 4 b 4 d 2 o 2 y 1

"are" equals "era"

"area" has as many letters as "are"

"area" + "era" = a 3 e 2 r 2

"area" - "era" = a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!