In C++ code: Design and write a C++ class that reads text, binary and csv files.  The class functions: Size:      Returns the file size Name:      Returns the file name Raw:    Returns the unparsed raw data Parse:    A external function to Parse the data.  The function accepts the raw data and returns the data parsed by the function.  This type of function is called a "Call-Back Function". A Call-Back is necessary for each file as each file requires different regular expressions to parse.   Call-back.cpp #include #include #include #include using namespace std; string ToLower(string s) {     string temp;     for (char c : s)         temp.push_back(tolower(c));     temp.push_back(NULL);     return temp; } string ToUpper(string s) {     string temp;     for (char c : s)         temp.push_back(toupper(c));     temp.push_back(NULL);     return temp; } struct Append {     string operator()(string a, string b)  // function object     {         return a + b;     } }; class CallBack {     function callback;  public:     CallBack(function cb) { callback = cb; }     string useCallBack(string s) { return callback(s); } }; void embedd(string s) {     CallBack cback(ToUpper);     cout << cback.useCallBack(s) << endl; } void functional() {     string cat = "cat";     string dog = "DOG";     function fn1 = ToUpper; // ToLower;          // function     function fn2 = &ToUpper;         // function pointer     function fn3 = Append(); // function object     function fn4 = [](string s) { return s.length(); };  // lambda expression     function fn5 = plus();      // standard function object     cout << fn1(dog) << endl;     cout << fn2(cat) << endl;     cout << fn3(cat, dog) << endl;     cout << fn4(dog) << endl;     cout << fn5(123, 456) << endl; } void main() {     functional();     embedd("dog"); }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Topic Video
Question

In C++ code:

Design and write a C++ class that reads text, binary and csv files.  The class functions:

Size:      Returns the file size
Name:      Returns the file name
Raw:    Returns the unparsed raw data
Parse:    A external function to Parse the data.  The function accepts the raw data and returns the data parsed by the function.  This type of function is called a "Call-Back Function". A Call-Back is necessary for each file as each file requires different regular expressions to parse.

 

Call-back.cpp

#include <string>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

string ToLower(string s)
{
    string temp;
    for (char c : s)
        temp.push_back(tolower(c));
    temp.push_back(NULL);
    return temp;
}

string ToUpper(string s)
{
    string temp;
    for (char c : s)
        temp.push_back(toupper(c));
    temp.push_back(NULL);
    return temp;
}

struct Append
{
    string operator()(string a, string b)  // function object
    {
        return a + b;
    }
};

class CallBack
{
    function<string(string)> callback; 
public:
    CallBack(function<string(string)> cb) { callback = cb; }
    string useCallBack(string s) { return callback(s); }
};

void embedd(string s)
{
    CallBack cback(ToUpper);
    cout << cback.useCallBack(s) << endl;
}

void functional()
{
    string cat = "cat";
    string dog = "DOG";
    function<string(string)> fn1 = ToUpper; // ToLower;          // function
    function<string(string)> fn2 = &ToUpper;         // function pointer
    function<string(string, string)> fn3 = Append(); // function object
    function<int(string)> fn4 = [](string s) { return s.length(); };  // lambda expression
    function<int(int, int)> fn5 = plus<int>();      // standard function object

    cout << fn1(dog) << endl;
    cout << fn2(cat) << endl;
    cout << fn3(cat, dog) << endl;
    cout << fn4(dog) << endl;
    cout << fn5(123, 456) << endl;
}

void main()
{
    functional();
    embedd("dog");
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

If we need to put vector in Raw function, how can we do that?

 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY