SlideShare a Scribd company logo
So basically I worked really hard on this code in my CS150 class and now I need to change it to
a class, and I thought OK that's simple enough, but I cant seem to figure it out at all! I know I
can just make all of the variables inside the class public, but that's not what my professor wants.
I am supposed to implement the private variables. I tried making the "letter" and "letterCount"
variables private and I created some void functions under the public part, I think I might have
been on the right track with that but I wasn't sure how to modify the rest of my code in order to
get it to run. Here's the original code, still in the struct format. Any help would be GREATLY
appreciated.
P.S. my professor said "make the member variables private, and impliment functions to manage
those private variables, such as getter and setter functions." so that might help you understand
whats expected. Thanks!
I NEED TO GET RID OF THE STRUCT ALLTOGETHER!
my class should be set up like this:
class
{
private:
letter
letterCount
public:
//functions to controll the private variables such as...
void getletter
void getlettercount
}
I just dont know how to impliment that in my code, and what to write in those functions in the
class. Thanks for your help!
[code]
#include
#include
#include
#include
using namespace std;
//Struct definition
struct letterType
{
char letter;
int letterCount;
};
//Function to open I/O files
void openFile(ifstream& inFile, ofstream& outFile);
//Function to fill the array of structs and keep track of the amount of uppercase/lowercase letters
void count(ifstream& inFile, letterType letterList[], int& totalBig, int& totalSmall);
//Function to print the letters, the occurences, and the percentages
void printResult(ofstream& outFile, letterType letterList[], int totalBig, int totalSmall);
//Function to create an output file that contains programmer info
void Info (ofstream& outputFile);
int main()
{
ofstream fout;
ifstream input; //object to read the text
ofstream output; //object to write the results
int totalCapital = 0; //variable to store the total number of uppercase
int totalLower = 0; //variable to store the total number of lowercase
letterType letterObj[52]; //array of structs of type letterType to hold the information
//Input and process data
Info (fout);
openFile(input, output);
count(input, letterObj, totalCapital, totalLower);
printResult(output, letterObj, totalCapital, totalLower);
//Close files
input.close();
output.close();
return 0;
}
void openFile(ifstream& inFile, ofstream& outFile)
{
string inFileName;
string outFileName;
cout << "Enter the name of the input file: ";
cin >> inFileName;
inFile.open(inFileName.c_str());
cout << endl;
cout << "Enter the name of the output file: ";
cin >> outFileName;
outFile.open(outFileName.c_str());
cout << endl;
}
void count(ifstream& inFile, letterType letterList[], int& totalBig, int& totalSmall)
{
char ch;
//Loop to initialize the array of structs; set letterCount to zero
for(int index = 0; index < 26; index++)
{
//This segment sets the uppercase letters
letterList[index].letter = static_cast(65 + index);
letterList[index].letterCount = 0;
//This segment sets the lowercase letters
letterList[index + 26].letter = static_cast(97 + index);
letterList[index + 26].letterCount = 0;
}
//read first character
inFile >> ch;
//Keep reading until end of file is reached
while(!inFile.eof())
{
//If uppercase letter or lowercase letter is found, update data
if('A' <= ch && ch <= 'Z')
{
letterList[static_cast(ch) - 65].letterCount++;
totalBig++;
}
else if('a' <= ch && ch <= 'z')
{
letterList[static_cast(ch) - 71].letterCount++;
totalSmall++;
}
//read the next character
inFile >> ch;
} //end while
} //end function
void printResult(ofstream& outFile, letterType letterList[], int totalBig, int totalSmall)
{
outFile << fixed << showpoint << setprecision(2);
outFile << "Letter Occurences Percentage" << endl;
for(int index = 0; index < 52; index++)
{
if(0 <= index && index <= 25)
{
outFile << setw(4) << letterList[index].letter << setw(12) << letterList[index].letterCount << "
";
outFile << setw(15)<< 100 * (letterList[index].letterCount /
(static_cast(totalBig)+static_cast(totalSmall))) << "%" << endl;
}
else
{
outFile << setw(4) << letterList[index].letter << setw(12) << letterList[index].letterCount << "
";
outFile << setw(15) << 100 * (letterList[index].letterCount /
(static_cast(totalBig)+static_cast(totalSmall))) << "%" << endl;
}
} //end for
} //end
void Info (ofstream& outputFile)
{
string outputFileName;
cout << "Enter your name: ";
cin >> outputFileName;
outputFileName = outputFileName+"_p4.txt";
outputFile.open(outputFileName.c_str());
outputFile << "Programmer name: Bryce Messer LAB CRN: 10342";
outputFile << " This program is a collection of variable declarations";
outputFile << " and function calls. This program reads a text and outputs";
outputFile << " the letters, together with their counts, as explained below";
outputFile << " in the function printResult.";
outputFile << "  The program consists of the following four functions: ";
outputFile << " **Function openFile: Opens the input and output files. You must pass the";
outputFile << " file streams as parameters (by reference, of course). If the file does not";
outputFile << " exist, the program should print an appropriate message and exit. The";
outputFile << " program must ask the user for the names of the input and output files.";
outputFile << "  **Function count: counts every occurrence of capital letters A-Z and";
outputFile << " small letters a-z in the text file opened in the function openFile. This";
outputFile << " information must go into an array of structures. The array must be passed";
outputFile << " as a parameter, and the file identifier must also be passed as a parameter.";
outputFile << "  **Function printResult: Prints the number of capital letters and small";
outputFile << " letters, as well as the percentage of capital letters for every letter A-Z and";
outputFile << " the percentage of small letters for every letter a-z. The percentages";
outputFile << " should look like this: ‘‘25%’’. This information must come from an array";
outputFile << " of structures, and this array must be passed as a parameter.";
outputFile << "  **Function Info: Creates an output file named 'yourName_P4.txt'";
outputFile << " that contains all your required programmer info, along with";
outputFile << " TA name,..) a description of the program ( what it does, and how),";
outputFile << " and how you approached solving it. You must include your algorithm that";
outputFile << " you wrote, including the steps and any refinements made.";
outputFile << " For Project 5, create an output file named 'yourName_P5.txt.'";
outputFile << "     ";
cout << endl;
}
[/code]
Solution
Here we are using the concept of this pointer of C++.
I have defined four functions
1) getletter()
2)setletter()
3)getlettercount()
4)setlettercount()
I dont know the name of the input file. So not able to run the code.I gave the random file number
of mine and it executed without any trouble
Please check and let me know for any quieries you have.
#include
#include
#include
#include
using namespace std;
class letterType
{
private:
char letter;
int letterCount;
public:
//functions to controll the private variables such as...
void setletter(char ch);
void setlettercount(int lcount);
char getletter();
int getlettercount();
};
void letterType::setletter(char ch)
{
this->letter = ch;
}
void letterType::setlettercount(int _letterCount)
{
this->letterCount = _letterCount;
}
char letterType::getletter()
{
return this->letter;
}
int letterType::getlettercount()
{
return this->letterCount;
}
//Function to open I/O files
void openFile(ifstream& inFile, ofstream& outFile);
//Function to fill the array of structs and keep track of the amount of uppercase/lowercase letters
void count(ifstream& inFile, letterType letterList[], int& totalBig, int& totalSmall);
//Function to print the letters, the occurences, and the percentages
void printResult(ofstream& outFile, letterType letterList[], int totalBig, int totalSmall);
//Function to create an output file that contains programmer info
void Info (ofstream& outputFile);
int main()
{
ofstream fout;
ifstream input; //object to read the text
ofstream output; //object to write the results
int totalCapital = 0; //variable to store the total number of uppercase
int totalLower = 0; //variable to store the total number of lowercase
letterType letterObj[52]; //array of structs of type letterType to hold the information
//Input and process data
Info (fout);
openFile(input, output);
count(input, letterObj, totalCapital, totalLower);
printResult(output, letterObj, totalCapital, totalLower);
//Close files
input.close();
output.close();
return 0;
}
void openFile(ifstream& inFile, ofstream& outFile)
{
string inFileName;
string outFileName;
cout << "Enter the name of the input file: ";
cin >> inFileName;
inFile.open(inFileName.c_str());
cout << endl;
cout << "Enter the name of the output file: ";
cin >> outFileName;
outFile.open(outFileName.c_str());
cout << endl;
}
void count(ifstream& inFile, letterType letterList[], int& totalBig, int& totalSmall)
{
char ch;
//Loop to initialize the array of structs; set letterCount to zero
for(int index = 0; index < 26; index++)
{
//This segment sets the uppercase letters
letterList[index].setletter(static_cast(65 + index));
letterList[index].setlettercount(0);
//This segment sets the lowercase letters
letterList[index + 26].setletter(static_cast(97 + index));
letterList[index + 26].setlettercount(0);
}
//read first character
inFile >> ch;
//Keep reading until end of file is reached
while(!inFile.eof())
{
//If uppercase letter or lowercase letter is found, update data
if('A' <= ch && ch <= 'Z')
{
letterList[static_cast(ch) - 65].setlettercount(letterList[static_cast(ch) - 65].getlettercount() + 1);
totalBig++;
}
else if('a' <= ch && ch <= 'z')
{
letterList[static_cast(ch) - 71].setlettercount(letterList[static_cast(ch) - 71].getlettercount() + 1);
totalSmall++;
}
//read the next character
inFile >> ch;
} //end while
} //end function
void printResult(ofstream& outFile, letterType letterList[], int totalBig, int totalSmall)
{
outFile << fixed << showpoint << setprecision(2);
outFile << "Letter Occurences Percentage" << endl;
for(int index = 0; index < 52; index++)
{
if(0 <= index && index <= 25)
{
outFile << setw(4) << letterList[index].getletter() << setw(12) <<
letterList[index].getlettercount() << " ";
outFile << setw(15)<< 100 * (letterList[index].getlettercount() /
(static_cast(totalBig)+static_cast(totalSmall))) << "%" << endl;
}
else
{
outFile << setw(4) << letterList[index].getlettercount() << setw(12) <<
letterList[index].getlettercount() << " ";
outFile << setw(15) << 100 * (letterList[index].getlettercount() /
(static_cast(totalBig)+static_cast(totalSmall))) << "%" << endl;
}
} //end for
} //end
void Info (ofstream& outputFile)
{
string outputFileName;
cout << "Enter your name: ";
cin >> outputFileName;
outputFileName = outputFileName+"_p4.txt";
outputFile.open(outputFileName.c_str());
outputFile << "Programmer name: Bryce Messer LAB CRN: 10342";
outputFile << " This program is a collection of variable declarations";
outputFile << " and function calls. This program reads a text and outputs";
outputFile << " the letters, together with their counts, as explained below";
outputFile << " in the function printResult.";
outputFile << "  The program consists of the following four functions: ";
outputFile << " **Function openFile: Opens the input and output files. You must pass the";
outputFile << " file streams as parameters (by reference, of course). If the file does not";
outputFile << " exist, the program should print an appropriate message and exit. The";
outputFile << " program must ask the user for the names of the input and output files.";
outputFile << "  **Function count: counts every occurrence of capital letters A-Z and";
outputFile << " small letters a-z in the text file opened in the function openFile. This";
outputFile << " information must go into an array of structures. The array must be passed";
outputFile << " as a parameter, and the file identifier must also be passed as a parameter.";
outputFile << "  **Function printResult: Prints the number of capital letters and small";
outputFile << " letters, as well as the percentage of capital letters for every letter A-Z and";
outputFile << " the percentage of small letters for every letter a-z. The percentages";
outputFile << " should look like this: ‘‘25%’’. This information must come from an array";
outputFile << " of structures, and this array must be passed as a parameter.";
outputFile << "  **Function Info: Creates an output file named 'yourName_P4.txt'";
outputFile << " that contains all your required programmer info, along with";
outputFile << " TA name,..) a description of the program ( what it does, and how),";
outputFile << " and how you approached solving it. You must include your algorithm that";
outputFile << " you wrote, including the steps and any refinements made.";
outputFile << " For Project 5, create an output file named 'yourName_P5.txt.'";
outputFile << "     ";
cout << endl;
}
The ‘this’ pointer is passed as a hidden argument to all nonstatic member function calls and is
available as a local variable within the body of all nonstatic functions. ‘this’ pointer is a constant
pointer that holds the memory address of the current object. ‘this’ pointer is not available in
static member functions as static member functions can be called without any object (with class
name).

