Hello I was wondering if anyone could help me with this prog
Hello I was wondering if anyone could help me with this programming assignment in C++. Thanks in advance! :
The purpose of this assignment is to practice using strings and C-strings. Your task is to create a class that counts words (by looking for spaces) and sentences (by looking for periods). The data will either come in dribs-and-drabs. Use the infamous operator \"<<\" to output the data seen so far. Because std::string is a class, I\'d recommend you use it to store the text information that has been entered through calls to addData and addStringData.
Implementation Details
Sample Driver
SpeechAnalyst
SpeechAnalyst( );
void clear( ); // resets everything...
void addData( char * stuff );
void addStringData( std::string stuff );
int getNumberOfWords( ) const;
int getNumberOfSentences( ) const;
friend ostream& operator << ( ostream& outs, const SpeechAnalyst & sa ); // prints the data seen so far!
std::string myData;
SpeechAnalyst sa;
cout << sa << endl;
std::string speech( \"Fourscore and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty and dedicated to the proposition that all men are created equal.\" );
sa.addStringData( speech );
cout << sa << endl;
sa.clear();
char * data = new char[ 50 ];
strcpy( data, \"Muffin says Hello.\" );
sa.addData( data );
cout << sa << endl;
sa.addData( data );
cout << sa << endl;
Sample Output
No data to print out....
Data has 29 words and 1 sentence.
Data has 3 words and 1 sentence.
Data has 6 words and 2 sentences.
HINT: You may add additional methods to the SpeechAnalyst class as long as you implement those defined in the original class definition.
| Implementation Details | Sample Driver | |||
| SpeechAnalyst sa; sa.clear(); | |||
| Sample Output | ||||
| No data to print out.... |
Solution
Iam giving you the C++ code for printing the number of words and spaces and lines in a given string ....
#include<fstream.h>
#include<conio.h>
void main() { clrscr();
ifstream fin(“STORY.TXT”);
char ch;
int number1, number2; // Declare 2 integer variable number1 and number2
int sum, difference, product, quotient, remainder; // declare 5 int variables
// Prompt user for the two numbers
cout << \"Enter two integers (separated by space): \";
cin >> number1 >> number2;
// Do arithmetic Operations
sum = number1 + number2;
difference = number1 - number2;
product = number1 * number2;
quotient = number1 / number2;
remainder = number1 % number2;
cout << \"The sum, difference, product, quotient and remainder of \"
<< number1 << \" and \" << number2 << \" are \"
<< sum << \", \"
<< difference << \", \"
<< product << \", \"
<< quotient << \", and \"
<< remainder << endl;
// Increment and Decrement
++number1; // Increment the value stored in variable number1 by 1
// same as \"number1 = number1 + 1\"
--number2; // Decrement the value stored in variable number2 by 1
// same as \"number2 = number2 - 1\"
cout << \"number1 after increment is \" << number1 << endl;
cout << \"number2 after decrement is \" << number2 << endl;
quotient = number1 / number2;
cout << \"The new quotient of \" << number1 << \" and \" << number2
<< \" is \" << quotient << endl;
return 0;


