Question

In: Computer Science

c++ do add comments for better understanding Lapindrome is defined as a string which when split...

c++

do add comments for better understanding

Lapindrome is defined as a string which when split in the middle, gives two halves having the same characters and same frequency of each character. If there are odd number of characters in the string, we ignore the middle character and check for lapindrome. For example gaga is a lapindrome, since the two halves ga and ga have the same characters with same frequency. Also, abccab, rotor and xyzxy are a few examples of lapindromes. Note that abbaab is NOT a lapindrome. The two halves contain the same characters but their frequencies do not match.
Your task is simple, declare a C++ Class Lapindrome that has a function checkLapindrome which display Yes if the string is Lapindrome otherwise, it should display No. The structure of the Class is given below. You are required to implement every function given in the class Lapindrome.

class Lapindrome
{
private:
int size; char* cstr;
public:
Lapindrome (int size=10); //initialize size and cstr
void setStr(char* cstr); //Assign the value of cstr to member variable cstr
char* getStr();
//returns the string cstr. void checkLapindrome (); //Display Yes if the cstr is Lapindrome otherwise No ~Lapindrome();
//Destructor

};

Solutions

Expert Solution

#include <bits/stdc++.h> 
using namespace std; 
const int MAX_CHAR = 26; 
  

class Lapindrome
{
private:
int size; char* cstr;
public:
Lapindrome (int size,char*cstr){
    this->size= size;
    this->cstr = cstr;
}
void setStr(char* cstr){
    this->cstr = cstr;
}
char* getStr(){
    return this->cstr;
}

bool checkCorrectOrNot(char* s) 
{ 
    int count1[MAX_CHAR] = {0}; 
    int count2[MAX_CHAR] = {0}; 
    int n = strlen(s); 
    if (n == 1) 
        return true; 
  
   
    for (int i=0,j=n-1; i<j; i++,j--) 
    { 
        
        count1[s[i]-'a']++; 
        count2[s[j]-'a']++; 
    } 
  

    for (int i = 0; i<MAX_CHAR; i++) 
    {   
        if (count1[i] != count2[i]) 
        
        { return false; }
    }
    return true; 
} 

};

int main() 
{ 
    char array[] = "ababababaa";  
    char *pointer2 = array;  
    Lapindrome l1(15,pointer2);
    if(l1.checkCorrectOrNot(pointer2)){
    printf("true");
    }
    else{
        printf("false");
    }

    return 0; 
} 

Related Solutions

By default, if we do not include comments with the /C switch when using the Shutdown...
By default, if we do not include comments with the /C switch when using the Shutdown command, the Pop-up message will include the time available (countdown) before the shutdown occurs. TRUE OR FALSE When we use the NSLOOKUP command and see the result displays a "Non-authoritative answer", this means the information is inaccurate. TRUE OR FALSE Not only can we use the ROBOCOPY command to copy files and directories, we can also use it to move files and directories. TRUE...
/* Complete the TO DO comments below */ window.onload = function() { /* TODO add a...
/* Complete the TO DO comments below */ window.onload = function() { /* TODO add a border to the header of the page (a) a simple type selector, and (b) the style property of the element object. */ document.querySelector('TODO').TODO = TODO; /* TODO change the text of the h1 element by using (a) the first-child pseudo selector, and (b) the innerHTML property of the element object. */ document.querySelector('TODO').TODO = TODO; /* TODO change the background-color of the section with id...
PLEASE PROVIDE COMMENTS ON STEPS Write a C++ program that modifies a string (null terminated) as...
PLEASE PROVIDE COMMENTS ON STEPS Write a C++ program that modifies a string (null terminated) as follows: Consonants are positioned at the beginning of the string and vowels are moved to the end of the string. Example : Original string : washer New string : wshrae Note: The library string functions cannot be used. You must use pointers and the switch statement to execute this program. Assume that the vowels are a, e, i, o, and u. The modification has...
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
This is for C programming. Suppose one string is defined for a sentence with maximum 100...
This is for C programming. Suppose one string is defined for a sentence with maximum 100 characters. Write a method that prints maximum occurring characters in the input string and its frequency. For example, if input string is "this is testt", your code should print 't' : 4. Thank you.
PYTHON: How do I split up the binary string into chunks of 8 so that they...
PYTHON: How do I split up the binary string into chunks of 8 so that they are converted from binary to ASCII characters? For example "0011101000101001" would be eventually converted to ":)" . The code I have below is what I currently have. It currently only works for binary strings of 8. argv[1] is the text file it is reading from and argv[2] is basically just 8. import sys filename=sys.argv[1] length = int(sys.argv[2]) message_data = open(filename, "r") message_text = message_data.read()...
C++: A string construction problem defined as follows: - You are given as input a target...
C++: A string construction problem defined as follows: - You are given as input a target string - Starting with an empty string, you add characters to it, until your new string is same as the target. You have two options to add characters to a string: - You can append an arbitrary character to your new string, with cost x - You can clone any substring of your new string so far, and append it to the end of...
c++ I want to flip the string when it's string type. For example, if it is...
c++ I want to flip the string when it's string type. For example, if it is 'apple', I would like to print 'elppa'. how can i do?
C PROGRAM STRING AND FILE PROCESSING LEAVE COMMENTS! I WILL LEAVE POSITIVE REVIEW! THANK YOU :)...
C PROGRAM STRING AND FILE PROCESSING LEAVE COMMENTS! I WILL LEAVE POSITIVE REVIEW! THANK YOU :) I need a program that 1) Count all words in a file. A word is any sequence of characters delimited by white space or the end of a sentence, whether or not it is an actual English word. 2)Count all syllables in each word. To make this simple, use the following rules: •Each group of adjacent vowels (a, e, i, o, u, y) counts...
hi,I have this C++ program,can someone add few comments with explanation what is the logic and...
hi,I have this C++ program,can someone add few comments with explanation what is the logic and what is what?thank you I m total beginner #include <iostream> using namespace std; int ArraySum(int MyArray[], int size){ int* p = MyArray; int sum = 0; while(p<MyArray+size){ sum += *p; p++; } return sum; } int main() { int MyArray[10] = {4, 0, 453, 1029, 44, 67, 111, 887, 4003, 1002}; cout<<ArraySum(MyArray,10); return 0; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT