Using Structs to count the capital and lower A-Z

I have already looked for a solution to this problem, but as of right now I'm still not having any luck. Here is the instructions:

Write a program whose main function is merely a collection of variable declarations and function calls. This program reads a text and outputs the letters, together with their counts, as explained below in the function printResult. (There can be no global variables! All information must be passed in and out of the functions. Use a structure to store the information.)

* Function count: Count every occurrence of capital letters A-Z and small letters a-z in the text file opened in the function openFile. This information must go into an array of structures. The array must be passed as a parameter, and the file identifier must also be passed as a parameter.



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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;

struct charCount
{
	char letter;
	int count;


charCount()
{
	letter = '\0';
	count = 0;
}
};

void openFile ( ifstream& input,  ofstream& output);
void countFunction (charCount letters[], ifstream& input);
void printResult (charCount letters[], ofstream& output);



int main ()
{	const int Max_Letters = 52;
	charCount characters[Max_Letters];
	ifstream infile;
	ofstream outfile;
	string inputName, outputName;
	
	
	openFile(infile,outfile);
	countFunction(characters, infile);
	printResult(characters, outfile);
	
	
    return 0;
}

void openFile (ifstream& input, ofstream& output)
{
	string inName, outName;
	cout << "Please enter the input file name." << endl;
	cin >> inName;
	input.open(inName.c_str());
	
	if(!input)
	{
		cout << "Error, the file with the name " << inName << " does not exist." << endl;
		return;
	}
	
	cout << "Please enter the output file name. " << endl;
	cin >> outName;
	output.open(outName.c_str());
void countFunction(charCount letters[], ifstream& input)
{
char ch;
	string alpha = "ABCDEFGHIJKLMNOPRSTUVWXYZabcdefhijklmnopqrstuvwxyz";

	for( int i = 0; i < 51; i++)
	{
		letters[i].letter = alpha[i];
		cout << letters[i].letter << endl;
	}
	
	


This is all I have so far.

Any help would be greatly appreciated.
Last edited on
I just need help figuring how to count the lower and upper case characters and storing it in a struct
Topic archived. No new replies allowed.