More Related Content

Similar to So basically I worked really hard on this code in my CS150 class and.pdf

C-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdfC-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdf
herminaherman
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsBG Java EE Course
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
Data structures and algorithms lab1
Data structures and algorithms lab1Data structures and algorithms lab1
Data structures and algorithms lab1Bianca Teşilă
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
GordonpACKellyb
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象勇浩 赖
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functionsmussawir20
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
Javascript part1
Javascript part1Javascript part1
Javascript part1Raghu nath
 
C
CC
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdf
ezonesolutions
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
JAYA
 
Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011
Scalac
 
Input output functions
Input output functionsInput output functions
Input output functionshyderali123
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdf
anandatalapatra
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
herminaherman
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
yamew16788
 
Useful c programs
Useful c programsUseful c programs
Useful c programs
MD SHAH FAHAD
 

Similar to So basically I worked really hard on this code in my CS150 class and.pdf (20)

C-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdfC-Program Custom Library, Header File, and Implementation FilesI .pdf
C-Program Custom Library, Header File, and Implementation FilesI .pdf
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
Data structures and algorithms lab1
Data structures and algorithms lab1Data structures and algorithms lab1
Data structures and algorithms lab1
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
SQL -PHP Tutorial
SQL -PHP TutorialSQL -PHP Tutorial
SQL -PHP Tutorial
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
 
