Type solution and submit as an attachment. Create the class Character Reader tha
ID: 3777882 • Letter: T
Question
Type solution and submit as an attachment. Create the class Character Reader that has the following properties protected string field named dots. Public default constructor that assigns the energy string to data. Public get accessor methods for dat. Public virtual void method named Add() that takes one char parameter. It add the parameter to the end of data. Create the class UniqueCharacter Reader that has the following properties: publicly inherits CharacterReader. Public default constructor that assigns the empty string to data. Public overhidden Add() that only the parameter to the end of data if the character is not already in data. Create the class SortedCharacterReader that has the following properties: publicly inherits CharacterReader. Public default constructor that assigns the empty string to data. Public overhidden that add the parameter to data and sort data in ascending order. In the main, create a pointer array of CharacterReader that contains an element for each class (it has three (3) elements in all). Next, use a loop to randomly add hundred (100) characters each of the elements of the array. Add the same characters to each element and only add uppercase letters. Last, display data for each element.Explanation / Answer
using namespace std;
int main()
{
string r_content,w_content;
fstream outfile;
outfile.open ("data.txt",ios_base::out);
if (!outfile)
{
cout<<"Error writing to file!";
return 0;
}
else
{
cout<<"Please enter a string to be written to the file: ";
cin>>w_content;
cout<<"Writing to file... ";
//send data to file before closing
outfile<<w_content;
outfile.close();
}
fstream infile;
infile.open("data.txt",ios_base::in);
if (!infile)
{
cout<<"Error reading file!";
return 0;
}
else
{
cout<<" Reading from file... ";
//read data in before closing
getline(infile,r_content);
cout<<"The file contents are: ";
cout<<r_content;
infile.close();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.