Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE COMPLETE BELOW C++ PROGRAM I HAVE DONE PART A AND B PLEASE READ THE QUESTION AND Please add further C++ PROGRAM Q) Create a

PLEASE COMPLETE BELOW C++ PROGRAM I HAVE DONE PART A AND B PLEASE READ THE QUESTION AND Please add further C++ PROGRAM Q) Create a file named dummy.txt manually and store any text of 500 words and perform following operations: a) Read file and print data on screen.(done) b) Count total letters, words and sentences from text file. (done) c) Create a file named info-dummy.txt and store total letters, words and sentences in following pattern: Letters: 125 Words: 70 Sentences: 8 d) Read above file named info-dummy.txt and add letters, words, sentence and print on screen. Letters: 125 Words: 70 Sentences: 8 Output: 203 (125+70+8)

#include  #include  #include  using namespace std; int main(){ fstream newfile; newfile.open("dummy.txt",ios::out); // open a file to perform write operation using file object if(newfile.is_open()) //checking whether the file is open { newfile<<"Chegg "; //inserting text newfile.close(); //close the file object } newfile.open("dummy.txt",ios::in); //open a file to perform read operation using file object if (newfile.is_open()){ //checking whether the file is open string tp; while(getline(newfile, tp)){ //read data from file object and put it into string. cout << tp << " "; //print the data of the string } newfile.close(); //close the file object. } }

part b)

#include  #include  using namespace std; int main() { ifstream lab3; string word; lab3.open("dummy.txt"); int countletters=0,countnum=0,countpunc=0,countspace=0,words=0,line=0; char character,prevchar = 0; if(!lab3) { cout << "Could not open file" << endl; return 1; } while(lab3.get(character) && !lab3.eof()) { if(isalpha(character)) { countletters++; } if (isdigit(character)) { countnum++; } if (ispunct(character)) { countpunc++; if (isalpha(prevchar)) { words++; } } if (isspace(character)) { countspace++; if (isalpha(prevchar)) { words++; } } if(character==' ') { line++; } prevchar = character; } cout << "There are " << countletters << " letters." << endl; cout << "There are " << countnum << " numbers." << endl; cout << "There are " << countpunc << " punctuations." << endl; cout << "There are " << countspace << " spaces." << endl; cout << "There are " << words << " words." << endl; cout << "There are " << line << " sentences." << endl; lab3.close(); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

ISBN: 0764549634, 9780764549632

More Books

Students also viewed these Databases questions