C
CC
C
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdf
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011
 
Input output functions
Input output functionsInput output functions
Input output functions
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdf
 
JavaScript
JavaScriptJavaScript
JavaScript
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 
Useful c programs
Useful c programsUseful c programs
Useful c programs
 

More from eyewaregallery

in C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfin C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
eyewaregallery
 
In addition to the fossil record, what other kinds of evidence reinfo.pdf
In addition to the fossil record, what other kinds of evidence reinfo.pdfIn addition to the fossil record, what other kinds of evidence reinfo.pdf
In addition to the fossil record, what other kinds of evidence reinfo.pdf
eyewaregallery
 
How much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdf
How much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdfHow much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdf
How much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdf
eyewaregallery
 
I am writing a program that places bolcks on a grid the the sape of .pdf
I am writing a program that places bolcks on a grid the the sape of .pdfI am writing a program that places bolcks on a grid the the sape of .pdf
I am writing a program that places bolcks on a grid the the sape of .pdf
eyewaregallery
 
How do teams bring value to an organizationHow are high performin.pdf
How do teams bring value to an organizationHow are high performin.pdfHow do teams bring value to an organizationHow are high performin.pdf
How do teams bring value to an organizationHow are high performin.pdf
eyewaregallery
 
how can we use empricism to figure out if a fact is trueSolutio.pdf
how can we use empricism to figure out if a fact is trueSolutio.pdfhow can we use empricism to figure out if a fact is trueSolutio.pdf
how can we use empricism to figure out if a fact is trueSolutio.pdf
eyewaregallery
 
