http://www.calstatela.edu/faculty/acervan5/cs242/2011/spring/homework.html#extra
ID: 3626685 • Letter: H
Question
http://www.calstatela.edu/faculty/acervan5/cs242/2011/spring/homework.html#extraCredit1.0% - Assume that a numeric value is assigned to each letter of the alphabet. A=1, B=2, C=3, ..., Y=25, Z=26. Write a program that prompts a user for a word or phrase and determines its numeric value. The value is to be calculated by summing the assigned values of every alphabet in the word or phrase.
For Example
Please enter a word or phrase: ace ace
The value for 'ace ace' is: 18
* 0.5% - Report the 1st 100 words in enable1.txt that have a value of 100.
* 1.0% - Prompt the User for a word or phrase, and report whether or not the input is a palindrome. Ignore spaces in your analysis.
For Example:
Please enter a word or phrase: never odd or even
'never odd or even' is a palindrome.
Explanation / Answer
please rate - thanks
this is 3 questions--but I'm bored
#include
#include
using namespace std;
bool isPalindrome( string& );
int main()
{string input;
bool palin;
int i;
cout<<"Enter a string: ";
getline(cin,input);
palin=isPalindrome(input);
if(palin)
cout<<<" is a Palindrome ";
else
cout<<<" is not a Palindrome ";
system("pause");
return 0;
}
bool isPalindrome(string& input)
{int i=0;
bool y=false;
string::size_type j=input.length()-1;
while(input[i]==input[j]&&i<=j)
{
i++;
j--;
if(!isalpha(input[i]))
i++;
if(!isalpha(input[j]))
j--;
}
if(i>j)
y=true;
return y;
}
----------------------------------
#include
#include
using namespace std;
bool isPalindrome( string& );
int main()
{string input;
int i,sum=0,val;
cout<<"Enter a string: ";
getline(cin,input);
for(i=0;input[i]!='';i++)
if(isalpha(input[i]))
{val=toupper(input[i])-'A'+1;
sum+=val;
}
cout<<"The value for '"<<<"' is: "<<
system("pause");
return 0;
}
--------------------------------------
#include
#include
using namespace std;
int main()
{int i,val,sum,count=0;
string input;
ifstream in;
in.open("enable1.txt");
if(in.fail())
{ cout<<"input file did not open please check it ";
system("pause");
return 1;
}
cout<<"1st 100 words with a value of 100 are ";
getline(in,input);
while( in )
{sum=0;
for(i=0;input[i]!='';i++)
if(isalpha(input[i]))
{val=toupper(input[i])-'A'+1;
sum+=val;
}
if(sum==100)
{count++;
cout<<<". "<<
}
if(count==100)
{in.close();
system("pause");
return 0;
}
getline(in,input);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.