1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
erma4kov [3.2K]
3 years ago
5

C++ a. Write a program that uses the function isPalindrome given in example 6-6 (Palindrome). Test your program on the followinn

g strings: "madam", "abba", "22", "67876", "444244", and "trymeuemyrt" b. Modify the function isPalindrome of example 6-6 so that when determining weather a string is a palindrome, cases are ignored, that is, uppercase and lowercase letters are considered the same. Example 6-6: bool isPalindrome (string str) { int length = str.Length(); for (int i = 0; i < length / 2; i++) if (str[i] != str[length - 1 - i]; return false; return true; }
Computers and Technology
1 answer:
Whitepunk [10]3 years ago
5 0

Answer:

#include <iostream>

#include <array>

using namespace std;

bool isPalindrome(string str)  

{  

int length = str.length();  

for (int i = 0; i < length / 2; i++)  

 if (toupper(str[i]) != toupper(str[length - 1 - i]))

  return false;  

return true;  

}

int main()

{

array<string, 6> tests = { "madam", "abba", "22", "67876", "444244", "trymEuemYRT" };

for (auto test : tests) {

 cout << test << " is " << (isPalindrome(test) ? "" : "NOT ") << "a palindrome.\n";

}

}

Explanation:

The toupper() addition forces characters to uppercase, thereby making the comparison case insensitive.

You might be interested in
Find the inverse function of f(x)= 1+squareroot of 1+2x
Svetllana [295]

Answer:

Therefore the inverse function of  f(x)=1+\sqrt{1+2x} is \frac{x^2-2x}{2}

Explanation:

We need to find the inverse of function f(x)=1+\sqrt{1+2x}

Function Inverse definition :

\mathrm{If\:a\:function\:f\left(x\right)\:is\:mapping\:x\:to\:y,\:then\:the\:inverse\:functionof\:f\left(x\right)\:maps\:y\:back\:to\:x.}

y=1+\sqrt{1+2x}\mathrm{Interchange\:the\:variables}\:x\:\mathrm{and}\:y

x=1+\sqrt{1+2y}

\mathrm{Solve}\:x=1+\sqrt{1+2y}\:\mathrm{for}\:y

\mathrm{Subtract\:}1\mathrm{\:from\:both\:sides}

1+\sqrt{1+2y}-1=x-1

Simplify

\sqrt{1+2y}=x-1

\mathrm{Square\:both\:sides}

\left(\sqrt{1+2y}\right)^2=\left(x-1\right)^2

\mathrm{Expand\:}\left(\sqrt{1+2y}\right)^2:\quad 1+2y

\mathrm{Expand\:}\left(x-1\right)^2:\quad x^2-2x+1

1+2y=x^2-2x+1

\mathrm{Subtract\:}1\mathrm{\:from\:both\:sides}

1+2y-1=x^2-2x+1-1

\mathrm{Simplify}

2y=x^2-2x

\mathrm{Divide\:both\:sides\:by\:}2

\frac{2y}{2}=\frac{x^2}{2}-\frac{2x}{2}

\mathrm{Simplify}

y=\frac{x^2-2x}{2}

Therefore the inverse function of f(x)=1+\sqrt{1+2x} is \frac{x^2-2x}{2}

4 0
3 years ago
True or False
steposvetlana [31]

Answer:

1. False

2. False

3. True

4. False

Explanation:

1. Folders are the containers to store files

2. The delete option deletes the file

3. Files are moved to recycle bin after being deleted, and can be permanently deleted from recycle bin

4. "MS-DOS was the main operating system for IBM PC compatible personal computers during the 1980s, from which point it was gradually superseded by operating systems offering a graphical user interface (GUI), in various generations of the graphical Microsoft Windows operating system."

<em>source for #4: Wikipedia</em>

3 0
3 years ago
Which game would be classified as an educational game
Masja [62]

Answer:

The various game types can be like board, video and card games. As far as educational video games are concerned they are made to explain to us some of the subjects which can be specific, as well as to teach a certain set of skills like role-playing. They are the interactive play that can help us learn the rules, goals, techniques to solve the problems. adaptation quality, as well as interactions, and all of these are being narrated in the form of a story. You should know that each game is a story in reality, and always. One can think of many such games, and like action games based on the military helps us learn how to fight a war.

Explanation:

Please check the answer.

7 0
3 years ago
Design and implement a set of classes that define various types of reading material: books, novels, magazines, technical journal
tino4ka555 [31]

Answer:

Following are the code to this question:

please find the attached file.

Explanation:

In this code, four class "novels, magazines, technical journals, and textbooks", is defined, in which it holds their respective default constructor and the get and set method to hold the string and integer value, and in the book class the main method is defined, that creates its object and a switch to for search value and print its value.

6 0
3 years ago
In order to consolidate your theoretical knowledge into technique and skills with practical and applicational value, you will us
Arisa [49]

Answer:

Check the explanation

Explanation:

Lasso: R example

To run Lasso Regression you can re-use the glmnet() function, but with the alpha parameter set to 1.

# Perform 10-fold cross-validation to select lambda --------------------------- lambdas_to_try <- 10^seq(-3, 5, length.out = 100) # Setting alpha = 1 implements lasso regression lasso_cv <- cv.glmnet(X, y, alpha = 1, lambda = lambdas_to_try, standardize = TRUE, nfolds = 10) # Plot cross-validation results plot(lasso_cv)

Best cross-validated lambda lambda_cv <- lasso_cv$lambda.min # Fit final model, get its sum of squared residuals and multiple R-squared model_cv <- glmnet(X, y, alpha = 1, lambda = lambda_cv, standardize = TRUE) y_hat_cv <- predict(model_cv, X) ssr_cv <- t(y - y_hat_cv) %*% (y - y_hat_cv) rsq_lasso_cv <- cor(y, y_hat_cv)^2 # See how increasing lambda shrinks the coefficients -------------------------- # Each line shows coefficients for one variables, for different lambdas. # The higher the lambda, the more the coefficients are shrinked towards zero. res <- glmnet(X, y, alpha = 1, lambda = lambdas_to_try, standardize = FALSE) plot(res, xvar = "lambda") legend("bottomright", lwd = 1, col = 1:6, legend = colnames(X), cex = .7)

Kindly check the Image below.

5 0
3 years ago
Other questions:
  • The class Date has a single constructor that accepts the integer value: a month- (1 for January through 12 for December), a day
    13·1 answer
  • What is primary storage
    11·2 answers
  • Xml is used to format the structure and style of a web page. true or false
    7·1 answer
  • How can people make sure they are using credit cards responsibly
    14·2 answers
  • (Complete the Problem-Solving discussion in Word for Programming Challenge 2 on page 404. Your Problem-Solving discussion should
    13·1 answer
  • 12.
    10·1 answer
  • You do not have to move your fingers to click the top row reach keys.<br> 1. True <br> 2. False
    15·1 answer
  • Does watching Beastars make me a furry? ​
    12·1 answer
  • A regional transportation and logistics company recently hired its first ChiefInformation Security Officer (CISO). The CISO’s fi
    7·1 answer
  • What is an advantage of using a dynamic hard drive in a vm?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!