Answer to Question #294415 in C++ for Adarsh

Question #294415

Write a C program that follows these guidelines:

  1. Include the header file named tools.h. It will include all other headers you need.
  2. In main(), declare a character array that is 26 slots long.
  3. Print a title on the first line of the output: “Program 1: A List Of Letters Used”. Print your name or names on the second line of the output and leave a blank line after that.
  4. Write an input loop, and repeat it until the sentinel character (#) appears:
  5. (a) Read a character from the keyboard.
  6. (b) Terminate the input loop when the user types a #.
  7. (c) Otherwise, if the letter is not alphabetic, reject it and continue at the top of the loop.
  8. (d) If the letter is upper-case, change it to lower case.
  9. (e) Now you have a lower-case letter; find out if it has already been entered by comparing it to each of the letters you have saved in your array. If it is a duplicate, reject it and continue at the top of the loop.
  10. (f) Now you have a NEW lower-case letter. Store it in the first unused slot in your char array
1
Expert's answer
2022-02-06T06:00:37-0500
// File tools.h
#include <iostream>
#include <cctype>


// File program1.cpp
#include "tools.h"

int main() {
    char array[26];
    int count = 0;

    std::cout << "Program 1: A List Of Letters Used" << std::endl;
    std::cout << "John Doe" << std::endl;

    while (true) {
        char ch;
        std::cin >> ch;

        if (ch == '#') {
            break;
        }
        if (!std::isalpha(ch)) {
            continue;
        }
        if (std::isupper(ch)) {
            ch = std::tolower(ch);
        }

        for (int i=0; i<count; i++) {
            if (ch == array[i]) {
                continue;
            }
        }
        array[count++] = ch;
    }

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog