Question

In: Computer Science

Problem: Text manipulation as a technology has a myriad of applications, including coding and decoding, textual...

Problem: Text manipulation as a technology has a myriad of applications, including coding and decoding, textual analysis to determine authorship of a document, and automatic translation between languages. Learning to parse and process textual data is a valuable skill to master.


Your assignment: Design, develop, and test an Object-Oriented C++ program to process multi-word phrases and sentences in a variety of ways. In this case, the required processing includes 1) reversing the words in a phrase, 2) sorting the words within the phrase in ascending order, and 3) applying the Rot13 encoding to all the characters in the original phrase.


Discussion: Phrases are composed of words, which are in turn composed of characters. In C++, those characters are represented as bytes, using the ASCII standard to encode each character as a number. Parsing a string involves breaking a string up into its component words, using spaces as the delimiters between words. This project requires first that the user’s input phrase be parsed into its component words, and then each word must be handled as an individual entity. In all the phrase processing except the Rot13 conversion, words must be kept intact.

Consider the following issues when preparing your solution.


- Create a user-defined Phrase class to manage a phrase and the words within it. This class must have one or more constructor(s) for initialization and multiple methods to perform the various operations on the phrase and its words.

- Create a single instance of the class in function main()

- Repeat the following steps until the user opts to quit:

- Prompt the user for a phrase or sentence, and read it into a single string

- Initialize the Phrase object with the user-input string

- Display the following conversions of the user-input string as produced by public methods of the Phrase class. The case of each letter must be preserved from the input string to each of these conversions. Each conversion must produce a separate output string.

- Reversed word order

- Sorted word order

- Rot13 character encoding

- In the Reversed Word and Sorted Word conversions, all words must remain intact and readable with regards to the spelling and capitalization of each word. For this assignment, leading and trailing punctuation should be considered a part of each word.

Coding:

- Each user-defined class must be defined within its own set of .h (.hpp in Xcode) and .cpp files.

- There should be three files.

- The first file is main.cpp.

- The second file is Phrase.cpp The is the file where the definitions are written for the classes.

- The third file is Phrase.h This is the header file where the functions are declared for the classes.

- The program must accept any string, including multiple words with embedded spaces, as input.

- Validate all inputs and do not proceed until valid values are entered.For input strings, the only validation required is that the input string must not be empty.

- Program must reverses the characters in the words

- Program must sort the characters in the words

Please do not use other solutions that has been provided on here before since they use the same code (all copies of one another) and do not work as required. Please ensure that the program meets ALL of the requirements.

Make the program as simple as possible. Use introductory Object-Oriented C++ programming. If all the requirements are met, then this will be upvoted.

Do use the C++ Standard Library headers, not use the C Standard Library headers (For instance, include cmath instead of math.h)

Do not use cstring’s or any of the cstring functions (strlen(), strcpy(), strcmp(), etc.)

Solutions

Expert Solution

: Design, develop, and test an Object-Oriented C++ program to process multi-word phrases and sentences in a variety of ways. In this case, the required processing includes

1) reversing the words in a phrase

Filename: main.cpp

// C++ program to reverse words in phrase
#include <iostream>

#include<phrase.h>

using namespace std;

int main()
{
string str;
int begin,end,i,j=0,len,temp,count=0;

cout<<"ENTER STRING: ";
getline(cin,str);

  //To find the length of string
len=str.length();

  //To reverse whole string
for(i=0;i<(len/2);i++)
{
temp=s[i];
str[i]=str[len-1-i];
s[len-1-i]=temp;
}

  //To reverse each word seperately
for(i=0;i<len;i++)
{
if(str[i]==' ' || str[i]=='\0')
{
for(begin=j,end=i-1 ; begin<(i+j)/2 ; begin++,end--)
{
temp=str[begin];
str[begin]=str[end];
str[end]=temp;
}
j=i+1;
}
}

cout<<"Reversed string:";

cout<<s;

return 0;
}

2.Filename Phrase.cpp

#include<iostream>

#include<phrase.h>

using namespace std;

int main()
{

string str;


//To find the length of string
n=str.length();

char temp;

cout << "Enter the phrase : " << endl;
for(int i = 0; i < n; ++i)
{
getline(cin, str[i]);
}

for(int i = 0; i < 9; ++i)
for( int j = i+1; j < 10; ++j)
{
if(str[i] > str[j])
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}

cout << "In ascending order: " << endl;

for(int i = 0; i < 10; ++i)
{
cout << str[i] << endl;
}
return 0;
}

Filename: phrase.h

//
// ROT13 Caesar Cipher

#include<bits/stdc++.h>
using namespace std;

// Map to lookup the index of alphabets
map <char,int> dict1;

// Map to lookup alphabets corresponding
// to the index after shift
map <int,char> dict2;

// Function to create map to lookup
void create_dict()
{
   for(int i = 1; i < 27; i++)
       dict1[char(64 + i)] = i;
  
   dict2[0] = 'Z';
  
   for(int i = 1; i < 26; i++)
       dict2[i] = char(64 + i);
      
   return;
}

// Function to encrypt the string
// according to the shift provided
string encrypt(string str, int shift)
{
   string cipher = "";
   for(int i = 0; i < str.size(); i++)
   {
       // Checking for namespace
       if(str[i] != ' ')
       {
           // loooks up the map and
           // adds the shift to the index
           int num = (dict1[str[i]] + shift) % 26;
          
           // looks up the second map for the
           // shifted alphabets and adds them
           cipher += dict2[num];
       }
       else
       {
           // adds space
           cipher += " ";
       }
   }
   return cipher;
}

// Function to decrypt the string
// according to the shift provided
string decrypt(string str, int shift)
{
   string decipher = "";
   for(int i = 0; i < str.size(); i++)
   {
       // checks for space
       if(message[i] != ' ')
       {
           // looks up the map and
           // subtracts the shift to the index
           int num = (dict1[str[i]] - shift + 26) % 26;
           // looks up the second map for the
           // shifted alphabets and adds them
           decipher += dict2[num];
       }
       else
       {
           // adds space
           decipher += " ";
       }
   }
   return decipher;
}

// Driver code
int main()
{
   create_dict();
  
   string str;
   int shift = 13;
  
   cout << encrypt(str, shift) << "\n";
  
  
   shift = 13;
  
   cout << decrypt(str, shift) << "\n";
  
   return 0;
}


Related Solutions

Problem: Text manipulation as a technology has a myriad of applications, including coding and decoding, textual...
Problem: Text manipulation as a technology has a myriad of applications, including coding and decoding, textual analysis to determine authorship of a document, and automatic translation between languages. Learning to parse and process textual data is a valuable skill to master. Your assignment: Design, develop, and test an Object-Oriented C++ program to process multi-word phrases and sentences in a variety of ways. In this case, the required processing includes 1) reversing the words in a phrase, 2) sorting the words...
Problem: Text manipulation as a technology has a myriad of applications, including coding and decoding, textual...
Problem: Text manipulation as a technology has a myriad of applications, including coding and decoding, textual analysis to determine authorship of a document, and automatic translation between languages. Learning to parse and process textual data is a valuable skill to master. Your assignment: Design, develop, and test an Object-Oriented C++ program to process multi-word phrases and sentences in a variety of ways. In this case, the required processing includes 1) reversing the words in a phrase, 2) sorting the words...
Problem: Text manipulation as a technology has a myriad of applications, including coding and decoding, textual...
Problem: Text manipulation as a technology has a myriad of applications, including coding and decoding, textual analysis to determine authorship of a document, and automatic translation between languages. Learning to parse and process textual data is a valuable skill to master. Your assignment: Design, develop, and test an Object-Oriented C++ program to process multi-word phrases and sentences in a variety of ways. In this case, the required processing includes 1) reversing the words in a phrase, 2) sorting the words...
Please write a complete C coding program (NOT C++) that has the following: (including comments) -...
Please write a complete C coding program (NOT C++) that has the following: (including comments) - declares two local integers x and y - defines a global structure containing two pointers (xptr, yptr) and an integer (z) - declares a variable (mst) by the type of previous structure - requests the values of x and y from the user using only one scanf statement - sets the first pointer in the struct to point to x - sets the second...
PCR is a technology that has many useful applications with biotechnology. What are some of those...
PCR is a technology that has many useful applications with biotechnology. What are some of those applications? What are the advantages of PCR over gene cloning for generating many copies of a DNA fragment? Humans are almost identical in the protein-coding sections of the genome, yet each individual has a unique DNA profile. Explain how this is possible?
PCR is a technology that has many useful applications with biotechnology. What are some of those...
PCR is a technology that has many useful applications with biotechnology. What are some of those applications? What are the advantages of PCR over gene cloning for generating many copies of a DNA fragment? Humans are almost identical in the protein-coding sections of the genome, yet each individual has a unique DNA profile. Explain how this is possible.
PCR is a technology that has many useful applications with biotechnology. What are some of those...
PCR is a technology that has many useful applications with biotechnology. What are some of those applications? What are the advantages of PCR over gene cloning for generating many copies of a DNA fragment?
Molly, the coding supervisor of Homer General Hospital, has a problem. Her Discharged Not Final Billed...
Molly, the coding supervisor of Homer General Hospital, has a problem. Her Discharged Not Final Billed (DNFB) report is staying significantly over the limit that administration desires. She is also behind in some of the compliance monitoring that needs to be completed. Molly has been given the mandate to determine what needs to be done to bring the DNFB down and still maintain quality, as well as keep current in the compliance monitoring. She pulled together the information shown in...
c++problem Amelia is a computational geometry scientist. Her research has a broad range of applications –...
c++problem Amelia is a computational geometry scientist. Her research has a broad range of applications – from pure geometry applications, to applied fields such as computer mathematics, or physical simulations. As her research assistant, you’re going to help her analyze some triangles in 2d space that she generated from a sample program. Amelia is aware of the fact that you’re new to C++ so the task is easy this week (Based on what Amelia’s more experienced assistants say, this means...
Lack of places to sit and relax has been a problem in Ibri College of Technology...
Lack of places to sit and relax has been a problem in Ibri College of Technology for many students. They find it difficult to choose a place in their breaks where they can sit after a class or while waiting for their next class. Write a recommendation report to Dr Hamdan Al Manthari based on the problem given. Your report should have a heading, introduction, discussion of recommendations and a conclusion. Give your report a title.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT