Write programs using loop and switch statements to count all the punctuation marks
in a file. A shell program is given below as a staring point.
//Count punctuation marks in a file.
#include
#include
using namespace std;
int main ()
{
ifstream inData;
char symbol;
int periodCt = 0; //The total number of periods (.)
int commaCt = 0; //The total number of commas (,)
int questionCt = 0; //The total number of question marks (?)
int colonCt = 0; //The total number of colons (:)
int semicolonCt = 0; //The total number of semi-colons (;)
int exclamationCt = 0; //The total number of exclamations (!)
inData.open("switch.txt");
/* FILL IN HERE */
//Use a loop to read the input data file symbol by symbol
//As reading goes, check which type of punctuation the symbol belongs to
//and increment the corresponding counter.
inData >> symbol; //Read the first symbol
while(inData)
{
//For each symbol, determine its type and increment corresponding counter.
switch()
{
}
inData >> symbol; //Read next symbol
}
//Once finishing with reading, print out the count for each punctuation mark.
return 0;
}
Symbols in the file "switch.txt" are:
*** There are lots of "symbols" in this file: ..;;??.,.,.,?:::; .!! ***