Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task: if the character read in is a '.' (dot), ',' (comma), '?' (question mark), '-' (dash), or a ' (single quote), then it is

Task:

  • if the character read in is a '.' (dot), ',' (comma), '?' (question mark), '-' (dash), or a "'" (single quote), then it is replaced by a ' ' (space) character unless these characters appear inside a double quotation-mark enclosed substring; and,
  • if the character is not a '.' (dot), '.' (comma), '?' (question mark), '-' (dash), or a "'" (single quote), then it is always output as-is.

You program must process all input from standard input (i.e., std::cin) and write all output to standard output (i.e., std::cout). This must be done in C++.

Edit: You can consider the input as a string

Clarifications:

  • In this assignment, do not use 's ispunct() or the ispunct() found within the C++ Standard Library. Simply hard-code the checks for punctuation in your code, e.g., use a switch statement and case labels on byte.
  • If a opening double-quotation character is not closed, then output everything to the screen (to the end-of-file/error condition), i.e., don't worry that the quotation mark not being closed.
  • Do not convert double-quotation characters to whitespace.
  • If you don't know where to start, start with the following code:
#include #include // for std::noskipws using namespace std; int main() { bool is_within_double_quotes = false; char byte; while (cin >> noskipws >> byte) { // NOTE: output your bytes with cout.put(byte); // or, cout << byte; (if byte is a char) // or, cout << static_cast(byte); (if byte is not a char) #error "Write code in here to process the input and write output to std::cout." } }

Sample Program Input File:

Consider this input file a1-input.dat:

$ cat a1-input.dat This -is' ?some? text. "This i-s 'so'.me text?" "a.b-c'd?z"A.B-C'D?Z'0.1-2"3?9'4.5-6'7?"aA.bB-cC'dD?zZ $ 

Sample Program Run:

This is a sample program run:

$ ./a.out 

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

Ehs 2.0 Revolutionizing The Future Of Safety With Digital Technology

Authors: Tony Mudd

1st Edition

B0CN69B3HW, 979-8867463663

More Books

Students also viewed these Databases questions