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.

Hopefully I can get some help on this one - this has been answered before on here, but the provided answers are all copies of one another that use the same code and do not work as required. Any help would be greatly appreciated and will be upvoted.

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

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

main.cpp

#include "Phrase.cpp"

int main()
{
        StrOper obj;
        int ch;
        do
        {
                cout << "\n1. New Phrase.\t 2. Reverse words.\t 3. Sort.\t 4. Rot13. \t 5. Quit";
                cout << "\n Enter choice";
                cin >> ch;
                switch (ch)
                {
                case 1:
                        obj.newphrase();
                        cout << endl;
                        break;
                case 3:
                        obj.sort();
                        cout << endl;
                        break;
                case 2:
                        obj.reversestr();
                        cout << endl;
                        break;
                case 4:
                        obj.rot();
                        cout << endl;
                        break;
                case 5:
                        break;
                default:
                        cout << "\n invalid choice";
                }
        } while (ch != 5);
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Phrase.h

#include <iostream>
#include<string.h>
using namespace std;
class StrOper
{
public:
        string str;
        void newphrase();
        void rot();
        void sort();
        void reversestr();
};

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Phrase.cpp

#include "Phrase.h"
 void StrOper::newphrase()
        {
                cout << "Enter the string\n";
                getline(cin,str);
        }
        void StrOper::rot()
        {
                char str1[100];
                int i = 0;
                while (str[i] != '\0')
                {
                        if (str[i] >= 'A' && str[i] <= 'Z')
                        {
                                str1[i] = str[i] + 13;
                                i = i + 1;
                        }
                        else
                        {
                                str1[i] = str[i] - 13;
                                i = i + 1;
                        }
                }
                cout << "\n Rot13 is:\t";
                cout << str1;
        }
        void StrOper::sort()

        {
                int i, j, k, len, wcount = 0;
                char p[50][100], cmp[50];
                len = str.length();
                // counting total words in a sentence
                for (i = 0; i < len; i++)
                {
                        if (str[i] == ' ')
                        {
                                wcount = wcount + 1;
                        }
                }
                i = 0;
                k = 0;
                // extracting words from senctance and place in an array
                for (j = 0; j < str.length(); j++)
                {
                        if (str[j] == ' ')
                        {
                                p[i][k] = '\0';
                                i++;
                                k = 0;
                        }
                        else
                                p[i][k++] = str[j];
                }

                // sorting words
                for (i = 0; i < wcount; i++)
                {
                        for (j = i + 1; j <= wcount; j++)
                        {
                                if ((strcmp(p[i], p[j]) > 0))
                                {
                                        strcpy(cmp, p[i]);
                                        strcpy(p[i], p[j]);
                                        strcpy(p[j], cmp);
                                }
                        }
                }
                cout << "After sorting string is \n";
                for (i = 0; i < wcount; i++)
                        cout << p[i] << "\t";

                cout << endl;
        }

        void StrOper::reversestr()
        {

                int i, j = 0, k = 0, x, len;
                char str1[50][100], temp;
                for (i = 0; str[i] != '\0'; i++)
                {
                        if (str[i] == ' ')
                        {
                                str1[k][j] = '\0';
                                k = k + 1;
                                j = 0;
                        }
                        else
                        {
                                str1[k][j] = str[i];
                                j = j + 1;
                        }
                        str1[k][j] = '\0';
                }

                for (i = 0; i < k; i++)
                {
                        len = strlen(str1[i]);
                        for (j = 0, x = len - 1; j < x; j++, x--)
                        {
                                temp = str1[i][j];
                                str1[i][j] = str1[i][x];
                                str1[i][x] = temp;
                        }
                }
                for (i = 0; i <= k; i++)
                {
                        cout << str1[i] << "\t";
                }
        }

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