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...
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...
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];...
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);...
#include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...
C++: Need help debugging my code I am writing this and using some other examples as reference code while rewriting it with my own understanding of the material but am having trouble making it finally compile. Below is a picture of the error messages. //main.cpp //Semester Project //Created by J---on 5/6/2019 #include <iostream> #include <fstream> #include <string> #include <sstream> #include <bits/stdc++.h> using namespace std; void instructions(); //displays program details and instructions void openFile(); void takeInput(int*); void switchBoard(int*); struct price {...