Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include #include using namespace std; class FlCalc { public: void doCalc(double num1, double num2, char op) { switch (op) { case '+': add(num1,
#include #include #include #include using namespace std; class FlCalc { public: void doCalc(double num1, double num2, char op) { switch (op) { case '+': add(num1, num2); break; case '-': subtract(num1, num2); break; case '*': multiply(num1, num2); break; case '/': divide(num1, num2); break; default: cout << "Invalid operator!" << endl; } } private: void add(double num1, double num2) { cout << "Addition: " << num1 + num2 << endl; } void subtract(double num1, double num2) { cout << "Subtraction: " << num1 - num2 << endl; } void multiply(double num1, double num2) { cout << "Multiplication: " << num1 * num2 << endl; } void divide(double num1, double num2) { if (num2 != 0) cout << "Division: " << num1 / num2 << endl; else cout << "Error: Division by zero!" << endl; } }; class FlCalc2 : public FlCalc { public: FlCalc allInOne(double num1, double num2) { FlCalc result; result.doCalc(num1, num2, '+'); result.doCalc(num1, num2, '-'); result.doCalc(num1, num2, '*'); result.doCalc(num1, num2, '/'); return result; } }; class Tools { public: void saveToFile(const string& filename, const string& content) { ofstream myfile(filename); if (myfile.is_open()) { myfile << content; myfile.close(); cout << "Data saved to file: " << filename << endl; } else { cout << "Error: Unable to open file: " << filename << endl; } } string readFromFile(const string& filename) { string content; ifstream myfile(filename); if (myfile.is_open()) { string line; while (getline(myfile, line)) { content += line + " "; } myfile.close(); return content; } else { cout << "Error: Unable to open file: " << filename << endl; return ""; } } }; int main() { string name; cout << "Enter name: "; getline(cin, name); string choice; while (true) { cout << " Menu: "; cout << "1. All-in-One Calculation "; cout << "2. Save to File "; cout << "3. Read from File "; cout << "4. Read Result File "; // Added menu item cout << "5. Exit "; cout << " Please choose: "; cin >> choice; if (choice == "1") { double num1, num2; cout << "Enter the first number: "; cin >> num1; cout << "Enter the second number: "; cin >> num2; FlCalc2 flCalc2; FlCalc result = flCalc2.allInOne(num1, num2); } else if (choice == "2") { string filename, content; cout << "Enter the filename: "; cin.ignore(); getline(cin, filename); cout << "Enter the content: "; getline(cin, content); Tools tools; tools.saveToFile(filename, content); } else if (choice == "3") { string filename; cout << "Enter the filename: "; cin.ignore(); getline(cin, filename); Tools tools; string content = tools.readFromFile(filename); if (!content.empty()) { cout << "Content of file " << filename << ": "; cout << content; } } else if (choice == "4") { string filename; cout << "Enter the result filename: "; cin.ignore(); getline(cin, filename); Tools tools; string content = tools.readFromFile(filename); if (!content.empty()) { cout << "Result content of file " << filename << ": "; cout << content; } } else if (choice == "5") { cout << name << ", Thank you for using the application. "; break; } else { cout << "Invalid choice! Please try again. "; } } return 0; } I have to use this code and You are going to implement the error trapping to any of prior applications that you developed (Week 12 or Week 14). You are going to develop 3 testcases to show how effective the error trapping. Make sure that you document the test cases errors. You must indicate where you implement the error trapping structure and why. This is using dev c++. Any help is appreciated
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started