Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help to the coding already working. 1. Create a namespace called cs135 and place all prototypes and functions implementations in the cs135 namespace. Remember,

need help to the coding already working.

1. Create a namespace called cs135 and place all prototypes and functions implementations in the cs135 namespace. Remember, you will be declaring the namespace in two locations. One for your prototypes and one for your function implementations.

2. DO NOT use the "[ ]" operator to access characters in strings. DO use the at() function instead. do not use vector

3. format the output as the photo

I paste the pa07.cpp cod here (the code already working)./// @file pa07.cpp #include #include #include #include

/// ------------------------------------------------------------------------- /// Function Prototype(s) /// ------------------------------------------------------------------------- bool ValidInput(std::string line); bool CheckSum(std::string number, int caseNum);

using namespace std;

int main() { const string filename = "pa07-input0data.txt"; ifstream inputfile(filename);

if (inputfile.is_open()) { string line; int caseNum = 1; while (getline(inputfile, line)) { CheckSum(line, caseNum); caseNum++; } inputfile.close(); } else { cout

return 0; } /// ------------------------------------------------------------------------- /// Function Implementation(s) /// ------------------------------------------------------------------------- bool ValidInput(string line) { // Remove all dashes and spaces from the line string strippedLine = ""; for (char c : line) { if (c != ' ' && c != '-') { strippedLine += c; } }

// Check if line is a 10-digit number with optional 'A' at the end bool isValid = true; if (strippedLine.length() != 10 && strippedLine.length() != 11) { isValid = false; } else { for (int i = 0; i

return isValid; } bool CheckSum(string number, int caseNum) { // Remove any dashes or spaces string strippedNumber = ""; for (char c : number) { if (c != ' ' && c != '-') { strippedNumber += c; } }

// Check that number is valid if (!ValidInput(strippedNumber)) { cout

// Convert digits to ints and store in vector vector original(10); for (int i = 0; i

// Calculate check digit int checkDigit = 0; for (int i = 0; i

// Check if check digit is valid if (checkDigit % 11 != 0) { cout

// If everything checks out, the number is valid cout

image text in transcribedimage text in transcribed
Sample Interaction $ ./pa07 Name of the file to be processed: pa07input0data.txt Case 1: 6897237761676 is correct Case 2: 6837063763774 is correct Case 3: 6067017775876 is correct Case 4: incorrect product number Case 5: 1567884763676 is correct Case 6: 6827362757173 is correct Case 7: 6347531738676 is correct Case 8: 6677188785877 is correct Case 9: incorrect product number Case 16: 6677174711975 is correct Case 11: 6817252763670 is correct Case 12: incorrect product number Case 13: 6457226774674 is correct Case 14: 6137139767274 is correct Case 15: 613715274477A is correct 5 \f

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_2

Step: 3

blur-text-image_3

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions