Question

In: Computer Science

C++: FramedI is an interface and appears as: class FramedI { public: virtual string getText()=0; virtual...

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;
}

Solutions

Expert Solution

//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


Related Solutions

class Function {     public:     virtual double compute(double value) = 0;     virtual double differenciate(double value) = 0;...
class Function {     public:     virtual double compute(double value) = 0;     virtual double differenciate(double value) = 0;     virtual double integrate(double value) = 0; }; class Sine : public Function {     public:     double compute(double value); // compute sin(x) for a given x     double differenciate(double value); // compute derivative sin'(x) for a given x     double integrate(double value); // integrate sin(x) for a given x }; class Tangent : public Function {     public:     double compute(double value); // compute tan(x) for a given x     double...
Consider the following interface: public interface Car{ public String getMake(); public void setMake(); public void honk();...
Consider the following interface: public interface Car{ public String getMake(); public void setMake(); public void honk(); public void crash(); public void drive(); } public interface Boat{ public String getMake (); public void setMake (); public void blast_horn(); public void sink(); public void move(); } 1. Create a concrete FamilyCar class from the Car interface.
public class StringTools {    public static int count(String a, char c) {          ...
public class StringTools {    public static int count(String a, char c) {           }
Finish the following java question: Consider the following interface: interface Duty { public String getDuty(); }...
Finish the following java question: Consider the following interface: interface Duty { public String getDuty(); } Write a class called Student which implements Duty. Class Student adds 1 data field, id, and 2 methods, getId and setId, along with a 1-argument constructor. The duty of a Student is to study 40 hours a week. Write a class called Professor which implements Duty. Class Professor adds 1 data field, name, and 2 methods, getName and setName, along with a 1-argument constructor....
public class Book{     public String title;     public String author;     public int year;    ...
public class Book{     public String title;     public String author;     public int year;     public String publisher;     public double cost;            public Book(String title,String author,int year,String publisher,double cost){        this.title=title;         this.author=author;         this.year=year;         this.publisher=publisher;         this.cost=cost;     }     public String getTitle(){         return title;     }         public String getAuthor(){         return author;     }     public int getYear(){         return year;     }     public String getPublisher(){         return publisher;...
Given: class Monster {     private:     string name;     int dangerLevel;     public:     Monster(sting, int);     virtual void hunt()
Given: class Monster {     private:     string name;     int dangerLevel;     public:     Monster(sting, int);     virtual void hunt() = 0;     virtual void fight(Monster&);     string getName() const; }; class GiantMonster : public Monster {     protected:         int height;          public:         GiantMonster(string, int, int);         virtual void trample(); }; class Dinosaur : public GiantMonster {     public:     Dinosaur(string, int, int);     void hunt();     void roar(); }; class Kraken : protected GiantMonster {     public:     Kraken(string, int, int);     virtual void hunt();     void sinkShip(); }; Indicate if the code snippets below are...
List.h template class List { // List class ADT              public:    virtual void...
List.h template class List { // List class ADT              public:    virtual void clear() = 0; // Inserts an item into the list at position index    virtual bool insert(const ListItemType& newItem) = 0;    // Append "it" at the end of the list    // The client must ensure that the list's capacity is not exceeded    virtual bool append(const ListItemType& newItem) = 0;    // Deletes an item from the list at a given position...
If a class A implements interface I1 and class C and D are derived from class...
If a class A implements interface I1 and class C and D are derived from class A, a variable of type I1 can be used to hold references of what type of objects? which one is correct 1. A, C, and D 2. A and D
public class Graph { private ST<String, SET<String>> st; public Graph() { st = new ST<String, SET<String>>();...
public class Graph { private ST<String, SET<String>> st; public Graph() { st = new ST<String, SET<String>>(); } public void addEdge(String v, String w) { // Put v in w's SET and w in v's SET. if (!st.contains(v)) st.put(v, new SET<String>()); if (!st.contains(w)) st.put(w, new SET<String>()); st.get(v).add(w); st.get(w).add(v); } public Iterable<String> adjacentTo(String v) { return st.get(v); } public Iterable<String> vertices() { return st.keys(); } // See Exercises 4.5.1-4 for V(), E(), degree(), // hasVertex(), and hasEdge(). public static void main(String[] args)...
// C++ Doubly linked list class clinknode{ friend class DList; public:     clinknode(){next = prev=0;data =0;}...
// C++ Doubly linked list class clinknode{ friend class DList; public:     clinknode(){next = prev=0;data =0;} protected:     clinknode *next;     clinknode *prev;     int data; } class DList{ public: DList(){first = last = 0;} void insertFront(int key); bool found(int key){ return search(key)!=0;} void deleteAll(int key); // other list functions... private: clinknode *search(int); clinknode *first; clinknode *last; } (20 points) Write the code for the deleteAll (int key) member function. It takes a key value and deletes all of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT