CS 280 Spring 2021 Recitation Assignment 4 February 15, 2021 Due Date: Wednesday, February 17, 2021, 23:59 Total Points: 6 Write a C++ program that creates a simple directory for the occurrences of...

1 answer below »
C++ assigment


CS 280 Spring 2021 Recitation Assignment 4 February 15, 2021 Due Date: Wednesday, February 17, 2021, 23:59 Total Points: 6 Write a C++ program that creates a simple directory for the occurrences of printable characters read from an input file. The program should read from a file name specified in the command line as an argument, However, if no file name is provided, the program should print on a new line "No file is found", and exit. If the file cannot be opened, print on a new line "File cannot be opened: ", followed by the file name, and exit. The program should read from the file words until the end of file. If the input file is empty, print out on a new line the message "File is empty." and then exit. A word is defined as a contiguous number of non-whitespace characters separated by whitespace. The program should keep a record of the number of occurrences of each letter, decimal digit (0- 9), and any non-alphanumeric characters (e.g., ‘.’, ‘,’, ‘@’, etc.) in a directory built using the

container. In order to avoid counting uppercase and lowercase letters, all letters should be converted to uppercase. After all input has been processed, the program should • Print each decimal digit and letter that was seen the largest number of times on a line by itself and the number of times it was seen in the file. • Print each printable character read from the file and the number of times it was seen. The character should be printed in order. • Print the number of non-alphanumeric characters that were seen in the file. For example, with an input file of the following contents: The results are as shown below: Digits of Largest number of occurrences: 0: 8 Digits of Largest number of occurrences: 7: 8 Letters of Largest number of occurrences: E: 43 An International Standard Book Number (ISBN) is a code of 10 characters, referred to as ISBN-10, separated by dashes such as 0-7637-0798-8. An ISBN-10 consists of four parts: a group code, a publisher code, a code that uniquely identifies the book among those published by a particular publisher, and a check character. The check character is used to validate an ISBN. For the ISBN 0-7637-0798-8, the group code is 0, which identifies the book as one from an English-speaking country. The publisher code 7637 is for "Jones and Bartlett Publishers". List of characters seen in the file and their number of occurrences: ": 2 (: 1 ): 1 ,: 7 -: 9 .: 5 0: 8 1: 3 3: 3 6: 3 7: 8 8: 4 9: 2 :: 1 A: 37 B: 17 C: 21 D: 18 E: 43 F: 9 G: 5 H: 23 I: 29 J: 1 K: 6 L: 11 M: 3 N: 26 O: 29 P: 11 Q: 1 R: 28 S: 35 T: 28 U: 15 V: 1 W: 1 Y: 4 Number of non-alphanumeric characters seen in the file: 7 Hints: 1. Use functions such as: isdigit(), isalpha(), isspace(), and toupper(). 2. Include the

container. 3. Create a directory using

to map a character to an integer. 4. See the recitation class slides for the use of the

methods, or refer to the online documentation for

at: www.cplusplus.com/reference/map/map/ 5. There are 5 test cases. These are: a. Case 1: Error checking of opening a file (non-existent file infile) b. Case 2: Empty File (infile1) c. Case 3: Input with All Letters (infile2) d. Case 4: Input with All Digits (infile3) e. Case 5: Input with Mixed Printable characters 6. If you want to look at the input for one of the test cases, use the linux "cat" command. The cases are in the directory $LIB/public/recitationSP21\RA4. You can, for example, look at myfile3 by saying "cat $LIB/public/recitationSP21/infile4", and you can look at the expected output by saying "cat $LIB/public/recitationSP21/case5.correct". Submission Guidelines 1. Please name your file as “HWx_firstname_lastname.cpp”. Where, “firstname” and “lastname” refer to your first and last names, “x” refers to the recitation assignment number (e.g., 1, 2, etc). Uploading and submission of your program is via Vocareum. Follow the link of Recitation Assignment 3 on Canvas in the Modules or Assignments pages. 2. Submissions after the due date are accepted with a fixed penalty of 25%. No submission is accepted after Saturday 11:59 pm, February 20, 2021. Grading Table Testing Cases Points Case 1: Error checking of opening a file 1.0 Case 2: Empty File 1.0 Case 3: Input with All Letters 1.0 Case 4: Input with All Digits 1.0 Case 5: Input with Mixed Printable characters 1.0 Compiles Successfully 1.0 Total 6 http://www.cplusplus.com/reference/map/map/




Answered Same DayFeb 17, 2021

Answer To: CS 280 Spring 2021 Recitation Assignment 4 February 15, 2021 Due Date: Wednesday, February 17, 2021,...

Sonu answered on Feb 18 2021
141 Votes
#include
using namespace std;
int main(int argc, char **argv)
{
    // if no argume
nt is passed in terminal
if(argc == 1){
cout<<"No file is found";
return 0;
}
//opening the file
    ifstream file;
file.open(argv[1]);
string data;
//if file opening is failed
if(!file.is_open()){
    cout<<"File cannot be opened: "<     return 0;
    }
    //storing file data in map
map my_map;
int max_count_digit = 0;
int max_count_alpha = 0;
int nonalphanum = 0;
while...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here