Question

Write a user-defined function in C++ to read the content from a text file OUT.TXT, count...

  1. Write a user-defined function in C++ to read the content from a text file OUT.TXT, count and display the number of alphabets present in it

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

Hi

Please find the snapshot for the code, test file and output, for the required program, I have added the comments in thee code for the ease of your understanding.

******** SNAPSHOT ******

#include<iostream> #include<fstream> #include<string> using namespace std; int main(void) FILE *fp; int c; int count =0; //To

******** FILE TAKEN FOR TESTING *********

test - Notepad Eile Edit Format View Help ab sd coser

************ OUTPUT **********

Total alphabet in count is 9

******** CODE ********

#include<iostream>

#include<fstream>

#include<string>

using namespace std;

int main(void)

{

    FILE *fp;

    int c;

    int count =0; //To store the aplhabet count

    fp = fopen("test.txt", "r");

    //fgetc is used to read the charater from file stream fp

    //And the condtion runs till the EOF

    while((c = fgetc(fp)) != EOF) {

        //This condition is used to check if the character is an alphabet

        if((c > 63 && c < 91) or (c > 96 && c < 123))

                        count++;

    }

    cout << "Total alphabet in count is "<<count;

    fclose(fp);

    return 0;

}

***************************

I hope it helps

Please get back to me in comment section incase of any query

Add a comment
Know the answer?
Add Answer to:
Write a user-defined function in C++ to read the content from a text file OUT.TXT, count...
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
  • Function / File Read (USING MATLAB) A) create a user-defined function : [maxsample , maxvalue , numsamples]=writetofile(sname,strgth) to do the following: The user-defined function shall: -Accept as t...

    Function / File Read (USING MATLAB) A) create a user-defined function : [maxsample , maxvalue , numsamples]=writetofile(sname,strgth) to do the following: The user-defined function shall: -Accept as the input a provided string for the sample name (sname) and number for strength (strgth) - open a text file named mytensiledata.txt, with permission to read or append the file. - Make sure to capture any error in opening the file - Write sname and strgth to the file - Close the file...

  • (Count the occurrences of words in a text file) Rewrite Listing 21.9 to read the text...

    (Count the occurrences of words in a text file) Rewrite Listing 21.9 to read the text from a text file. The text file is passed as a command-line argument. Words are delimited by white space characters, punctuation marks (, ; . : ?), quotation marks (' "), and parentheses. Count the words in a case-sensitive fashion (e.g., consider Good and good to be the same word). The words must start with a letter. Display the output of words in alphabetical...

  • Write a C program to run on ocelot to read a text file and print it...

    Write a C program to run on ocelot to read a text file and print it to the display. It should optionally find the count of the number of words in the file, and/or find the number of occurrences of a substring, and/or take all the words in the string and sort them lexicographically (ASCII order). You must use getopt to parse the command line. There is no user input while this program is running. Usage: mywords [-cs] [-f substring]...

  • Write a user-defined MATLAB function for the following math function y(x). The input to the function...

    Write a user-defined MATLAB function for the following math function y(x). The input to the function is x and the output is y. y(x)=-(0.2*x^4)+((e^-0.5*x)*x^3)+7*x^2 Call the function to calculate y(x) over the interval -3 ≤ x ≤ 4 for each increment of 1. Display x and corresponding y(x) in a text file with labeled column headings. Use the type command to display the contents in the text file.

  • Basic C program Problem: In this assignment, you have to read a text file (in.txt) that...

    Basic C program Problem: In this assignment, you have to read a text file (in.txt) that contains a set of point coordinates (x,y). The first line of the file contains the number of points (N) and then each line of the file contains x and y values that are separated by space. The value of x and y are an integer. They can be both negative and positive numbers. You have to sort those points in x-axis major order and...

  • python Write the function getSpamLines(filename) that read the filename text file and look for lines of the form &#...

    python Write the function getSpamLines(filename) that read the filename text file and look for lines of the form 'SPAM-Confidence: float number'. When you encounter a line that starts with "SPAM-Confidence:" extract the floating-point number on the line. The function returns the count of the lines where the confidence value is greater than 0.8. For example, if 'spam.txt' contains the following lines along with normal text getSpamLines('spam.txt') returns 2. SPAM-Confidence: 0.8945 Mary had a little lamb. SPAM-Confidence: 0.8275 SPAM-Confidence: 0.7507 The...

  • Conditional statements, loops, reading from file, user defined functions.

    # in C Project objective: Conditional statements, loops, reading from file, user defined functions.**Submit source code (prog3.c) through CanvasOne source code file(unformatted text) will be submittedHere is INCOMPLETE code to get started: prog3.cHere is input.txt file: input.txtThe file name must match the assignmentThe code should be tested and run on a Microsoft compiler before it is uploaded onto CanvasThe code must be submitted on time in order to receive credit (11:59PM on the due date)Late submissions will not be accepted or gradedAll...

  • I need this in Visual Studio C++ Write a function that count the number of vowels,...

    I need this in Visual Studio C++ Write a function that count the number of vowels, the number of consonants and the average number of letters in each word. The function accept a C-String (char array) or a string object as an argument and return the number of vowels, number of consonants and the average number of letters in each word. Problem: Requirements: . Use pointers as part of the solution Read a string from a text file. . Write...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • //Done in C please! //Any help appreciated! Write two programs to write and read from file...

    //Done in C please! //Any help appreciated! Write two programs to write and read from file the age and first and last names of people. The programs should work as follows: 1. The first program reads strings containing first and last names and saves them in a text file (this should be done with the fprintf function). The program should take the name of the file as a command line argument. The loop ends when the user enters 0, the...

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