I wrote a C++ program for a computer science class, but I apparently missed one thing. This is the statement that I overlooked: "Your program must include at least one function that uses one or more reference variables as parameters". How can I go about incorporating reference variables in my program and still get the same results (as my program does get the correct intended output)? I would appreciate any help with this. Thanks in advance!
#include <iostream>
#include <fstream>
using namespace std;
struct Letter_Stats
{
int count;
char ch;
};
void display(Letter_Stats, Letter_Stats);
int main()
{
ifstream inFile;
char ch;
int i;
Letter_Stats letters[26];
Letter_Stats small, large;
inFile.open("letter_count.txt", ios::in);
if (inFile.fail())
{
cout << "Error opening file.";
return 1;
}
for (i = 0; i<26; i++)
{
letters[i].count = 0;
letters[i].ch = ('A' + i);
}
while (!inFile.eof())
{
inFile.get(ch);
if ('A' <= toupper(ch) && toupper(ch) <= 'Z')
letters[toupper(ch) - 'A'].count++;
}
inFile.close();
small = letters[0];
large = letters[0];
for (i = 1; i<26; i++)
{
if (letters[i].count > large.count)
{
large = letters[i];
}
if (letters[i].count < small.count)
{
small = letters[i];
}
}
display(large, small);
return 0;
}
void display(Letter_Stats most, Letter_Stats least)
{
cout << "The most common letter is " << most.ch << " with " << most.count << " occurrences." << endl;
cout << "The least common letter is " << least.ch << " with " << least.count << " occurrences." << endl;
}