Gene RegulationFunction of transcription factor domains, i.e. DNA.pdf
Gene RegulationFunction of transcription factor domains, i.e. DNA.pdfGene RegulationFunction of transcription factor domains, i.e. DNA.pdf
Gene RegulationFunction of transcription factor domains, i.e. DNA.pdf
eyewaregallery
 
For each step of DNA replication, predict the outcome ifconcentra.pdf
For each step of DNA replication, predict the outcome ifconcentra.pdfFor each step of DNA replication, predict the outcome ifconcentra.pdf
For each step of DNA replication, predict the outcome ifconcentra.pdf
eyewaregallery
 
Explain THREE unique characteristics of fungi.SolutionThree un.pdf
Explain THREE unique characteristics of fungi.SolutionThree un.pdfExplain THREE unique characteristics of fungi.SolutionThree un.pdf
Explain THREE unique characteristics of fungi.SolutionThree un.pdf
eyewaregallery
 
Explain the basic relationship between humans and microorganisms.pdf
Explain the basic relationship between humans and microorganisms.pdfExplain the basic relationship between humans and microorganisms.pdf
Explain the basic relationship between humans and microorganisms.pdf
eyewaregallery
 
discuss the rationale for the global harmonization of financial repo.pdf
discuss the rationale for the global harmonization of financial repo.pdfdiscuss the rationale for the global harmonization of financial repo.pdf
discuss the rationale for the global harmonization of financial repo.pdf
eyewaregallery
 
Describe the need to multitask in BBC (behavior-based control) syste.pdf
Describe the need to multitask in BBC (behavior-based control) syste.pdfDescribe the need to multitask in BBC (behavior-based control) syste.pdf
Describe the need to multitask in BBC (behavior-based control) syste.pdf
eyewaregallery
 
A spinner with 7 equally sized slices is shown below. The dial is spu.pdf
A spinner with 7 equally sized slices is shown below. The dial is spu.pdfA spinner with 7 equally sized slices is shown below. The dial is spu.pdf
A spinner with 7 equally sized slices is shown below. The dial is spu.pdf
eyewaregallery
 
ble below to calculate the Gross Domestic Product uning the ral Gro.pdf
ble below to calculate the Gross Domestic Product uning the ral Gro.pdfble below to calculate the Gross Domestic Product uning the ral Gro.pdf
ble below to calculate the Gross Domestic Product uning the ral Gro.pdf
eyewaregallery
 
1.The limbic systemA. matures before the prefrontal cortexB. is.pdf
1.The limbic systemA. matures before the prefrontal cortexB. is.pdf1.The limbic systemA. matures before the prefrontal cortexB. is.pdf
1.The limbic systemA. matures before the prefrontal cortexB. is.pdf
eyewaregallery
 
Why is leadership a critical factor in implementing change and qua.pdf
Why is leadership a critical factor in implementing change and qua.pdfWhy is leadership a critical factor in implementing change and qua.pdf
Why is leadership a critical factor in implementing change and qua.pdf
eyewaregallery
 
