The code keeps saying its generating too much output check for any unterminated loops. I cant find any. Can anyone help?
#include <iostream>
#include <string>
using namespace std;
char printMenu();
int GetNumOfNonWSCharacters(string);
int GetNumOfWords(string);
void ReplaceExclamation(string&);
void ShortenSpace(string&);
int FindText(string, string);
int main(){
char option;
string text, phraseToFind;
cout << "\n\n Enter a sample text: ";
getline(cin, text);
cout << "\n\n You entered: " << text;
while(1){
option = printMenu();
switch(option){
case 'q':
case 'Q': return 0;
case 'c':
case 'C': cout << "\n\n Number of non-whitespace characters:
" << GetNumOfNonWSCharacters(text) << "\n\n";
break;
case 'w':
case 'W': cout << "\n\n Number of words: " <<
GetNumOfWords(text) << "\n\n";
break;
case 'f':
case 'F': cin.ignore(); cout << "\n\n Enter a word/Phrase to
find: "; getline(cin, phraseToFind);
cout << "\n\n \"" << phraseToFind << "\"
instances: " << FindText(text, phraseToFind) << "
\n\n";
break;
case 'r':
case 'R': ReplaceExclamation(text); cout << "\n\n Edited
text: " << text << "\n\n";
break;
case 's':
case 'S': ShortenSpace(text); cout << "\n\n Edited text: "
<< text << "\n\n";
break;
default: cout << "\n\n Invalid Choice.... Try Again \n\n";
break;
}
}
cout << "\n\n";
return 0;
}
char printMenu()
{
char ch;
cout <<"\n\n\t Menu Options: \n";
cout << "\n \t c - Number of non-whitespace characters \n\t w
- Number of words \n\t f - Find text \n\t r - Replace all !'s \n\t
s - Shorten spaces \n\t q - Quit";
cout <<"\n\n\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 words = 0, i;
int len = text.size();
for(i=0; i<len;)
{
if(isspace(text[i]))
{
while(isspace(text[i]))
i++;
words++;
}
else
{
i++;
}
}
words = words + 1;
return words;
}
void ReplaceExclamation(string& text)
{
string newText = text;
int i, len = text.size();
for(i=0; i<len; i++)
{
if(text[i] == '!')
newText[i] = '.';
}
text = newText;
}
void 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';
text = newText;
}
int FindText(string text, string phrase)
{
int count = 0;
if (phrase.size() == 0)
return 0;
for(size_t offset = text.find(phrase); offset != string::npos;
offset = text.find(phrase, offset + phrase.size()))
{
++count;
}
return count;
}
I have run the program.Its perfectly working fine.If you want to quit the program ,press 'q'.
I have given the compiling command also.Please use it .
You can see the below screenshots:


The code keeps saying its generating too much output check for any unterminated loops. I cant...
(1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews...
#include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here. */ int GetNumOfNonWSCharacters(const char usrStr[]) { int length; int i; int count = 0; char c; length=strlen(usrStr); for (i = 0; i < length; i++) { c=usrStr[i]; if ( c!=' ' ) { count++; } } return count; } int GetNumOfWords(const char usrStr[]) { int counted = 0; // result // state: const char* it = usrStr; int inword = 0; do switch(*it)...
C++ (1) Prompt the user to enter a string of their choosing (Hint: you will need to call the getline() function to read a string consisting of white spaces.) Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!...
I need assistance with this code. Is there any way I can create
this stack class (dealing with infix to postfix then postfix
evaluation) without utilizing <stdio.h> and
<math.h>?
____________________________________________________________________________________________
C++ Program:
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
using namespace std;
//Stack class
class STACK
{
private:
char *str;
int N;
public:
//Constructor
STACK(int maxN)
{
str = new char[maxN];
N = -1;
}
//Function that checks for empty
int empty()
{
return (N == -1);
}
//Push...
c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...
Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found; string document[1000][6]; ifstream infile; char s[1000];...
C++ Programming I have finished the code but there's one error which shows that "strcpy" might be unsafe. Consider using strcpy_s instead. I've tried that but it's not working probably because I didn't implement it correctly. I am posting my code below. It'd be really helpful if you could fix all the strcpy errors and post it below. Thank you. Text.cpp: #include <iostream> #include <iomanip> #include <cassert> #include <cstring> #include "Text.h" Text::Text ( const char *charSeq ) { bufferSize...
Hi there! I need to fix the errors that this code is giving me and also I neet to make it look better. thank you! #include <iostream> #include <windows.h> #include <ctime> #include <cstdio> #include <fstream> // file stream #include <string> #include <cstring> using namespace std; const int N=10000; int *freq =new int [N]; int *duration=new int [N]; char const*filename="filename.txt"; int songLength(140); char MENU(); // SHOWS USER CHOICE void execute(const char command); void About(); void Save( int freq[],int duration[],int songLength); void...
1. What would be the output of the following lines of code: int num = 2; switch(num){ case 1: cout << "1"; case 2: cout << "2"; case 3: cout << "3"; case 4: cout << "4"; } 2. What would be the output of the following code: char op = '*'; switch(op){ case '+': cout << "Addition"; break; case '-': cout << "Subtraction"; break; case '/': cout << "Division"; break; default: cout << "Invalid"; } 3. What would be...
The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...