Question

In: Computer Science

Note: The built-in character analysis functions (isdigit(), islower(), etc.) may not be used. Exercise 6.1 Write...

Note: The built-in character analysis functions (isdigit(), islower(),
etc.) may not be used.

Exercise 6.1 Write to an output file
Open an output file (stream) and write your identifying information to the
associated output file using a function. Put your standard output informa-
tion in a function named ShowHeader(). The file stream must be passed by
reference to the function. To do this, an & (ampersand) is used between the
data type (ofstream) and the name of the argument (I like to use fOut for
output file stream objects and fIn for input file stream object names).

Exercise 6.2 Read from an input file
Read/Process an input file a character at a time. Open an input file (stream)
and read a single character on each pass through a loop (a while() loop is
probably easiest) until the end of file is reached. After reading the character,
write it to the output file created earlier. The output should contain the
same characters as the input file.

Exercise 6.3 Character Analysis
Suggestion: Develop the remainder of this program in piecewise manner–
specifically, add one character analysis operation at a time, before adding
the next.
Analyze the characters in a file using functions to display their charac-
teristics, e.g., lower case, digit etc. The logic for analysis will be inside the
loop above.
Specifically, test if the character:
• is a letter.
• test if it is lower case or upper case.
• if the character is a letter, test if it is a vowel or consonant.
• is a digit.
• if the character is a digit, test if the value is odd or even.
• is a punctuation character.
• is a logical operator symbol.
Write a short function for most operations in the list above. If a character
is a letter, then it is either upper or lower case, so we only need to write one
function to test the case of the character. Do not use the built-in functions.

Note: there are no I/O (input/output) operations in the functions, only a
single character is examined.

Solutions

Expert Solution

Exercise 6.1
Answer :

#include <iostream>
#include <fstream>
using namespace std;


void ShowHeader(ifstream& fileOut){

    int data;
    while (fileOut >> data) {
        fileOut << data << endl;
    }
}

int main()
{

    ofstream fOut;
    char *fileOut = fOut.open("output data file");
    ShowHeader(fileOut);

    fOut.close();

}


Exercise 6.2
Answer :

#include <iostream>
#include <fstream>
using namespace std;

int main()
{

    ifstream fIn;
    ofstream fOut;
    fIn.open("input data file");
    fOut.open("output data file");
    int data;
    while (fIn >> data) {
        fOut << data << endl;
    }

    fIn.close();
    fOut.close();

}

Excercise 6.3

#include <iostream>
#include <fstream>
using namespace std;


void calculateAverage(ifstream& inp, ifstream& iop)
{
    int data;
   while (inp >> data)
    {
        if (isalpha(inp >> data)){
            iop << data <<"is Letter" << endl;
        }
        if (tolower(inp >> data)){
            iop << data <<"is LowerCase" << endl;
        }
        if (toupper(inp >> data)){
            iop << data <<"is Upper Case" << endl;
        }
        if(inp >> data=='a' || inp >> data=='e' || inp >> data=='i' ||
           inp >> data=='o' || inp >> data=='u' || inp >> data=='A' ||
           inp >> data=='E' || inp >> data=='I' || inp >> data=='O' ||
           inp >> data=='U'){
           iop << data <<"is Vowel" << endl;
           }
           else if((inp << data>='a'&& inp << data<='z') || (inp << data>='A'&& inp << data<='Z'))
        {
             iop << data <<" is Consonants" << endl;
        }
         if(inp << data >='0' && inp << data <='9')
        {
            iop << data <<"is Digit" << endl;
            if( inp >> data % 2 == 0){
                iop << data <<" and is Even" << endl;
            }
            else{
                iop << data <<" and is Odd" << endl;
            }

        }
        if (ispunct(inp << data)){
         iop << data <<" is punctuation character" << endl;
        }
        if(inp << data >='&&' || inp << data <='||' || inp << data <='!'){
            iop << data <<" logical operator symbol " << endl;
        }
        }

}
int main()
{

    ofstream fIn;
    ofstream fOut;
      char *fIn = fOut.open("output data file");
    char *fOut = fOut.open("output data file");
    ShowHeader(fIn, fOut);

    fOut.close();

}


Related Solutions

In the Python: Note 1: You may not use these python built-in functions: sorted(), min(), max(),...
In the Python: Note 1: You may not use these python built-in functions: sorted(), min(), max(), sum(), pow(), zip(), map(), append(), count() and counter(). (7 points) unique.py: A number in a list is unique if it appears only once. Given a list of random numbers, print the unique numbers and their count. Print the duplicate numbers and their count. Sample runs: Enter the size of the list : 7 [8, 2, 6, 5, 2, 4, 5] There are 3 unique...
PLEASE NOTE:1)-DO NOT USE FUNCTIONS USE ONLY DO WHILE LOOP.                          2)DO NOT USE IN-BUILT FUNCTIONS....
PLEASE NOTE:1)-DO NOT USE FUNCTIONS USE ONLY DO WHILE LOOP.                          2)DO NOT USE IN-BUILT FUNCTIONS.                          3)Use of string and char is not allowed.             Write a program in c laungage that prints a table of the binary, octal and hexadecimal equivalents of the decimal numbers in the range1 through 256.
Write a 150-word character analysis of the protagonist King Oedipus as he is portrayed in the...
Write a 150-word character analysis of the protagonist King Oedipus as he is portrayed in the portion of the play.
Please write code for C language Problem: Write a couple of functions to process arrays. Note...
Please write code for C language Problem: Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an...
Write a class IgnoreCaseComparator that implements Comparator<Character>. If it were used as the argument to List.sort(),...
Write a class IgnoreCaseComparator that implements Comparator<Character>. If it were used as the argument to List.sort(), it would sort the list ignoring case. This behavior is different from using the natural ordering of characters, where uppercase characters come before lowercase characters. Note that this question is not asking you to sort a list -- just to write the comparator! For example, if the unsorted list were [b, C, A, d], then the list would be [A, b, C, d] after...
The hypothalamus is important in what body functions? Note: Please write or type in a way...
The hypothalamus is important in what body functions? Note: Please write or type in a way that is legible and understandable. Thank you for taking the time to answer my question.
Write a program in which, you define and call each of the following functions, note that...
Write a program in which, you define and call each of the following functions, note that YOU CANNOT USE ARRAY NOTATION IN ANY FUNCTION AT ALL IN THIS EXERCISE, ONLY USE POINTER NOTATION TO MANIPULATE ARRAYS IN THE FUNCTIONS: 1. function read_array, that takes an array of 6 doubles and prompts the user to fill it through the keyboard. 2. function reverse_array, that takes an array of 6 doubles and reverses its contents. 3. function swap_arrays, that takes two arrays...
C++ 10.15: Character Analysis Write a program that reads the contents of a file named text.txt...
C++ 10.15: Character Analysis Write a program that reads the contents of a file named text.txt and determines the following: The number of uppercase letters in the file The number of lowercase letters in the file The number of digits in the file Prompts And Output Labels. There are no prompts-- nothing is read from standard in, just from the file text.txt. Each of the numbers calculated is displayed on a separate line on standard output, preceded by the following...
You can only use built in Lisp functions and you cannot use setq function. Write a...
You can only use built in Lisp functions and you cannot use setq function. Write a function in Lisp called f1 that counts the number of lists in a list. Example: (f1 ‘(a (a b (b c)) c d (e))) returns 2
Summarize the built-in security features and tools used in modern cloud infrastructures. You may select among...
Summarize the built-in security features and tools used in modern cloud infrastructures. You may select among Amazon AWS, Microsoft Azure and Google Cloud. Use internet resources to answer this question.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT