Question
please answer only if you know
data structures question
provide C++ code please
4. Write definition of the function LetterCount() whose header is int LetterCount(string word) It returns the count of the di
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>

using namespace std;

int LetterCount(string word) {
    string distinct;

    for (int i = 0; i < word.size(); ++i) { // go through each character of word
        char ch = word[i];  // get character from word
        if (ch >= 'A' && ch <= 'Z') // if character is upeprcase
            ch = ch + 'a' - 'A';    // then convert it to lowercase

        bool found = false; // set found to false
        for (int j = 0; j < distinct.size(); ++j) { // go through all charcters of distinct
            if (ch == distinct[j])  // if this character at word is already in distinct string
                found = true;   // set found to true
        }

        if (!found) {   // if this character is not found in distinct
            distinct += ch; // then add it to distinct string
        }
    }

    return distinct.size(); // finally return the length of distinct string
}

int main() {
    cout << LetterCount("Hellohowareyou") << endl;
    return 0;
}

phpLIvnGT.png

Add a comment
Know the answer?
Add Answer to:
please answer only if you know data structures question provide C++ code please 4. Write definition...
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
  • Topics: About Java What is a compiler, and what does it do? Characteristics of the languageStrongly...

    Topics: About Java What is a compiler, and what does it do? Characteristics of the languageStrongly typed and statically typed Everything has a data type & data types must be declared Case sensitive Object oriented System.out.print() vs. System.out.println() How to use the Scanner class to obtain user input Data typesWhat are they? Know the basic types like: int, double, boolean, String, etc. Variables What is a variable? Declarations Initialization Assignment Constants Reserved words like: What is a reserved word? Examples:...

  • Please write code in C++ and include all headers not bits/stdc: 17.10 (Occurrences of a specified...

    Please write code in C++ and include all headers not bits/stdc: 17.10 (Occurrences of a specified character in a string) Write a recursive function that finds the number of occurrences of a specified letter in a string using the following function header. int count(const string& s, char a) For example, count("Welcome", 'e') returns 2. Write a test program that prompts the user to enter a string and a character, and displays the number of occurrences for the character in the...

  • answer in c++ please , Your objective is to write the definition of the function Equal()...

    answer in c++ please , Your objective is to write the definition of the function Equal() whose header is template <typename T> bool Equal(Node<T>* ar1,Node<T>* ar2) It returns true if the nodes of ar1 and ar2 with the same position have the same value, and ar1 and ar2 have the same length; otherwise, it returns false.

  • Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And...

    Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And also I have codes but just donot work so make sure that it works. Requested files: CrosswordGenerator.cpp, CrosswordGenerator.h, CrosswordGenerator_test.cpp CrosswordGenerator - Write a program that helps to generate a crossword puzzle by organizing words that share letters.   For this assignment, you will write a program that forms the basis of a crossword puzzle generator. In order to create a crossword puzzle you need to...

  • Data Structures and Algorithms. (C++ Language) 1. Write the definition code for a function that p...

    Data Structures and Algorithms. (C++ Language) 1. Write the definition code for a function that passes in a stack and returns (using a return statement) the number of items in the stack (the stack size). a. assume the this function is to be toolkit function in the implementation of the ADT stack. b. assume that this function is not a toolkit function. 2. Given the declaration: s = stack i = item struct STACK { INFO_RC i; int top; }...

  • Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank...

    Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank you. Here are the temps given: January 47 36 February 51 37 March 57 39 April 62 43 May 69 48 June 73 52 July 81 56 August 83 57 September 81 52 October 64 46 November 52 41 December 45 35 Janual line Iranin Note: This program is similar to another recently assigned program, except that it uses struct and an array of...

  • I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly...

    I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...

  • -PLEASE PROVIDE CLEAR AND CONCISE C++ CODE THAT HAS BEEN TESTED AND WORKS PROPERLY -PLEASE PROVIDE...

    -PLEASE PROVIDE CLEAR AND CONCISE C++ CODE THAT HAS BEEN TESTED AND WORKS PROPERLY -PLEASE PROVIDE WRITTEN CODE AND SCREENSHOT OF CODE - PLEASE DO NOT USE STL LIBRARIES - WRITE CODE BY MODIFYING GIVEN CODE - SUBJECT IS DATA STRUCTURES 4. Define the function InsertionSort() whose header is template <typename T> void InsertionSort (Node<T>* root) Given that root is a doubly linked node, the function sorts the data of the linked list pointed to by root using the insertion...

  • C programming language: If you malloc, make sure to assert and free the data. please do...

    C programming language: If you malloc, make sure to assert and free the data. please do not call any function you don't write yourself other than: malloc, free, assert, sizeof, scanf/printf families (eg., sprintf, fprintf & printf all OK to use) Write a function whose only argument is the input string. The function should return a new string which consists of only the upper case letters from the original string. The new string should be allocated to use the minimum...

  • Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a...

    Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a function that finds if a given value is present in a linked-list. The function should look for the first occurrence of the value and return a true if the value is present or false if it is not present in the list. Your code should work on a linked-list of any size including an empty list. Your solution must be RECURSIVE. Non-recursive solutions will...

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
ADVERTISEMENT