Question

Create a class called cStringManipType that has 2 functions:       1. Displays an entire c-string reversed                    &nbs

Create a class called cStringManipType that has 2 functions:  

    1. Displays an entire c-string reversed                     

    2. Displays a c-string where every word is reversed

NOTE: Additional functions may be included in the class such          

        getCstring which would have the user enter a sentence.   

In main declare two objects of the class, get two sentences   

and then display each one completely in reverse and finally   

display each sentence with every word reversed   

EXAMPLE: If the two objects contained the sentences:   

     1st object: EVERY GOOD BOY & GIRL DOES FINE               

     2nd object: TO BE OR NOT TO BE   

         The output would be:

ENIF SEOD LRIG & YOB DOOG YREVE                 

EB OT TON RO EB OT   

YREVE DOOG YOB & LRIG SEOD ENIF                

OT EB RO TON OT EB                               

                                                                 

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

#include <iostream>

#include <cstring>

#define N 100

using namespace std;

class cStringManipType {

private:

char str[N];

public:

void getCString() {

cout << "Enter a string: ";

cin.get(str, N);

cin.ignore();

}

void getCStringReversed() {

for(int i=strlen(str)-1; i>=0; i--) {

cout << str[i];

}

cout << endl;

}

void getWordReversed() {

int i=0,j=0,k=0,l=0;

char y[N]={'\0'};

for(i=0;i<=strlen(str);i++)

{

if(str[i]==' ' || str[i]=='\0')

{

for(j=i-1;j>=l;j--)

y[k++] = str[j];

y[k++] = ' ';

l = i+1;

}

}

cout << y << endl;

}

};

int main() {

cStringManipType str1;

cStringManipType str2;

str1.getCString();

str2.getCString();

str1.getCStringReversed();

str2.getCStringReversed();

str1.getWordReversed();

str2.getWordReversed();

}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
Create a class called cStringManipType that has 2 functions:       1. Displays an entire c-string reversed                    &nbs
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a data file named REVERSE.TXT and type the sentence                        EVERY GOOD BOY & GIRL...

    Create a data file named REVERSE.TXT and type the sentence                        EVERY GOOD BOY & GIRL DOES FINE                                                                                  Write a C++ program that retrieves the phrase stored in the       the data file REVERSE.TXT and immediately displays the phrase    on the screen. Then your program displays the phrase where      each word is reversed. Notice you’re not reversing the entire sentence. The order of the words remains the same. However,    the spelling of each word is reversed! EXAMPLE:...

  • C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember...

    C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember class should have a constructor with no parameters, a constructor with a parameter, a mutator function and an accessor function. Also, include a function to display the name. Define a class called Athlete which is derived from FitnessMember. An Athlete record has the Athlete's name (defined in the FitnessMember class), ID number of type String and integer number of training days. Define a class...

  • public class EmployeeDriver public static void main(String[] args) 1/declare create an Employee object named joo. Une...

    public class EmployeeDriver public static void main(String[] args) 1/declare create an Employee object named joo. Une no-arg constructor 1/change the attributes for joe as the following: //name to Joe Cool, id to 1111111, hours to 20, pay rate to 15 //dealare & create another Employee oblegt named one using arg-constructor // The name of the new employees Jane Doeid is 2001122. She makes $10.50/hour // change the object Jane's hours to 40. 1/change the object jane's pay rate to $12.00....

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

  • C++ Define the class HotelRoom. The class has the following private data members: the room number...

    C++ Define the class HotelRoom. The class has the following private data members: the room number (an integer) and daily rate (a double). Include a default constructor as well as a constructor with two parameters to initialize the room number and the room’s daily rate. The class should have get/set functions for all its private data members [3pts]. The constructors and the set functions must throw an invalid_argument exception if either one of the parameter values are negative. The exception...

  • C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (Strin...

    C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...

  • C++ Program 1. Create a class named BaseballGame that has fields for two team names and...

    C++ Program 1. Create a class named BaseballGame that has fields for two team names and a final score for each team. Include methods to set and get the values for each data field. Your application declares an array of 12 BaseballGame objects. Prompt the user for data for each object, and display all the values. Then pass each object to a method that displays the name of the winning team or “Tie” if the score is a tie. (main.cpp,...

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

  • Project overview: Create a java graphics program that displays an order menu and bill from a...

    Project overview: Create a java graphics program that displays an order menu and bill from a Sandwich shop, or any other establishment you prefer. In this program the design is left up to the programmer however good object oriented design is required. Below are two images that should be used to assist in development of your program. Items are selected on the Order Calculator and the Message window that displays the Subtotal, Tax and Total is displayed when the Calculate...

  • Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment...

    Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT