Nerdylearner8639
06.03.2020 •
Computers and Technology
Some object is moving along a path in the plane. At n+1 points of time we have recorded the corresponding (x,y) positions of the object: (x0,y0), (x1,y1), ..., (xn,yn). The total length L of the path from (x0,y0) to (xn,yn) is the sum of all the individual line segments ((xi−1,yi−1) to (xi,yi), i=1,...,n): L=∑i=1n(xi−xi−1)2+(yi−yi−1)2−−−−−−−−−−−−−−−−−−−−−√. Write a function pathlength( x,y ) for computing L according to the formula. The arguments x and y hold all the x0,...,xn and y0,...,yn coordinates, respectively. (You may assume x and y are lists of the same length.) (This assignment is based on Langtangen, Exercise 3.17a.)
Solved
Show answers
More tips
- F Food and Cooking Fresh and Easy Lemonade in 10 Minutes...
- S Sport How to wrap boxing hand wraps? Everything you need to know!...
- F Family and Home How to Sew Curtain Tapes: Best Tips from Professionals...
- A Animals and plants How to Grow Lime from a Seed: Simple Tips and Interesting Facts...
- C Computers and Internet How to Create a Folder on Your iPhone?...
- G Goods and services How to sew a ribbon: Tips for beginners...
- F Food and Cooking How to Make Mayonnaise at Home? Secrets of Homemade Mayonnaise...
- C Computers and Internet Which Phone is Best for Internet Surfing?...
- F Food and Cooking Everything You Need to Know About Pasta...
- C Computers and Internet How to Choose a Monitor?...
Answers on questions: Computers and Technology
- C Computers and Technology You can calculate the surface area of a cube if you know the length of an edge. Write a program that takes the length of an edge (an integer) as input and prints the cube s...
- M Mathematics Jonathan operates an oil change and tune-up service. He charges 29.99 for 4 cylinder oil changes and 39.99 for 6-cylinder oil changes. He charges 75.00 for fuel system cleanings....
- S Social Studies Which has been a source of conflict in the Middle East...
- L Law The First Amendment restricts government officials from interfering with an individual s practice of his religious beliefs. (True or false)...
- M Mathematics Evaluate the expression. 7÷7–9×7...
- M Mathematics 11 ) A regular hexagon, where all the sides of the figure are equal in length, is shown....
- H History Which words describe why the pharaohs built their pyramids...
- M Mathematics Chloe and Eduardo are selling wrapping paper for a school fundraiser. Customers can buy rolls of plain wrapping paper and rolls of holiday wrapping paper. Chloe sold 5 rolls...
- H History Outline the process of how a bill passes through Congress. Include the procedure if the bill is amended after having passed either the House of Representatives or the Senate....
- P Physics Sound waves being bent as you yell through your cupped hands (medium does not change) is an example of?...
Ответ:
a) # include <iostream>
# include <conio.h>
# include <stdio.h>
# include <string.h>
using namespace::std;
bool IsPalindrome(const string& str)
{
if (str.empty())
return false;
int i = 0; // first characters
int j = str.length() - 1; // last character
while (i < j)
{
if (str[i] != str[j])
{
return false;
}
i++;
j--;
}
return true;
}
int main()
{
string str;
cout<<"Enter the string";
getline(cin, str);
bool a= IsPalindrome(str);
if(a)
{
cout<<"Is in palindrome";
}
else
{
cout<<"Is not in palindrome";
}
}
b) Modified version of function with full program to discard uppercase or lowercase is as below:
# include <iostream>
# include <conio.h>
# include <stdio.h>
# include <string.h>
using namespace::std;
bool IsPalindrome(const string& str)
{
if (str.empty())
return false;
int i = 0; // first characters
int j = str.length() - 1; // last character
while (i < j)
{
char a= tolower(str[i]);
char b= tolower(str[j]);
if (a != b)
{
return false;
}
i++;
j--;
}
return true;
}
int main()
{
string str;
cout<<"Enter the string";
getline(cin, str);
bool a= IsPalindrome(str);
if(a)
{
cout<<"Is in palindrome";
}
else
{
cout<<"Is not in palindrome";
}
}
Explanation:
Please check the answer section.