SOLUTION
THERE IS A LINK TO THE ZIPPED FILE AT THE END OF THIS DOCUMENT
Crystal Indigo!
Crystal Indigo!
Providing all solutions you need anytime
+27 76 626 8187
**NOTE: if the GUI is displaying differently from what you desire just change
how the widgets are displayed. copy the code and run DO necessary
changes.
,//QUESTION 1
//output
//TextCounter.h
#ifndef TEXTCOUNTER_H
#define TEXTCOUNTER_H
#include <QObject>
#include <QString>
#include <QVector>
class TextCounter : public QObject
{
Q_OBJECT
public:
explicit TextCounter(QObject *parent = nullptr);
void processArguments(int argc, char *argv[]);
private:
bool flagA;
bool flagB;
bool flagC;
bool flagD;
void countOccurrences(const QString &filename);
void printResults(int wordCount, int hyphenatedCount, int
sameCharacterCount, int nonVowelStartCount);
QString removePunctuation(const QString &text) const;
bool isWordLongerThan4CharsStartingWithCapital(const QString &word);
bool isHyphenatedWord(const QString &word);
bool isSameCharacterWord(const QString &word);
bool doesNotStartWithVowel(const QString &word);
};
#endif // TEXTCOUNTER_H
//TextCounter.cpp
#include "textcounter.h"
#include <QDebug>
, #include <QFile>
#include <QTextStream>
#include <QRegularExpression>
TextCounter::TextCounter(QObject *parent) : QObject(parent),
flagA(false), flagB(false), flagC(false), flagD(false)
{
}
void TextCounter::processArguments(int argc, char *argv[])
{
// If no arguments provided, print a message
if (argc == 1) {
qDebug() << "No arguments provided. Please include file name(s).";
return;
}
// Parse the arguments
QVector<QString> filenames;
for (int i = 1; i < argc; ++i) {
QString arg = QString::fromUtf8(argv[i]);
if (arg.startsWith('-')) {
if (arg.contains('a'))
flagA = true;
if (arg.contains('b'))
flagB = true;
if (arg.contains('c'))
flagC = true;
if (arg.contains('d'))
flagD = true;
} else {
filenames.append(arg);
}
}
// If no flags provided, assume all flags were used
if (!flagA && !flagB && !flagC && !flagD) {
flagA = true;
flagB = true;
flagC = true;
flagD = true;
}
// Process each file
for (const QString &filename : filenames) {
countOccurrences(filename);
}
}
void TextCounter::countOccurrences(const QString &filename)
{