Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone fix this code please? #include #include #include #include #include #include using namespace std; bool emptyFile(ifstream& pFile) { return pFile.peek() == std::ifstream::traits_type::eof(); } void

Can someone fix this code please?

#include #include #include #include #include #include using namespace std;

bool emptyFile(ifstream& pFile) { return pFile.peek() == std::ifstream::traits_type::eof(); }

void displayCharactersWithOccurrences(map& m) { vector > v;

for (auto p : m) { v.push_back(p); }

sort(v.begin(), v.end());

for (auto x : v) { cout

}

int main() {

map ocr; string fileName, temp;

cin >> fileName;

ifstream f; f.open(fileName);

if (f.fail()) cout

while (!f.eof()) { getline(f, temp); for (char s: temp) { if (isalnum(s)) { if (isalpha(s)) ocr[toupper(s)]++; else ocr[s]++; } else if (!isspace(s)) { ocr[s]++; non_alnum++; } } }

for (char i = '0'; i

for (char i = '0'; i

for (char c = 'A'; c

cout

displayCharactersWithOccurrences(ocr);

cout

}

return 0; } image text in transcribed

image text in transcribed

Testing files

infile (it should print out file cannot be opened.)

file1 (this is an empty file)

file2

3456 1025 1234 45 4321 125 278 1025

file3

Prior to the launch of new technologies we hear of the benefits these latest developments will bring. As the latest innovations become integrated with, and form the infrastructure of, everyday living, we begin to experience some less positive aspects. Clearly, computer technology brings both benefits and disadvantages - the degree to which either has an impact on individuals and their ability to live a "good life"^ is the degree to which ethics is relevant to computing. A number of ethical issues have been discussed and debated over the last twenty years or so under the broad category of "computer ethics". This rather loose term has been criticised for placing ethics - a uniquely human characteristic - onto computers. Despite early predictions in Artificial Intelligence we are still far from being able to ascribe a moral viewpoint to mechanical devices. If, however, we talk about the ethics of computing we are talking about the use of computers - thus placing the moral perspective (and consequently the moral responsibility) firmly in the hands of computing professionals and the users.

file4

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".

image text in transcribed

CS 280 Spring 2021 Recitation Assignment 4 February 15, 2021 Due Date: Wednesday, February 17, 2021, 23:59 Total Points: 0 Write a Ch 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, il no file name is provided, the program should print on a new line "No lile is kourd', and exit. If the file cannot be opened, peint 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 enpty, print out on a new line the message "File is empty." and then exit, 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 eller, decimal digit (0- 9), and any non-alphanumeric characters (eg,',7,'@", etc.) in a directory huilt using the to mp a character to an integer. 4. See the recitation class slides for the use of the Cap> methods, or refer to the online documentation for nap al: www.cplusplus.comrelerence mapa S. There are 5 test cases. These are: il Case 1: For checking of opening a file (non-existent file infile) b. Casc 2: Empty Filc infill) C. Case 3: Input with All Letters (infile) d. Case 4: Input with All Digits (Infiles) c. Casc S. Input with Mixed Printable characters 1: 6: 3 7: 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 recitationSP21R.A4. You can, for example, kick at myfile3 by saying "cal $LIB public recitation SP21/inlilol', and you can look at the expected output by saying "eat SLID/public/recitationsr21/case5.correct". 2: 37 3:17 C: 21 D: 28 T: 9 G: 5 H: 23 I: 29 Submission Guidelines 1. Please mame your file as "HWx_firstnamne_lastname.cpp". Where. "firstaine" and "lastname" rcfer to your first and last names, "x" refers to the recitation assignment number (C..., 1, 2, etc). Uploading and submission of your program is via Vocureum. Follow the link of Recitation Assignment 3 on Canvas in the Moduks 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. L: 11 M: 3 N: 26 0: 29 P: 11 Grading Table Points 1.0 L.O L.O 2:28 S: 35 T: 28 U: 25 Testing Cases Case 1: Derce decking of opening a filo CN2: Emply Filo Case 3: Input with All Lelles Case 4: Input with All lagi Case 5: Input with Mixed Printable characters Carlis Skully Total 1.0 L.O LO 6 Y: 4 Number of non-alphanumeric characters aeen in the file: 7 SUMMARY: RESULT: compiles [ 1 / 1] RESULT: cantopen [ 1 / 1] RESULT: empty [ 0 / 1 ] RESULT: allletters [ 0 | 1 ] RESULT: alldigits [ 0 /i] RESULT: mixed [ 0 / 1] TOTAL SCORE 2 out of 6 ccc_v1_w_e5429_17437@runweb7:-$

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data And Hadoop Fundamentals Tools And Techniques For Data Driven Success

Authors: Mayank Bhushan

2nd Edition

9355516665, 978-9355516664

More Books

Students also viewed these Databases questions

Question

1. Describe the power of nonverbal communication

Answered: 1 week ago