Question

In: Computer Science

c++ The purpose of this project is to test your ability to use files, class design,...

c++

The purpose of this project is to test your ability to use files, class design, operator overloading, and Strings or strings effectively in program design

Create a program which will read a phrase from the user and create a framed version of it for printing. For example, the phrase "hello world"would result in:

   *********
   * hello *
   * world *
   *********

Whereas the phrase "the sky is falling"might be:

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

Or:

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

Or even:

   ***********
   *     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?

The phrase "O | -+- | /-\"when centered would become:

    *******
    *  O  *
    *  |  *
    * -+- *
    *  |  *
    * /-\ *
    *******

(Okay, so it's a sad excuse for a stick figure, but hey! I've never claimed to be a great good decent artist, now have I? *phbbt*)

Also allow the user to specify what character you are to make the frame from. Typical choices would be @, #, *, +, 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.)

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.

In case it isn't clear, you should create a 'frame the phrase' class. It should have overloaded operators for at leastinput and output. (Although concatenation might prove interesting, too...)

add a choice of frame types: single line, double line, or shaded. For instance:

    +---------+     +============+      +--------+    +=======+
    |         |     ||          ||      |        |*   ||     ||#
    |         |     ||          ||      |        |*   ||     ||#
    +---------+     +============+      +--------+*   +=======+#
                                         **********    #########

Solutions

Expert Solution

/******************************************************************************

   Program to read a phrase and display in a framed version of it.

*******************************************************************************/


#include <string>

#include <vector>

#include <string.h>

#include <stdio.h>

#include <iostream>

using namespace std;

#define MAX_NAME_LENGTH    200

int maxlength;

std::vector<std::string> split(std::string str,std::string sep){
  
   char* cstr=const_cast<char*>(str.c_str());
  
   char* current;
  
   std::vector<std::string> arr;
  
   current=strtok(cstr,sep.c_str());
  
   while(current!=NULL){
      
       arr.push_back(current);
      
       current=strtok(NULL,sep.c_str());
  
   }
  
   return arr;

}

int main()
{
  
   char name[MAX_NAME_LENGTH];
  
   std::vector<std::string> arr;
  
   cout<<"Enter the phrase:"<<endl;
  
   cin.getline(name,MAX_NAME_LENGTH);
  
   
   arr=split(name," ");
  
   for(int j=0;j<arr.size();j++){
      
       if(arr[j].length() > maxlength)
         
       maxlength= arr[j].length();
  
   }
   
   cout<<"############# Output ###############"<<endl;
   for(int k=0;k<=maxlength+2;k++)
      
       printf("%s","*");
  
   for(size_t i=0;i<arr.size();i++)
      
       printf("\n*%s*",arr[i].c_str());
  
   cout<<endl;  
  
   for(int k=0;k<=maxlength+2;k++)
      
       printf("%s","*");
  
   return 0;

}


Related Solutions

