Question

please use c++

please write down the input file information

please add comments for some codes

please do not use #include <bits/stdc++.h> we did not learn it yet

thank you

CSIT 575-Take Home Lab #11: Arrays To learn to code, compile and run a program processing characters. Assignment Plan and cod

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

_________________

// aboutComputer.txt

A computer is a device that can be instructed to carry out an
arbitrary set of arithmetic or logical operations automatically.
The ability of computers to follow a sequence of operations
called a program make computers very flexible and useful.
Since ancient times simple manual devices like the abacus
aided people in doing calculations. Early in the Industrial
Revolution, some mechanical devices were built to automate
long tedious tasks, such as guiding patterns for looms.

____________________


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

//Function Declarations
void readFile();
void makeCount(string word,int &lowerCount,int &upperCount,int &puncCount,int freq[]);
void letterFrequency(char ch,int freq[]);
void displayResults(int upperCount,int lowerCount,int spaceCount,int puncCount,int wordCount,int freq[]);
int main() {
  
   //calling the function
readFile();  

return 0;
}
//This function will read the data from the file
void readFile()
{
int upperCount=0,lowerCount=0,spaceCount=0,puncCount=0,wordCount=0;
int freq[26]={0};
string word;
//defines an input stream for the data file  
ifstream dataIn;

//Opening the input file
dataIn.open("aboutComputer.txt");
while(dataIn>>word)
{
   wordCount++;
   spaceCount++;
   makeCount(word,lowerCount,upperCount,puncCount,freq);
}
  
//Closing the intput file
dataIn.close();
  
   displayResults(upperCount,lowerCount,spaceCount-1,puncCount,wordCount,freq);
}
//This function will count no of lower,upper case letters,punctuation letters
void makeCount(string word,int &lowerCount,int &upperCount,int &puncCount,int freq[])
{
   char ch;
   for(int i=0;i<word.length();i++)
   {
       ch=word.at(i);
      
       if(islower(ch))
       {
           lowerCount++;
           letterFrequency(ch,freq);
       }
       if(isupper(ch))
       {
           letterFrequency(ch+32,freq);
           upperCount++;
       }
       if(ch=='"')
       {
           puncCount++;
       }
      
   }
}
void letterFrequency(char ch,int freq[])
{
   freq[((int) (ch) - 97)]++;
}
//This function will display the results in the output
void displayResults(int upperCount,int lowerCount,int spaceCount,int puncCount,int wordCount,int freq[])
{
   cout<<"Number of upper case letters :"<<upperCount<<endl;
   cout<<"Number of lower case letters :"<<lowerCount<<endl;
   cout<<"Number of spaces :"<<spaceCount<<endl;
   cout<<"Number of punchuation characters :"<<puncCount<<endl;
   cout<<"Total Number of words :"<<wordCount<<endl;
  
   cout<<endl;
   char ch=97;
   for(int i=0;i<26;i++)
   {
       cout<<ch<<"/"<<(char)(ch-32)<<":"<<freq[i]<<endl;
       ch++;
   }
}

___________________________

Output:

i C:\Program Files (x86)\Dev-Cpp\MinGw64bin,ReadFileCountUpperLowerPuncSpacesWordsLetter umber of upper case letters 6 umber

Add a comment
Know the answer?
Add Answer to:
please use c++ please write down the input file information please add comments for some codes...
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
  • 1. Write a python program that reads a file and prints the letters in increasing order...

    1. Write a python program that reads a file and prints the letters in increasing order of frequency. Your program should convert entire input to lower case and only counts letters a-z. Special characters or spaces should not be counted. Each letter and it's occurrences should be listed on a separate line. 2. Test and verify your program and it's output. ---Please provide a code and a screenshot of the code and output. Thank you. ----

  • Write a C program that reads characters from a text file, and recognizes the identifiers in...

    Write a C program that reads characters from a text file, and recognizes the identifiers in the text file. It ignores the rest of the characters. An identifier is a sequence of letters, digits, and underscore characters, where the first character is always a letter or an underscore character. Lower and upper case characters can be part of the identifier. The recognized identifier are copied into the output text. b. Change the C program in exercise 2, so that all...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • Programming language --> Matlab The name of a text file Outputs: (cell) An Nx2 cell array...

    Programming language --> Matlab The name of a text file Outputs: (cell) An Nx2 cell array listing words and their counts in sorted order Function Description: Have you ever seen those fancy word-clouds based on the frequency of word occurrences in some text? Well the first step of making a graphic like that is to figure out how often the words in some text occur, which is exactly what this function will do. You will count the number of occurrences...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • 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]...

  • C++ please Write a program that reads the following sentences from a file: I am Sam...

    C++ please Write a program that reads the following sentences from a file: I am Sam Sam I am That Sam I am That Sam I am I do not like that Sam I am Do you like green eggs and ham I do not like them But I do like spam! You will first have to create the text file containing the input, separate from your program. Your program should produce two output files: (i) (ii) one with the...

  • (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...

  • Question 2 Write a program that will read in a line of text up to 100...

    Question 2 Write a program that will read in a line of text up to 100 characters as string, and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by whitespace, a period, a comma, or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespace, commas, an<d periods. When...

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