Why are there bubbles in beer and champagneSolution Bubbles of .pdf
Why are there bubbles in beer and champagneSolution  Bubbles of .pdfWhy are there bubbles in beer and champagneSolution  Bubbles of .pdf
Why are there bubbles in beer and champagneSolution Bubbles of .pdf
eyewaregallery
 
Which of the following is true of a traditional master budget a. It.pdf
Which of the following is true of a traditional master budget a. It.pdfWhich of the following is true of a traditional master budget a. It.pdf
Which of the following is true of a traditional master budget a. It.pdf
eyewaregallery
 
Which ethnic groups were a part of the former YugoslaviaCroats, S.pdf
Which ethnic groups were a part of the former YugoslaviaCroats, S.pdfWhich ethnic groups were a part of the former YugoslaviaCroats, S.pdf
Which ethnic groups were a part of the former YugoslaviaCroats, S.pdf
eyewaregallery
 
What would the components of the development be in an early learning.pdf
What would the components of the development be in an early learning.pdfWhat would the components of the development be in an early learning.pdf
What would the components of the development be in an early learning.pdf
eyewaregallery
 

More from eyewaregallery (20)

in C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfin C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
 
In addition to the fossil record, what other kinds of evidence reinfo.pdf
In addition to the fossil record, what other kinds of evidence reinfo.pdfIn addition to the fossil record, what other kinds of evidence reinfo.pdf
In addition to the fossil record, what other kinds of evidence reinfo.pdf
 
How much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdf
How much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdfHow much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdf
How much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdf
 
I am writing a program that places bolcks on a grid the the sape of .pdf
I am writing a program that places bolcks on a grid the the sape of .pdfI am writing a program that places bolcks on a grid the the sape of .pdf
I am writing a program that places bolcks on a grid the the sape of .pdf
 
How do teams bring value to an organizationHow are high performin.pdf
How do teams bring value to an organizationHow are high performin.pdfHow do teams bring value to an organizationHow are high performin.pdf
How do teams bring value to an organizationHow are high performin.pdf
 
how can we use empricism to figure out if a fact is trueSolutio.pdf
how can we use empricism to figure out if a fact is trueSolutio.pdfhow can we use empricism to figure out if a fact is trueSolutio.pdf
how can we use empricism to figure out if a fact is trueSolutio.pdf
 
Gene RegulationFunction of transcription factor domains, i.e. DNA.pdf
Gene RegulationFunction of transcription factor domains, i.e. DNA.pdfGene RegulationFunction of transcription factor domains, i.e. DNA.pdf
Gene RegulationFunction of transcription factor domains, i.e. DNA.pdf
 
For each step of DNA replication, predict the outcome ifconcentra.pdf
For each step of DNA replication, predict the outcome ifconcentra.pdfFor each step of DNA replication, predict the outcome ifconcentra.pdf
For each step of DNA replication, predict the outcome ifconcentra.pdf
 
Explain THREE unique characteristics of fungi.SolutionThree un.pdf
Explain THREE unique characteristics of fungi.SolutionThree un.pdfExplain THREE unique characteristics of fungi.SolutionThree un.pdf
Explain THREE unique characteristics of fungi.SolutionThree un.pdf
 
Explain the basic relationship between humans and microorganisms.pdf
Explain the basic relationship between humans and microorganisms.pdfExplain the basic relationship between humans and microorganisms.pdf
Explain the basic relationship between humans and microorganisms.pdf
 
discuss the rationale for the global harmonization of financial repo.pdf
discuss the rationale for the global harmonization of financial repo.pdfdiscuss the rationale for the global harmonization of financial repo.pdf
discuss the rationale for the global harmonization of financial repo.pdf
 
Describe the need to multitask in BBC (behavior-based control) syste.pdf
Describe the need to multitask in BBC (behavior-based control) syste.pdfDescribe the need to multitask in BBC (behavior-based control) syste.pdf
Describe the need to multitask in BBC (behavior-based control) syste.pdf
 
A spinner with 7 equally sized slices is shown below. The dial is spu.pdf
A spinner with 7 equally sized slices is shown below. The dial is spu.pdfA spinner with 7 equally sized slices is shown below. The dial is spu.pdf
A spinner with 7 equally sized slices is shown below. The dial is spu.pdf
 
ble below to calculate the Gross Domestic Product uning the ral Gro.pdf
ble below to calculate the Gross Domestic Product uning the ral Gro.pdfble below to calculate the Gross Domestic Product uning the ral Gro.pdf
ble below to calculate the Gross Domestic Product uning the ral Gro.pdf
 
1.The limbic systemA. matures before the prefrontal cortexB. is.pdf
1.The limbic systemA. matures before the prefrontal cortexB. is.pdf1.The limbic systemA. matures before the prefrontal cortexB. is.pdf
1.The limbic systemA. matures before the prefrontal cortexB. is.pdf
 
Why is leadership a critical factor in implementing change and qua.pdf
Why is leadership a critical factor in implementing change and qua.pdfWhy is leadership a critical factor in implementing change and qua.pdf
Why is leadership a critical factor in implementing change and qua.pdf
 
Why are there bubbles in beer and champagneSolution Bubbles of .pdf
Why are there bubbles in beer and champagneSolution  Bubbles of .pdfWhy are there bubbles in beer and champagneSolution  Bubbles of .pdf
Why are there bubbles in beer and champagneSolution Bubbles of .pdf
 
Which of the following is true of a traditional master budget a. It.pdf
Which of the following is true of a traditional master budget a. It.pdfWhich of the following is true of a traditional master budget a. It.pdf
Which of the following is true of a traditional master budget a. It.pdf
 
Which ethnic groups were a part of the former YugoslaviaCroats, S.pdf
Which ethnic groups were a part of the former YugoslaviaCroats, S.pdfWhich ethnic groups were a part of the former YugoslaviaCroats, S.pdf
Which ethnic groups were a part of the former YugoslaviaCroats, S.pdf
 
What would the components of the development be in an early learning.pdf
What would the components of the development be in an early learning.pdfWhat would the components of the development be in an early learning.pdf
What would the components of the development be in an early learning.pdf
 

Recently uploaded

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 

Recently uploaded (20)

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 

