Question

Using C++ Use the below program. Fill in the code for the 2 functions. The expected...

Using C++

Use the below program. Fill in the code for the 2 functions.
The expected output should be:

The:fox:jumps:over:the:fence.:
The:fox:jumps:over:the:fence.:
The:fox:jumps:over:the:fence.:
The:fox:jumps:over:the:fence.:

#include
#include
#include


using namespace std;

//Assume a line is less than 256

//Prints the characters in the string str1 from beginIndex
//and inclusing endIndex
void printSubString( const char* str1 , int beginIndex, int endIndex )
{

}


void printWordsInAString( const char* str1 )
{
}


int main()
{
char str1[] = "The fox jumps over the fence." ;
char str2[] = "The        fox jumps over the fence." ;
char str3[] = "     The fox jumps over the fence." ;
char str4[] = "The fox jumps over the fence. " ;


printWordsInAString( str1 ) ;
cout << endl ;
printWordsInAString( str2 ) ;
cout << endl ;

printWordsInAString( str3 ) ;
cout << endl ;
printWordsInAString( str4 ) ;
cout << endl ;


return( 1 ) ;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/******************************************************************************

Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/
#include <iostream>
#include <string>
#include <cstring>


using namespace std;

//Assume a line is less than 256

//Prints the characters in the string str1 from beginIndex
//and inclusing endIndex
void printSubString( const char* str1 , int beginIndex, int endIndex )
{
int i;
for (i = beginIndex; i <= endIndex; i++){
cout << str1[i];
}
cout << ":";
}

void printWordsInAString( const char* str1 )
{
int index,beginIndex,endIndex;
   beginIndex = 0;
   endIndex = 0;
   index = 0;
  
while(str1[index] != '\0'){
if (isspace(str1[index])){
           if (endIndex > beginIndex){
               printSubString(str1,beginIndex,(endIndex-1));
               beginIndex = endIndex;
           }
           beginIndex++;
}
       endIndex++;
       index++;
}
if (endIndex > beginIndex){
   printSubString(str1,beginIndex,(endIndex-1));
   }
}


int main()
{
char str1[] = "The fox jumps over the fence." ;
char str2[] = "The fox jumps over the fence." ;
char str3[] = " The fox jumps over the fence." ;
char str4[] = "The fox jumps over the fence. " ;


printWordsInAString( str1 ) ;
cout << endl ;
printWordsInAString( str2 ) ;
cout << endl ;

printWordsInAString( str3 ) ;
cout << endl ;
printWordsInAString( str4 ) ;
cout << endl ;


return( 1 ) ;
}

output

The:fox:jumps:over:the:fence.:
The:fox:jumps:over:the:fence.:
The:fox:jumps:over:the:fence.:
The:fox:jumps:over:the:fence.:

Add a comment
Know the answer?
Add Answer to:
Using C++ Use the below program. Fill in the code for the 2 functions. The expected...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! myst...

    SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...

  • You are to implement a MyString class which is our own limited implementation of the std::string...

    You are to implement a MyString class which is our own limited implementation of the std::string Header file and test (main) file are given in below, code for mystring.cpp. Here is header file mystring.h /* MyString class */ #ifndef MyString_H #define MyString_H #include <iostream> using namespace std; class MyString { private:    char* str;    int len; public:    MyString();    MyString(const char* s);    MyString(MyString& s);    ~MyString();    friend ostream& operator <<(ostream& os, MyString& s); // Prints string    MyString& operator=(MyString& s); //Copy assignment    MyString& operator+(MyString&...

  • Problem with C++ program. Visual Studio say when I try to debug "Run-Time Check Failure #2...

    Problem with C++ program. Visual Studio say when I try to debug "Run-Time Check Failure #2 - Stack around the variable 'string4b' was corrupted. I need some help because if the arrays for string4a and string4b have different sizes. Also if I put different sizes in string3a and string4b it will say that those arrays for 3a and 3b are corrupted. But for the assigment I need to put arrays of different sizes so that they can do their work...

  • C++ Write a MyString class that stores a (null-terminated) char* and a length and implements all...

    C++ Write a MyString class that stores a (null-terminated) char* and a length and implements all of the member functions below. Submit your completed source (.cpp) file. Default constructor: empty string const char* constructor: initializes data members appropriately Copy constructor: prints "Copy constructor" and endl in addition to making a copy Move constructor: prints "Move constructor" and endl in addition to moving data Copy assignment operator: prints "Copy assignment" and endl in addition to making a copy Move assignment operator:...

  • In C programming Write the implementation for the three functions described below. The functions are called...

    In C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. Write a print_string function that prints the characters in a string to screen on- by-one. Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1 if...

  • C programming Write the implementation for the three functions described below. The functions are called from...

    C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. a) Write a print_string function that prints the characters in a string to screen on- by-one. b) Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1...

  • Write a MyString class that stores a (null-terminated) char* and a length and implements all of...

    Write a MyString class that stores a (null-terminated) char* and a length and implements all of the member functions below. Default constructor: empty string const char* constructor: initializes data members appropriately Copy constructor: prints "Copy constructor" and endl in addition to making a copy Move constructor: prints "Move constructor" and endl in addition to moving data Copy assignment operator: prints "Copy assignment" and endl in addition to making a copy Move assignment operator: prints "Move assignment" and endl in addition...

  • Take the following C++ code and add to it the following: Write a program that reads...

    Take the following C++ code and add to it the following: Write a program that reads a string and outputs the number of times each lowercase vowel appears in it. Your program must contain a function with one of its parameters as a char variable, and if the character is a vowel, it increments that vowel's count. #include<iostream> #include<string> using namespace std; int countVowel(char, char); int main(void) { string str1; int countA = 0; int countE = 0; int countI...

  • In C++ please! *Do not use any other library functions(like strlen) than the one posted(<cstddef>) in the code below!* /** CS 150 C-Strings Follow the instructions on your handout to complete t...

    In C++ please! *Do not use any other library functions(like strlen) than the one posted(<cstddef>) in the code below!* /** CS 150 C-Strings Follow the instructions on your handout to complete the requested function. You may not use ANY library functions or include any headers, except for <cstddef> for size_t. */ #include <cstddef> // size_t for sizes and indexes ///////////////// WRITE YOUR FUNCTION BELOW THIS LINE /////////////////////// ///////////////// WRITE YOUR FUNCTION ABOVE THIS LINE /////////////////////// // These are OK after...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT