Question

Write a C++ program that defines an array of 10 characters ( only lower-case letters )...

Write a C++ program that defines an array of 10 characters ( only lower-case letters ) then you have to check if character 'a' oppears within the array by outputting the index of the character of it is found otherwise output " the character is not found " .

Homework Answers

Answer #1

It is not mentioned whether the array of 10 characters are taken from user or given directly. So lets assume that these 10 characters are taken from user. Also it is not mentioned whether these 10 characters are distinct (or) not. So lets consider these are not distinct which means 'a' can appear zero(or) more number of times in array. The C++ program of the above scenario is given below :

#include <iostream>
using namespace std;

int main()
{
    int i=0,count=0;
    char arr[10];
    cout<<"Enter the lower-case characters"<<"\n";
    cin>>arr;
    for(i=0;i<10;i++)
    {
        if(arr[i]=='a')
        {
            cout<<"'a' is found at index "<<i<<"\n";
            count++;
        }
    }
    if(count==0)
        cout<<"The character is not found"<<"\n";
    return 0;
}

The screen shot of compiled code is given below :

The output when all the characters are distinct is shown below :

The output when the characters are not distinct is shown below :

The output when the character 'a' is not present is shown below :

Know the answer?
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
Similar Questions
An array of characters contains a few letters. Write a complete C program that will display...
An array of characters contains a few letters. Write a complete C program that will display the output as shown below. Lets assume the array contains =”abcde”. The program should be able to work with any array size, configurable in the program. Expected output Original array = [ a b c d e] a a b a b c a b c d a b c d e
Write a program that takes a string of characters (including spaces) as input, computes the frequency...
Write a program that takes a string of characters (including spaces) as input, computes the frequency of each character, sorts them by frequency, and outputs the Huffman code for each character.   When you are writing your program, you should first test it on a string of 7 characters, so you can check it. PLEASE NOTE: Your program must work for any text that has upper and lower case letters digits 0 - 9, commas, periods, and spaces. Please submit the...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
3. Write function, leastChar(inputString) that takes as input a string of one or more letters (and...
3. Write function, leastChar(inputString) that takes as input a string of one or more letters (and no other characters) and prints 1) the "least" character in the string, where one character is less than another if it occurs earlier in the alphabet (thus 'a' is less than 'C' and both are less than 'y') and 2) the index of the first occurrence of that character. When comparing letters in this problem, ignore case - i.e. 'e' and 'E' should be...
1) Assume that a password can contain upper and lower-case letters (26), digits, and special characters...
1) Assume that a password can contain upper and lower-case letters (26), digits, and special characters from the set { !, #, $, %, &, * }. Furthermore, each password must start with a letter and must contain at least one digit and one special character. How many different six-character passwords can be formed according to this specification?
ANSWER IN C++ ONLY A string of characters including only alphabets (lowercase letters) is provided as...
ANSWER IN C++ ONLY A string of characters including only alphabets (lowercase letters) is provided as an input. The first task is to compute the frequency of each character appearing in the string. In the output, the characters have to be arranged in the same order as they appear in the input string. Then characters have to be rearranged, such that all the characters having a specific frequency, say xx, come together. Let the frequency of a character, lying in...
(C++) Write a program whose input is two characters and a string, and whose output indicates...
(C++) Write a program whose input is two characters and a string, and whose output indicates the number of times each character appears in the string. Ex: If the input is: n M Monday the output is: 1 1 Ex: If the input is: z y Today is Monday the output is: 0 2 Ex: If the input is: n y It's a sunny day the output is: 2 2 Case matters. Ex: If the input is: n N Nobody...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
Write a program in c++ to Convert an array of inches to an array of centimeters....
Write a program in c++ to Convert an array of inches to an array of centimeters. The program should contain a function called inchesTOcm with three parameters (inches array that contains the values in inches, cm array to save the result in, and an integer variable that defines the length of the array). In the main function: 1. Define an array (inches) of length 3. 2. Initialize the array by asking the user to input the values of its elements....
C++ Write a recursive routine that will have a character array and an index as parameters...
C++ Write a recursive routine that will have a character array and an index as parameters and will return the count of all vowels (assume lowercase). You may assume that the index starts out at the END of the array.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT