In C++, create a program that takes in data from the user input and create a "painting" of that text. an example: ********* *   the   * *   sky   * *     is    * * falling * ********* it should also be able to be like these as well: ********* *the      * *sky      * *is         * *falling  * ********* or ********* *      the* *      sky* *         is* *  falling* ********* Depending on whether or not the user asked for left, centered, or right justification — respectively — of the phrase's words within the frame. Note how the frame exactly fits the phrase based on the longest word within. Neat, eh? Also be able to use different symbols for the border, make a menu for the user to use @, #, *, +, x, X, o, or O. But let them tell you anything that will print just fine. (Hint: has a function called isprint that tells if a character is printable.) so the one above could become: ####### #   the   # #   sky   # #     is    # # falling # ####### Give them the option of reading phrases from the keyboard or a file they specify (assume each line of the input stream contains a single phrase). The user should also be able to choose if the framed phrase is printed on the screen or into a file they specify. The code should be able to perform all of the above requirements!

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter9: Records (struct)
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

In C++, create a program that takes in data from the user input and create a "painting" of that text.

an example:

*********
*   the   *
*   sky   *
*     is    *
* falling *
*********

it should also be able to be like these as well:

*********
*the      *
*sky      *
*is         *
*falling  *
*********

or

*********
*      the*
*      sky*
*         is*
*  falling*
*********

Depending on whether or not the user asked for left, centered, or right justification — respectively — of the phrase's words within the frame. Note how the frame exactly fits the phrase based on the longest word within. Neat, eh?

Also be able to use different symbols for the border, make a menu for the user to use @, #, *, +, x, X, o, or O. But let them tell you anything that will print just fine. (Hint: <cctype> has a function called isprint that tells if a character is printable.)

so the one above could become:

#######
#   the   #
#   sky   #
#     is    #
# falling #
#######

Give them the option of reading phrases from the keyboard or a file they specify (assume each line of the input stream contains a single phrase).

The user should also be able to choose if the framed phrase is printed on the screen or into a file they specify.

The code should be able to perform all of the above requirements!

 

Expert Solution
Step 1
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
// #include
using namespace std;
vector<string> sttok(string str)
{
int i = 0;
vector<string> res;
string temp = "";
for (i = 0; i < str.size(); i++)
{
if (str[i] == ' ')
{
res.push_back(temp);
temp = "";
}
else
{
temp.push_back(str[i]);
}
}
res.push_back(temp);
return res;
}
string strip(string str)
{
string res;
int i = 0;
while (i < str.size())
{
if (str[i] == '\n')
{
i++;
continue;
}
res.push_back(str[i]);
i++;
}
return res;
}
int main(void)
{
char framechar;
vector<string> phrasetok;
cout << "press 1 if you want to enter phrase through keyboard and press 0 if "
"you want program to read phrase from file"
<< endl;
int in;
cin >> in;
std::string phrase;
cout << "enter the phrase you want to print"<<endl;
cin.ignore();
cin.clear();
if (in == 1) // reading from keyboard
{
getline(std::cin, phrase);
}
else // reading from a file
{
}
phrasetok = sttok(phrase);
cout << "Enter the printable frame character: ";
cin.clear();
cin >> framechar;
int just;
cout << "enter 1 for left justification, 2 for center justification and 3 "
"for right justification"
<< endl;
cin >> just;
int i = 0;
cout<<" ";
for (i = 1; i <=10; i++)
{
cout << framechar;
}
cout << endl;
i = 0;
while (i < phrasetok.size())
{
string str = phrasetok[i];
cout << framechar;
if (just == 1)
{
int sp = 10 - str.size()+1;
cout << str;
for (int j = 1; j < sp; j++)
{
cout << " ";
}
}
else if (just == 2)
{
int sp = 10 - str.size()+1;
sp = sp / 2;
for (int j = 1; j <= sp; j++)
{
cout << " ";
}
cout << str;
if(str.size()%2==0)
sp++;
for (int j = 1; j < sp; j++)
{
cout << " ";
}
}
else
{
int sp = 10 - str.size() +1;
for (int j = 1; j < sp; j++)
{
cout << " ";
}
cout << str;
}
cout<<framechar<<endl;
i++;
}
cout<<" ";
for (i = 1; i <= 10; i++)
{
cout << framechar;
}
cout << endl;
return 0;
}
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning