Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The problem is as follows: On the student CD you will find a file named text.txt

ID: 3622082 • Letter: T

Question

The problem is as follows:
On the student CD you will find a file named text.txt. Write a program that reads the file's contents and determines the following:
* The number of uppercase letters in the file
* The number of lowercase letters in the file
* The number of digits in the file
* The number of whitespace characters in the file
* The number of punctuation marks in the file

There is an answer listed for this but it doesn't compile. There is a run-time error that sates that The variable 'c' is being used without being initialized.

I was wondering if you could rework this with explinations. I want to learn this which is why I would like to see explinations.

Thanks for your time.

This is what was listed for an answer but doesn't compile:


#include
#include
using namespace std;

int main()
{ ifstream in;
char c;
int up=0,low=0,d=0,white=0;
in.open("text.txt");
if(in.fail())
{ cout<<"file did notopen please check it ";
system("pause");
return 1;
}

while(in)
{if(isupper(c))
up++;
else if(islower(c))
low++;
else if(isdigit(c))
d++;
else if(isspace(c))
white++;
in.get(c);
}
cout<<"Uppercase characters:"system("pause");
return 0;
}

Explanation / Answer

Hope this helps. Let me know if you have any questions. Please rate. :) The main reason it was not working was because you were using c before reading in from the file. You should add a "in.get(c);" before the while loop, and then it should run fine. I changed a few other minor details, and added comments explaining each step. Here ya go: #include #include using namespace std; int main() { // declare our local variables: // ifstream used for an input file stream ifstream in; // this char will be used to read one character at a time from the file char c; // these will represent our running counts for uppercase, lowercase, // digits, and whitespace characters int up = 0, low = 0, d = 0, white = 0; // open the file in.open("text.txt"); // if the file failed to open, notify the user and exit the program if(!in.is_open()) { cout