SOLUTION
NOTE: Change what you need to change and remember to submit what is specified in the
submission instructions.
THE LINK TO THE PROJECT IS IN THIS FILE.
,OUTPUTS FOR ALL QUESTIONS
QUESTION 1 output
BEFORE running anything, ensure that the file you want to analyze is in the same folder as your
executable, question1.exe. You can see where your executable is from here:
,Depending on where your project is, below is where my project is:
Output
Helper before setting the flags:
The instructions to set the flags are in your assignment questions. Play around with the
flags to see if it runs the way you want
After setting flags but can not open files:
After setting the flags and can open files:
This output is different from the one in the question because in the question they gave us
an example of how it can be, you can change to the one you want.
,QUESTION 2 OUTPUT:
You can follow the path to where the file was saved
,QUESTION 3 OUTPUT
SOURCE CODE:
Question 1
fileprocessor.h
#ifndef FILEPROCESSOR_H
, #define FILEPROCESSOR_H
#include <QString>
#include <QRegularExpression>
class FileProcessor {
public:
FileProcessor() = default;
QString readFile(const QString& fileName) const;
int countCapitalWords(const QString& text) const;
int countHyphenatedWords(const QString& text) const;
int countSameLetterWords(const QString& text) const;
int countNonVowelWords(const QString& text) const;
};
#endif // FILEPROCESSOR_H
fileprocessor.cpp
#include "fileprocessor.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>
QString FileProcessor::readFile(const QString& fileName) const
{
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug().noquote() << QString("Error: Unable to open
'%1'").arg(fileName);
qDebug().noquote() << QString("MAKE sure txt file is where your
executable is. e.g
path\\to\\build\\Desktop_Qt_6_9_0_MinGW_64_bit-Debug\\question1.exe");
return QString();
}
QTextStream stream(&file);
QString content = stream.readAll();
file.close();
return content;