So basically I worked really hard on this code in my CS150 class and.pdf

  • 1. So basically I worked really hard on this code in my CS150 class and now I need to change it to a class, and I thought OK that's simple enough, but I cant seem to figure it out at all! I know I can just make all of the variables inside the class public, but that's not what my professor wants. I am supposed to implement the private variables. I tried making the "letter" and "letterCount" variables private and I created some void functions under the public part, I think I might have been on the right track with that but I wasn't sure how to modify the rest of my code in order to get it to run. Here's the original code, still in the struct format. Any help would be GREATLY appreciated. P.S. my professor said "make the member variables private, and impliment functions to manage those private variables, such as getter and setter functions." so that might help you understand whats expected. Thanks! I NEED TO GET RID OF THE STRUCT ALLTOGETHER! my class should be set up like this: class { private: letter letterCount public: //functions to controll the private variables such as... void getletter void getlettercount } I just dont know how to impliment that in my code, and what to write in those functions in the class. Thanks for your help! [code] #include #include #include #include using namespace std; //Struct definition struct letterType
  • 2. { char letter; int letterCount; }; //Function to open I/O files void openFile(ifstream& inFile, ofstream& outFile); //Function to fill the array of structs and keep track of the amount of uppercase/lowercase letters void count(ifstream& inFile, letterType letterList[], int& totalBig, int& totalSmall); //Function to print the letters, the occurences, and the percentages void printResult(ofstream& outFile, letterType letterList[], int totalBig, int totalSmall); //Function to create an output file that contains programmer info void Info (ofstream& outputFile); int main() { ofstream fout; ifstream input; //object to read the text ofstream output; //object to write the results int totalCapital = 0; //variable to store the total number of uppercase int totalLower = 0; //variable to store the total number of lowercase letterType letterObj[52]; //array of structs of type letterType to hold the information //Input and process data Info (fout); openFile(input, output); count(input, letterObj, totalCapital, totalLower); printResult(output, letterObj, totalCapital, totalLower); //Close files input.close(); output.close(); return 0;
  • 3. } void openFile(ifstream& inFile, ofstream& outFile) { string inFileName; string outFileName; cout << "Enter the name of the input file: "; cin >> inFileName; inFile.open(inFileName.c_str()); cout << endl; cout << "Enter the name of the output file: "; cin >> outFileName; outFile.open(outFileName.c_str()); cout << endl; } void count(ifstream& inFile, letterType letterList[], int& totalBig, int& totalSmall) { char ch; //Loop to initialize the array of structs; set letterCount to zero for(int index = 0; index < 26; index++) { //This segment sets the uppercase letters letterList[index].letter = static_cast(65 + index); letterList[index].letterCount = 0; //This segment sets the lowercase letters letterList[index + 26].letter = static_cast(97 + index); letterList[index + 26].letterCount = 0; } //read first character inFile >> ch;
  • 4. //Keep reading until end of file is reached while(!inFile.eof()) { //If uppercase letter or lowercase letter is found, update data if('A' <= ch && ch <= 'Z') { letterList[static_cast(ch) - 65].letterCount++; totalBig++; } else if('a' <= ch && ch <= 'z') { letterList[static_cast(ch) - 71].letterCount++; totalSmall++; } //read the next character inFile >> ch; } //end while } //end function void printResult(ofstream& outFile, letterType letterList[], int totalBig, int totalSmall) { outFile << fixed << showpoint << setprecision(2); outFile << "Letter Occurences Percentage" << endl; for(int index = 0; index < 52; index++) { if(0 <= index && index <= 25) { outFile << setw(4) << letterList[index].letter << setw(12) << letterList[index].letterCount << " "; outFile << setw(15)<< 100 * (letterList[index].letterCount / (static_cast(totalBig)+static_cast(totalSmall))) << "%" << endl;
  • 5. } else { outFile << setw(4) << letterList[index].letter << setw(12) << letterList[index].letterCount << " "; outFile << setw(15) << 100 * (letterList[index].letterCount / (static_cast(totalBig)+static_cast(totalSmall))) << "%" << endl; } } //end for } //end void Info (ofstream& outputFile) { string outputFileName; cout << "Enter your name: "; cin >> outputFileName; outputFileName = outputFileName+"_p4.txt"; outputFile.open(outputFileName.c_str()); outputFile << "Programmer name: Bryce Messer LAB CRN: 10342"; outputFile << " This program is a collection of variable declarations"; outputFile << " and function calls. This program reads a text and outputs"; outputFile << " the letters, together with their counts, as explained below"; outputFile << " in the function printResult."; outputFile << " The program consists of the following four functions: "; outputFile << " **Function openFile: Opens the input and output files. You must pass the"; outputFile << " file streams as parameters (by reference, of course). If the file does not"; outputFile << " exist, the program should print an appropriate message and exit. The"; outputFile << " program must ask the user for the names of the input and output files."; outputFile << " **Function count: counts every occurrence of capital letters A-Z and"; outputFile << " small letters a-z in the text file opened in the function openFile. This"; outputFile << " information must go into an array of structures. The array must be passed";
  • 6. outputFile << " as a parameter, and the file identifier must also be passed as a parameter."; outputFile << " **Function printResult: Prints the number of capital letters and small"; outputFile << " letters, as well as the percentage of capital letters for every letter A-Z and"; outputFile << " the percentage of small letters for every letter a-z. The percentages"; outputFile << " should look like this: ‘‘25%’’. This information must come from an array"; outputFile << " of structures, and this array must be passed as a parameter."; outputFile << " **Function Info: Creates an output file named 'yourName_P4.txt'"; outputFile << " that contains all your required programmer info, along with"; outputFile << " TA name,..) a description of the program ( what it does, and how),"; outputFile << " and how you approached solving it. You must include your algorithm that"; outputFile << " you wrote, including the steps and any refinements made."; outputFile << " For Project 5, create an output file named 'yourName_P5.txt.'"; outputFile << " "; cout << endl; } [/code] Solution Here we are using the concept of this pointer of C++. I have defined four functions 1) getletter() 2)setletter() 3)getlettercount() 4)setlettercount() I dont know the name of the input file. So not able to run the code.I gave the random file number of mine and it executed without any trouble Please check and let me know for any quieries you have. #include #include #include #include using namespace std;
  • 7. class letterType { private: char letter; int letterCount; public: //functions to controll the private variables such as... void setletter(char ch); void setlettercount(int lcount); char getletter(); int getlettercount(); }; void letterType::setletter(char ch) { this->letter = ch; } void letterType::setlettercount(int _letterCount) { this->letterCount = _letterCount; } char letterType::getletter() { return this->letter; } int letterType::getlettercount() { return this->letterCount; } //Function to open I/O files void openFile(ifstream& inFile, ofstream& outFile); //Function to fill the array of structs and keep track of the amount of uppercase/lowercase letters void count(ifstream& inFile, letterType letterList[], int& totalBig, int& totalSmall); //Function to print the letters, the occurences, and the percentages void printResult(ofstream& outFile, letterType letterList[], int totalBig, int totalSmall); //Function to create an output file that contains programmer info void Info (ofstream& outputFile);
  • 8. int main() { ofstream fout; ifstream input; //object to read the text ofstream output; //object to write the results int totalCapital = 0; //variable to store the total number of uppercase int totalLower = 0; //variable to store the total number of lowercase letterType letterObj[52]; //array of structs of type letterType to hold the information //Input and process data Info (fout); openFile(input, output); count(input, letterObj, totalCapital, totalLower); printResult(output, letterObj, totalCapital, totalLower); //Close files input.close(); output.close(); return 0; } void openFile(ifstream& inFile, ofstream& outFile) { string inFileName; string outFileName; cout << "Enter the name of the input file: "; cin >> inFileName; inFile.open(inFileName.c_str()); cout << endl; cout << "Enter the name of the output file: "; cin >> outFileName; outFile.open(outFileName.c_str()); cout << endl; } void count(ifstream& inFile, letterType letterList[], int& totalBig, int& totalSmall) { char ch; //Loop to initialize the array of structs; set letterCount to zero for(int index = 0; index < 26; index++)
  • 9. { //This segment sets the uppercase letters letterList[index].setletter(static_cast(65 + index)); letterList[index].setlettercount(0); //This segment sets the lowercase letters letterList[index + 26].setletter(static_cast(97 + index)); letterList[index + 26].setlettercount(0); } //read first character inFile >> ch; //Keep reading until end of file is reached while(!inFile.eof()) { //If uppercase letter or lowercase letter is found, update data if('A' <= ch && ch <= 'Z') { letterList[static_cast(ch) - 65].setlettercount(letterList[static_cast(ch) - 65].getlettercount() + 1); totalBig++; } else if('a' <= ch && ch <= 'z') { letterList[static_cast(ch) - 71].setlettercount(letterList[static_cast(ch) - 71].getlettercount() + 1); totalSmall++; } //read the next character inFile >> ch; } //end while } //end function void printResult(ofstream& outFile, letterType letterList[], int totalBig, int totalSmall) { outFile << fixed << showpoint << setprecision(2); outFile << "Letter Occurences Percentage" << endl; for(int index = 0; index < 52; index++) { if(0 <= index && index <= 25) {
  • 10. outFile << setw(4) << letterList[index].getletter() << setw(12) << letterList[index].getlettercount() << " "; outFile << setw(15)<< 100 * (letterList[index].getlettercount() / (static_cast(totalBig)+static_cast(totalSmall))) << "%" << endl; } else { outFile << setw(4) << letterList[index].getlettercount() << setw(12) << letterList[index].getlettercount() << " "; outFile << setw(15) << 100 * (letterList[index].getlettercount() / (static_cast(totalBig)+static_cast(totalSmall))) << "%" << endl; } } //end for } //end void Info (ofstream& outputFile) { string outputFileName; cout << "Enter your name: "; cin >> outputFileName; outputFileName = outputFileName+"_p4.txt"; outputFile.open(outputFileName.c_str()); outputFile << "Programmer name: Bryce Messer LAB CRN: 10342"; outputFile << " This program is a collection of variable declarations"; outputFile << " and function calls. This program reads a text and outputs"; outputFile << " the letters, together with their counts, as explained below"; outputFile << " in the function printResult."; outputFile << " The program consists of the following four functions: "; outputFile << " **Function openFile: Opens the input and output files. You must pass the"; outputFile << " file streams as parameters (by reference, of course). If the file does not"; outputFile << " exist, the program should print an appropriate message and exit. The"; outputFile << " program must ask the user for the names of the input and output files."; outputFile << " **Function count: counts every occurrence of capital letters A-Z and"; outputFile << " small letters a-z in the text file opened in the function openFile. This"; outputFile << " information must go into an array of structures. The array must be passed"; outputFile << " as a parameter, and the file identifier must also be passed as a parameter.";
  • 11. outputFile << " **Function printResult: Prints the number of capital letters and small"; outputFile << " letters, as well as the percentage of capital letters for every letter A-Z and"; outputFile << " the percentage of small letters for every letter a-z. The percentages"; outputFile << " should look like this: ‘‘25%’’. This information must come from an array"; outputFile << " of structures, and this array must be passed as a parameter."; outputFile << " **Function Info: Creates an output file named 'yourName_P4.txt'"; outputFile << " that contains all your required programmer info, along with"; outputFile << " TA name,..) a description of the program ( what it does, and how),"; outputFile << " and how you approached solving it. You must include your algorithm that"; outputFile << " you wrote, including the steps and any refinements made."; outputFile << " For Project 5, create an output file named 'yourName_P5.txt.'"; outputFile << " "; cout << endl; } The ‘this’ pointer is passed as a hidden argument to all nonstatic member function calls and is available as a local variable within the body of all nonstatic functions. ‘this’ pointer is a constant pointer that holds the memory address of the current object. ‘this’ pointer is not available in static member functions as static member functions can be called without any object (with class name).