??? Unexpected output from std-out (between --): -- Enter sequence for region: --
1 1 1 1 -1 1 1 1 1 -1 1 1 1 1 -1 1 1 1 1 -1 1 1 1 1 1 1 30x100 region
“Can input be like this...?”is “Yes.”
int region[15][15] int main() int rows, cols cin >> rows >> cols // if rows*cols > 15*15: oops! for (int r = 0; r < rows; r++) for (int c = 0; c < cols; c++) cin >> region[r][c]
../../test-code: line 165: 10192 Segmentation fault ... ../../test-code: line 133: 10060 Killed ...
cin >> regionSizeA >> regionSizeB loopSize = (regionSizeA*regionSizeB) int * elevationArray = new int[loopSize]
regionSizeA
? What's regionSizeB
? Who knows?
terminate after throwing an instance of 'std::bad_alloc' what(): St9bad_alloc ../../test-code: line 185: 3683 Done 3684 Aborted (core dumped)
static std::string read_signed(std::istream & ins, int * value) // Read an int from ins and store it in *value. // Return an error message or the empty string // if no errors. ins >> *value if (ins.eof()) return "Unexpected eof" if (ins.fail()) return "Unexpected non-integer value" if (ins.bad()) return "Unrecoverable I-O error" return ""
bool isNotAnInt(string s) bool isNaI = false if (s[0] == '-') //if it's a negative number //skip 1st character, goes through chars in string for (unsigned int k = 1; k < s.length(); k++) //if it's not a # or if it's a decimal if(!(isdigit(s[k])) || s[k] == '.') isNaI = true else //goes through chars in string for (unsigned int j = 0; j < s.length(); j++) //if it's not a # or if it's a decimal if (!(isdigit(s[j])) || s[j] == '.') isNaI = true return isNaI int validateWidth(string s) int number = atoi(s.c_str()) if (isNotAnInt(s)) // error else if (!(withinRange(number))) // error else return number int getWidth() string strWidth cin >> strWidth return validateWidth(strWidth)
// Takes string and returns true if it is // an int and false if it is not an int. bool isNotAnInt(string s) { ... }
// Return true iff the entire string s can // be interpreted as a decimal integer. bool isNotAnInt(string s) { ... }
*** 1 1 1 1 test. *** -1 1 1 1 test. *** 1 -1 1 1 test. *** 1 1 1 -1 test. ??? Unexpected output from std-err (between --): -- !!!Rainfall should be a non-negative integer, Not, -1 -- *** 1 1 1 test. ??? Output expected from std-err, none produced. *** 1 1 test. *** 1 test. *** 30x100 test.
cerr << "!!! Row should be non negative, not " << row cerr << "!!! Column should be non negative, not " << col cerr << "!!! Region height should be an integer" << endl cerr << "!!!Rainfall should be non-negative, Not, " << rainfall << endl
void perr(const string & emsg) cerr << "!!! " < emsg < ".\n" exit(EXIT_FAILURE) perr(string("Row should be non negative, not ") + row) perr(string("Column should be non negative, not " + col) perr("Region height should be an integer") perr(string("Rainfall should be non-negative, not ") + rainfall)