Question

Write a function, value of (Word), which returns t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <iomanip>

using namespace std;

//Function declarations
int valueOf(string word);
int numberOf(char ch);
int main()
{
   //Declaring variables
string word;
  
//Getting the word entered by the user
cout<<"Enter a word :";
cin>>word;
  
//Displaying the value of the word
cout<<"valueOf('"<<word<<"')"<<endl;
  
//calling te function by passsing the word as argument
cout<<valueOf(word);

   return 0;
}

/* Function implementation which finds the value of a character
* Params: character
* return: value of character of type int
*/
int numberOf(char ch)
{
   //Declaring an array of charcaters
   char chararr[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  
   //Declaring an array of numbers
   int nosarr[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26};
  
   //this for loop will return the value of the character
   for(int i=0;i<26;i++)
   {
       if(ch==chararr[i])
       {
           return nosarr[i];
       }
   }
}

//Function implentation which calculates the value of the word
int valueOf(string word)
{
   //Declaring variables
   int sum=0;
  
   //Finding the length of the word
   int len=word.length();
  
   //This for loop will calculates the value of the word
for(int i=0;i<len;i++)
{
   //Adding the values of each character
   sum+=numberOf(word[i]);
}
return sum;
  
}

__________________________

Output:

CProgram Files 86)\Dev-Cpp MinGW64\bin\ValueOfword.exe Enter a word abe valueOf <abe> 8 Process exited af ter 3.214 Seconds

____________Thank You

Add a comment
Know the answer?
Add Answer to:
Write a function, value of (Word), which returns the value of a word of lowercase letters,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function that converts letters in string that is passed to, to lowercase: function("ALPHABET"); //...

    Write a function that converts letters in string that is passed to, to lowercase: function("ALPHABET"); // returns "alphabet" no built in javascript methods, must output to the console

  • u also need to store the letters' ASCII number in the freq array 4. [8] Write...

    u also need to store the letters' ASCII number in the freq array 4. [8] Write a C function with prototype · void letter_freq(const char word[], int freq []); This function computes the number of appearances of each letter in the string word and stores them in array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90...

  • using basic c++ and use no functions from c string library b) Write a fragment of...

    using basic c++ and use no functions from c string library b) Write a fragment of code (with declarations) that reads a pair of words from the keyboard and determines how many letters in corresponding positions of each word are the same. The words consist only of the letters of the English alphabet (uppercase and lowercase). For example, if the words are coat and CATTLE, the following output should be generated: 012245 0122 matching letter in position 0 t is...

  • Write a function called most_consonants(words) that takes a list of strings called words and returns the...

    Write a function called most_consonants(words) that takes a list of strings called words and returns the string in the list with the most consonants (i.e., the most letters that are not vowels). You may assume that the strings only contain lowercase letters. For example: >>> most_consonants(['python', 'is', 'such', 'fun']) result: 'python' >>> most_consonants(['oooooooh', 'i', 'see', 'now']) result: 'now' The function that you write must use a helper function (either the num_vowels function from lecture, or a similar function that you...

  • 4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This...

    4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This function computes the number of appearances of each letter in the string word and stores them irn array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90 for the uppercase letters. You must account for uppercase and lowercase letter variants, which...

  • in c, 5. Write a function that tests whether two words are anagrams. The function returns...

    in c, 5. Write a function that tests whether two words are anagrams. The function returns 1 if the two words are anagrams, returns 0 otherwise. Two words are anagrams if they are permutations of the same letters. For example, smartest and mattress are anagrams and dumbest and stumble are not anagrams. Assume wordl and word2 are null-terminated strings containing arbitrary lower-case alphabetic letters. Hint: use an array of 26 integers to keep track of how many times each letter...

  • Write a function that, given a word and a set of characters, filters all occurrences of...

    Write a function that, given a word and a set of characters, filters all occurrences of those characters from the word. For e.g. remove_chars("abcdeeeeefmnop", "ebo") returns: acdfmnp i.e all occurrences of e, b and o have been removed from abcdeeeeefmnop You should acquire the word and set of characters both from the user and then pass them to the function. Note: std::cin terminates when it encounters a space, you should take the word and character set as separate inputs: std::cin...

  • Solve it in Python 4. An alternade is a word in which its letters, taken alternatively...

    Solve it in Python 4. An alternade is a word in which its letters, taken alternatively in a strict sequence, and used in the same order as the original word, make up at least two other words. All letters must be used, but the smaller words are not necessarily of the same length. For example, a word with seven letters where every second letter is used will produce a four-letter word and a three-letter word. Here are two examples: "board":...

  • To be done in java code. 2 words are anagrams if 1 word can be formed...

    To be done in java code. 2 words are anagrams if 1 word can be formed by rearranging all the letters of the other word, eg: mary, army a word is represented as a linked list with one letter per node of the list. Write a function that, given w1 and w2, with each pointing to a word of lowercase letters, returns 1 if the words are anagrams and 0 if they are not. Base your algorithm on the following:...

  • Function name: crazy_scrabble Parameters : word (string), current points (int), double word score (boolean) Returns: int...

    Function name: crazy_scrabble Parameters : word (string), current points (int), double word score (boolean) Returns: int Description: You are playing scrabble with a friend, and you thought you knew how to calculate how many points you have, but your friend suddenly starts making up all these crazy rules. Write a function that helps keep track of how many points you have with these new rules: ●Each 'k', 'm', 'p', 'x', 'y', and 'z' earns you 7 points. ●'c' and 's'...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT