1 2025 - DUE April 2025; 100% correct solutions and
explanations.
Question 1
Here's a complete C++ console application that meets all the specifications).
This program:
Accepts multiple files and flags.
Uses regular expressions to count specific patterns.
Processes text by removing punctuation and trimming whitespace.
Provides meaningful messages for different input scenarios.
C++ Code (using std::regex)
cpp
CopyEdit
#include <iostream>
#include <fstream>
#include <sstream>
#include <regex>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
// Function to clean text: remove punctuation and trim
string cleanText(const string &input) {
string result = regex_replace(input, regex(R"([\.,?!:;])"), ""); // remove
punctuation
result = regex_replace(result, regex(R"(^\s+|\s+$)"), ""); // trim
whitespace
return result;
}