Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include #include #include using namespace std; bool isFileValid(string); bool isValidPLU(string); bool isValidName(string); bool isValidType(string); bool isValidPrice(string); bool isValidInventory(string); string tokenize(string &); int

#include #include #include #include #include #include using namespace std; bool isFileValid(string); bool isValidPLU(string); bool isValidName(string); bool isValidType(string); bool isValidPrice(string); bool isValidInventory(string); string tokenize(string &); int getWordsCount(string); int main() { cout << "***Checking inventory.txt***" << endl; if (isFileValid("in1.txt")) cout << "***inventory.txt has valid content***" << endl; else cout << "***inventory.txt has invalid content***" << endl; } bool isFileValid(string) { ifstream myfile("in1.txt"); bool status = true; string line; string token; if (myfile.is_open()) { while (getline(myfile, line)) { cout << endl; int i = 1; int c = getWordsCount(line); while (line.length() != 0 && i < c+2) { if (i == 5 && c == 4) token = line; else token = tokenize(line); if (i == 1) { if (isValidPLU(token)) cout << "Token #1 is " << token << ", PLU is valid" << endl; else { cout << "Token #1 is " << token << ", PLU is invalid" << endl; status = false; } } else if (i == 2) { if (isValidName(token)) cout << "Token #2 is " << token << ", Product name is valid" << endl; else { cout << "Token #2 is " << token << ", Product name is invalid" << endl; status = false; } } else if (i == 3) { if (isValidType(token)) cout << "Token #3 is " << token << ", Sales type is valid" << endl; else { cout << "Token #3 is " << token << ", Sales type is invalid" << endl; status = false; } } else if (i == 4) { if (isValidPrice(token)) cout << "Token #4 is " << token << ", Price is valid" << endl; else { cout << "Token #4 is " << token << ", Price is invalid" << endl; status = false; } } else if (i == 5) { if (isValidInventory(token)) cout << "Token #5 is " << token << ", Inventory is valid" << endl; else { cout << "Token #5 is " << token << ", Inventory is invalid" << endl; status = false; } } else if (i == 6) { cout << "Token #6 is " << token << ", Too many items in record" << endl; status = false; } i++; } } } else cout << "Unable to open the file!!!" << endl; return status; } string tokenize(string &line) { std::string delimiter = " "; size_t pos = 0; std::string token = ""; if ((pos = line.find(delimiter)) != std::string::npos) { token = line.substr(0, pos); line.erase(0, pos + delimiter.length()); } return token; } bool isValidPLU(string str) { bool st = false; if (str.length() != 4) { return false; } else { for (int i = 0; i < str.length(); i++) { char ch = str[i]; if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { st = true; } else if (ch >= '0' && ch <= '9') { st = true; } else { return false; } } } return st; } bool isValidName(string str) { char ch = str[0]; if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) return true; else return false; } bool isValidType(string str) { if (str.length() == 1 && (str[0] == '0' || str[0] == '1')) return true; else return false; } bool isValidPrice(string str) { bool st = false; int dot = 0; for (int i = 0; i < str.length(); i++) { char ch = str[i]; if (ch >= '0' && ch <= '9') { st = true; } else if (ch == '.') { dot++; if (dot > 1) return false; else { st = true; string str2 = str.substr(i, str.length()); if (str2.length() > 3) return false; } } else { return false; } } return st; } bool isValidInventory(string str) { bool st = false; int dot = 0; for (int i = 0; i < str.length(); i++) { char ch = str[i]; if (ch >= '0' && ch <= '9') { st = true; } } return st; } int getWordsCount(string str) { int words = 0; // Holds number of words for (int i = 0; str[i] != '\0'; i++) { if (str[i] == ' ') //Checking for spaces { words++; } } return words; } *****This is my code but for some reason I keep getting a warning that says "Warning: unused variable 'dot'. my compiler is code:: blocks.

I highlighted the line in my code where i keep getting the error. I also have 3 other warning saying "Warning: Comparison between signed and unsigned integer expression". I also highlighted these warnings as well

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

4. Does cultural aptitude impact ones emotional intelligence?

Answered: 1 week ago