Hi there! I am new to C++ and I will be straight forward and say that this is an assignment and I want someone to review my progress to see if I am headed in the right direction!!!
The assignment is as follows: (below the assignment, I will post my code)
Thanks to anyone for any help or pointers!!!
Phase 1) Arrays of characters
· Read in a paragraph (or more) from the user (hint: read one word at a time)
· As you read, count the number of times they use “but”, “and”
· Count the number of times words end in ‘;’
· Count the number of words.
· Do not echo the paragraph!
· Stop reading when the user has entered a # sign as the first character on a line
· Output the results to the user
Phase 2) External Data Files
· Once you are comfortable with Phase 1, add the ability to write the paragraph to an external data file
· The filename should be read in from the user (prompt/read/echo/confirm)
· Near the end of the program, Phase 2 should add the ability to read the text back into the program. This time you are interested in counting the number of sentences (ending in period only). (hint: read using the 3 argument version of cin.get)
· Output the paper back to the user as you read. Make sure as you do this to capitalize the first letter of each sentence.
Important things to keep in mind
1. Write at least three functions with arguments for this assignment.
2. Allow the user to enter in the name of the external data file.
3. Watch out. When using the 3 argument version of cin.get you need to make sure to remove all delimiter (.) from the input buffer.
4. You should use the cstring library strcmp, strcpy, and strlen functions.
5. The program should experiment with BOTH cin >> array as well as cin.get( 3 argument);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char *allwords[1000]; // array of POINTERS to char strings
char word[500]; // input buffer for longest possible word.
int n = 0;
int wordcount;
int butcount;
int andcount;
int semicoloncount;
int periodcount;
// Prompt for sentence and return number of words entered
do
{
cout << " Please enter a sentence: ";
cin >> (str, 30);
cin.ignore();
++wordcount;
But (str, butcount);
cout << "back from But" << endl;
And (str, andcount);
cout << "back from And" << endl;
Semicolon (str, semicoloncount);
cout << "back from Semicolon" << endl;
Period (str, periodcount);
cout << " back from Period" << endl;
}
while (str[0] != '#');
|