Concept explainers
Palindrome Testing
A palindrome is a string that reads the same backward as forward. For example, the words worn, dad, madam and radar are all palindromes. Write a class Pstring that is derived from the STL string class. The Pstring class adds a member function
bool isPalindrome( )
that determines whether the string is a palindrome. Include a constructor that takes an STL string object as parameter and passes it to the string base class constructor. Test your class by having a main
You may find it useful to use the subscript operator [ ] of the string class: If str is a string object and k is an integer, then str[k] returns the character at position k in the string.
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Starting Out with C++: Early Objects (9th Edition)
Additional Engineering Textbook Solutions
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
SURVEY OF OPERATING SYSTEMS
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Mechanics of Materials (10th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
- In C++ yhou will create a new class named StringMod that will have several functions specific tostring. Here is a UML diagram:StringMod- str : string+ StringMod()+ StringMod(string);+ size() const : int+ backwards() const : string+ count(char) const : int+ getString() const : string+ uppercase() const : string+ lowercase() const : string+ erase() : void+ setString(string) : voidFirst of all, none of these functions should contain output statements! No cout, no cin, in any of thesefunctions!As you can see, several of the methods of StringMod are const, meaning they won’t change theinternal string. You’ll likely declare a local string which will be updated and then returned.The default constructor just sets str to an empty string, "". The constructor with parameters should justcall setString() to set str to the value passed to the constructor.backwards() returns a new string that is the reverse of the string in str.uppercase() takes every letter in the string and capitalizes it, while…arrow_forwardTerm by CodeChum Admin (JAVA CODE) Construct a class called Term. It is going to represent a term in polynomial expression. It has an integer coefficient and an exponent. In this case, there is only 1 independent variable that is 'x'. There should be two operations for the Term: public Term times(Term t) - multiplies the term with another term and returns the result public String toString() - prints the coefficient followed by "x^" and appended by the exponent. But with the following additional rules: if the coefficient is 1, then it is not printed. if the exponent is 1, then it is not printed ( the caret is not printed as well) if the exponent is 0, then only the coefficient is printed. Input The first line contains the coefficient and the exponent of the first term. The second line contains the coefficient and the exponent of the second term. 1·1 4·3 Output Display the resulting product for each of the test case. 4x^4arrow_forwardComputer sciencearrow_forward
- javascript Need help defining a function frequencyAnalysis that accepts a string of lower-case letters as a parameter. frequencyAnalysis should return an object containing the amount of times each letter appeared in the string. example frequencyAnalysis('abca'); // => {a: 2, b: 1, c: 1}arrow_forwardJavaarrow_forwardthe function returns the result as a string if the expression is legal. the expression returns an empty string and then put the function public class Ez1MathEval {public String heavywtEval (String exprn) {return ""}}arrow_forward
- Homework 10-1 Programming Challenge: 2 - Backwards String Write a function that accepts a string and returns a string in which the contents are the reverse of the original string, and a program in which this function is demonstrated. The prototype is string reverseString(const string &); This might need a little explanation. We want to pass the string by reference (as is customary for objects) but we don't want the function to make any changes to our string. Thus, we pass as a "constant reference." Newer languages like Java do this automatically; if you pass an object to a Java method, it's handled internally kind of like this, as a constant reference to that object. Any changes made to the object within the function are strictly local; the original object is unchanged. So our function will return a brand new string with contents equal to the reverse of the string sent to the function.arrow_forwardWrite a class BCheckString that is derived from the STL string class. This new class will have two member functions: A) A BCheckString(string s) constructor that receives a string object passed by value and passes it on to the base class constructor.B) An char operator[](int k) function that throws a BoundsException object if k is negative or is greater than or equal to the length of the string. If k is within the bounds of the string, this function will return the character at position k in the string. You will need to write the definition of the BoundsException class. Test your class with a main function that attempts to access characters that are within and outside the bounds of a suitably initialized BCheckString object.arrow_forwardC++arrow_forward
- Fix the errors in the Customer class and the Program. #include <iostream>#include <fstream>#include <string>using namespace std; class Customer {// Constructorvoid Customer(string name, string address) : cust_name(name), cust_address(address){acct_number = this.getNextAcctNumber();} // Accessor to get the account numberconst int getAcctNumber() { return acct_number; } // Accessor to get the customer namestring getCustName(} const { return cust_name; } // Accessor to get the customer addressstring getCustAddress() const { return cust_address; } // Set a customer name and addressstatic void set(string name, string address); // Set a customer addressvoid setAddress(string cust_address) { cust_address = cust_address; } // Get the next account number for the next customer.static const unsigned long getNextAcctNumber() { ++nextAcctNum; } // input operatorfriend Customer operator>> (istream& ins, Customer cust); // output operatorfriend void operator<<…arrow_forwardComputer Science You are required to develop a small chatting application where two or more friends can communicate each other through messages. Create a class Message which has Date d, and message (string). Provide getters/setters, constructors, toString. Create a class Friend having String name, String contact, email and ArrayList of Messages provide getters/setters, constructors, toString addMessage(Message m) method which will add new message to the list. Provide following options to the user using JFrame. Login which will help user login to the application. View Friends (Display List of All Friends) View Messages ( This should display all message of a Friend) Send message (This should ask for friend name and message match the friend name and write that message to the array list).arrow_forwardFill in the blanksarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT