In: Computer Science
C++: FramedI is an interface and appears as:
class FramedI { public: virtual string getText()=0; virtual char
getFrameChar() =0; };
You must implement the interface and call the class FramedText. It
must implement the FramedI interface. Any attributes used in the
FramedText class MUST be private.
Create a function called void showFramedText(ostream&, FramedI&);
If the text to display is "Here's my text here" and the framing
character is '*', the function must output
*********************** * Here's my text here *
***********************
The methods getText() would return "Here's my text here" and getFrameChar() would return '*'.
The showFramedText() function needs no more information to do it's work and can be written BEFORE implementing FramedText class.
Text must align perfectly around the text as shown. Make sure a newline is output after the last frame character. There must be a space between the leftmost frame character and the start of the text. Also, there must be a space at the end of the text before the rightmost character. See the use of FramedText in the template for clues on what constructor must be used. You must have only 1 constructor. Assume the text and the frame will never be too big across the screen, that is, the text will always be limited to say 30 characters.
#include<iostream>
#include<string>
using namespace std;
class FramedI
{
public:
virtual string getText()=0;
virtual char getFrameChar() =0;
};
void showFramedText(ostream& os, FramedI& fi)
{
//Write the function implementation here.
}
//Implement the FramedI interface here
//Your FramedText class must only have 1 constructor
int main()
{
FramedText frame1("MOVIE PREMIERE TONIGHT", '*');
FramedI *frame2 = new FramedText("W A R N I N G!", '#');
FramedI *frames[4];
//Properly assign frames[0] and [1] to frame1 and frame2
//Input from the user names of 2 classmates.
//Dynamically create instances who's values will be assigned to
index 2 and 3 in the frames array.
//iterate the frames array and call showFramedText() function for
each element.
//You may assume you know there's 4 elements in the frames
array.
//As an example, if the user entered John Ceeplus for the first
classmate's name, the third iteration should output:
/*
++++++++++++++++
+ John Ceeplus +
++++++++++++++++
*/
//Reminder that the showFramedText() function needs to do the
output.
return 0;
}
//C++ code
#include<iostream>
#include<string>
using namespace std;
class FramedI
{
public:
virtual string getText() = 0;
virtual char getFrameChar() = 0;
};
void showFramedText(ostream& os, FramedI& fi)
{
for (int i = 0; i <= 16; i++)
{
os <<
fi.getFrameChar()<<" ";
}
os << endl;
os <<
fi.getFrameChar()<<" "<<fi.getText()<<"
"<<fi.getFrameChar();
os << endl;
for (int i = 0; i <= 16; i++)
{
os <<
fi.getFrameChar()<<" ";
}
os << endl;
}
//Implement the FramedI interface here
//Your FramedText class must only have 1 constructor
class FramedText :public FramedI{
private:
char symbol;
string text;
public:
FramedText(string t, char ch)
{
symbol = ch;
text = t;
}
string getText()
{
return text;
}
char getFrameChar()
{
return symbol;
}
};
int main()
{
FramedText frame1("MOVIE PREMIERE TONIGHT",
'*');
FramedI* frame2 = new FramedText("W A R N I N G!",
'#');
FramedI* frames[4];
//Properly assign frames[0] and [1] to frame1 and
frame2
frames[0] = &frame1;
frames[1] = frame2;
//Input from the user names of 2 classmates.
//Dynamically create instances who's values will be
assigned to index 2 and 3 in the frames array.
string text;
char ch;
cout << "Enter text:
";
getline(cin, text);
cout << "Enter symbol:
";
cin >> ch;
cin.ignore();
frames[2] = new
FramedText(text,ch);
//==========================================
cout << "Enter text: ";
getline(cin, text);
cout << "Enter symbol:
";
cin >> ch;
frames[3] = new FramedText(text,
ch);
//iterate the frames array and call
showFramedText() function for each element.
//You may assume you know there's 4 elements in the
frames array.
for (int i = 0; i < 4; i++)
{
showFramedText(cout,
*frames[i]);
}
//As an example, if the user entered John Ceeplus
for the first classmate's name, the third iteration should
output:
/*
++++++++++++++++
+ John Ceeplus +
++++++++++++++++
*/
//Reminder that the showFramedText() function needs to
do the output.
return 0;
}
//Output
//If you need any help regarding this solution ........... please leave a comment ........ thanks