Create a new project called: ToDoList Purpose: To demonstrate your ability to use a linear structure  to...
Create a new project called: ToDoList Purpose: To demonstrate your ability to use a linear structure  to insert, contain, change, and remove data elements (Strings). Also to show that you can perform the detailed work in functions with the main function containing only the major program logic. Specifications: Create a new project called ToDoList and save it in the appropriate Lab folder. Step 1: To begin the main program, use an ArrayList or LinkedList, to declare a structure to hold String...
Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability...
Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability to identify emerging ethical issues in business, interpret the multitude of perspectives inherent in your case study, and model appropriate behaviour by recommending specific solutions. How to Proceed Select a case. It can be one of the textbook cases that we have not discussed during the course. It can also come from the outside world, perhaps a case you have been following in the...
This exercise will test your ability to use the basic instance methods of String. The exercise...
This exercise will test your ability to use the basic instance methods of String. The exercise is to create a program that compares two Strings ignoring the case and returns the offset between the first two distinct characters in the two Strings from left to right. All the input strings have five characters. For this exercise, compareToIgnoreCase() and compareTo() methods are not allowed. Example 1, "London" and "Lately" will return the offset between 'o' and 'a', which is 14 Example...
Complete the following task in C++. Separate your class into header and cpp files. You can...
Complete the following task in C++. Separate your class into header and cpp files. You can only useiostream, string and sstream. Create a main.cpp file to test your code thoroughly. Given : commodity.h and commodity.cpp here -> https://www.chegg.com/homework-help/questions-and-answers/31-commodity-request-presented-two-diagrams-depicting-commodity-request-classes-form-basic-q39578118?trackid=uF_YZqoK Create : locomotive.h, locomotive.cpp, main.cpp Locomotive Class Hierarchy Presented here will be a class diagram depicting the nature of the class hierarchy formed between a parent locomotive class and its children, the two kinds of specic trains operated. The relationship is a...
Complete the following task in C++. Separate your class into header and cpp files. You can...
Complete the following task in C++. Separate your class into header and cpp files. You can only use iostream, string and sstream. Create a main.cpp file to test your code thoroughly. Given : commodity.h and commodity.cpp here -> https://www.chegg.com/homework-help/questions-and-answers/31-commodity-request-presented-two-diagrams-depicting-commodity-request-classes-form-basic-q39578118?trackid=uF_YZqoK Given : locomotive.h, locomotive.cpp, main.cpp -> https://www.chegg.com/homework-help/questions-and-answers/complete-following-task-c--separate-class-header-cpp-files-useiostream-string-sstream-crea-q39733428 Create : DieselElectric.cpp DieselElectric.h DieselElectric dieselElectric -fuelSupply:int --------------------------- +getSupply():int +setSupply(s:int):void +dieselElectric(f:int) +~dieselElectric() +generateID():string +calculateRange():double The class variables are as follows: fuelSuppply: The fuel supply of the train in terms of a number of kilolitres...
Please use jGRASP program to solve the following project. This program assesses your ability to use...
Please use jGRASP program to solve the following project. This program assesses your ability to use functions, arrays, for loops, and if statements where needed. You are writing a program to track bird sightings in Prince William County for a weekend event where bird watchers watch birds and record each unique species that they see. Over a weekend, Saturday and Sunday, the bird watchers (aka birders) are going to record how many bird species they sight each day. You begin...
Term Project C++ Pet Class Problem Specification: Design a class named Pet, which should have the...
Term Project C++ Pet Class Problem Specification: Design a class named Pet, which should have the following fields: • name: The name field holds the name of a pet. • type: The type field holds the type of animal that a pet is. Example values are “Dog”, “Cat”, and “Bird”. • age: The age field holds the pet’s age. The Pet class should also have the following methods: • setName: The setName method stores a value in the name field....
Use the following class for the following problem. The only purpose of the class is to...
Use the following class for the following problem. The only purpose of the class is to display a message both when the constructor is invoked and when the destructor is executed. class Trace { public: Trace(string n); ~Trace(); private: string name; }; Trace::Trace(string n) : name(n) { cout << "Entering " << name << "\n"; } Trace::~Trace() { cout << "Exiting " << name << "\n"; } Requirement: Extend the class Trace with a copy constructor and an assignment operator,...
Use C++ write a "Design and implement a class of infix calculators" ,simply write a function...
Use C++ write a "Design and implement a class of infix calculators" ,simply write a function named "evaluateInfix()" that evaluates infix expressions. It should have one string parameter and should return an int result. It should call a separate function named "infixToPostfix()" to convert the infix expression into a postfix expression, and then it should do the work of evaluating the resulting postfix expression. Then write a main() function to thoroughly test the function. Use the pseudocode algorithm that evaluates...
In C++ Create a class called Rational (separate the files as shown in the chapter) for...
In C++ Create a class called Rational (separate the files as shown in the chapter) for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private data of the class-the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form. For example,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT