Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C++)Recieving system and timeoout errors only on one software. I am wrting a string manipulation code to post as an assignment on a textbook software

(C++)Recieving system and timeoout errors only on one software.

I am wrting a string manipulation code to post as an assignment on a textbook software called zyBooks. My code runs fine on any IDE that I try, but whenever I post on zyBooks I get one of three errors: either an out of bounds error, a timeout error, or some traceback/memory error related to python. I contacted tech support but so far they haven't been much help. I'll attach a copy of my code as well as a couple of the errors I've recieved.

Code:

#include #include using namespace std;

int main() {

int GetNumOfNonWSCharacters(string); int GetNumOfWords(string); int FindText(string, string); string ReplaceExclamation(string); string ShortenSpace(string); char printMenu(); char option; string text, phraseToFind; cout << "Enter a sample text:"; getline (cin, text); cout << "You entered:" << text; while(1) { option = printMenu(); switch(option) { case 'q': case 'Q': exit(0); case 'c': case 'C': cout << "Number of non-whitespace characters:" << GetNumOfNonWSCharacters(text); break; case 'w': case 'W': cout << "Number of words:" << GetNumOfWords(text); break; case 'f': case 'F': cout << "Enter a word or phrase to find: "; getline(cin, phraseToFind); cout << phraseToFind << " instances: " << FindText(text, phraseToFind); break; case 'r': case 'R': text = ReplaceExclamation(text); cout << "Edited text: " << text; case 's': case 'S': text = ShortenSpace(text); cout << "Edited text: " << text; break; default: cout << "Invalid choice... Try again."; break; } } return 0; }

char printMenu() { char ch; cout << " \t Menu Options: "; cout << " \t c - Number of non-whitespace characters \t w - Number of words \t f - Find text \t r - Replace all !'s \t s - Shorten spaces \t q - Quit"; cout <<" \t Choose an option: "; cin >> ch; return ch; }

int GetNumOfNonWSCharacters(const string text) { int cnt = 0, i; int len = text.size(); for (i = 0; i < len; i++) { if(!isspace(text[i])) { cnt++; } } return cnt; }

int GetNumOfWords(const string text) { int i; int words; int len = text.size();

for (i = 0; i < len;) { if (isspace(text[i])) { while (isspace(text[i])) i++; words++; } else { i++; } } return words; }

string ReplaceExclamation(string text) { string newText = text; int i, len = text.size(); for (i = 0; i < len; i++) { if (text[i] == '!') newText[i] = '.'; } return newText; }

string ShortenSpace(string text) { char *newText; int i, len = text.size(), k = 0; newText = new char [len + 1]; for (i = 0; i < len; k++) { newText[k] = text[i]; if (isspace(text[i])) { while (isspace(text[i])) i++; } else { i++; } } newText[k] = '\0'; return newText; }

int FindText (string text, string phrase) { int count = 0; if (phrase.size() == 0) return 0; for(size_t offset = text.find(phrase); offset != std::string::npos; offset = text.find(phrase, offset + phrase.size())) { ++count; } return count; }

Errors:

Traceback (most recent call last): File "./run", line 20, in print(json.dumps(runner.run())) File "/home/runner/local/submission/explore_runner.py", line 98, in run timeout=self.TIMEOUT_SECONDS)[0].decode('utf8') File "/usr/lib/python3.5/subprocess.py", line 1072, in communicate stdout, stderr = self._communicate(input, endtime, timeout) File "/usr/lib/python3.5/subprocess.py", line 1735, in _communicate data = os.read(key.fd, 32768) OSError: [Errno 14] Bad address

Submission failed. Please verify your code and try again.

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

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

More Books

Students also viewed these Databases questions

Question

How has social media emerged as an important force in recruiting?

Answered: 1 week ago