Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me fix my program. My professor claimed that when he had entered a text file with 12 words starting with the letter

Can someone help me fix my program. My professor claimed that when he had entered a text file with 12 words starting with the letter 'D' or 'd' it brought back up 10. Here is the problem:

Query the user for the name of a file. Open and process that file, reporting the number of words that begin with the letter d, irrespective of case. The input file for testing this assignment is posted on Blackboard.

Program is in C++

Input file:

Dozens of years ago in a drafty castle Duke David of Dundeedle did dwell. David's dimpled daughter Dora was a delight. oscar

Program:

#include  #include  #include  #include  #include  using namespace std; int main(void) { int count; char curr, prev; string inputFileName; string s; ifstream fileIn; cout<<"Enter name of file of characters :"; cin>>inputFileName; fileIn.open(inputFileName.data()); assert(fileIn.is_open() ); curr=' '; count=0; while(!(fileIn.eof())){ prev=curr; curr=fileIn.get(); if(prev==' '){ switch (curr){ case 'd': case 'D': count++; } } } cout<<"The number of words starting with the letter D are "<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

Students also viewed these Databases questions