Pseudo Code Generator

File Transformation Pseudo Code

This pseudo code outlines a program that reads character input, applies transformations via an abstract class, and writes results to a file, including functionality for displaying the file contents to standard output.


Empty image or helper icon

Prompt

// Thomas Kelly Programming 3, Lab A, 8/24/2024
//

#include 
#include 

using namespace std;

class Xlate {   // parent abstract class Xlate

private:

public:

    virtual char transform(char byte) = 0; // pure virtual transform function of type character 

    virtual void doFilter(istream& in, ostream& out) {

        char byte;

        while (in.get(byte))
        {

            out.put(transform(byte)); // puts value of byte through parameter of transform function (loop runs to store characters)

        }


    }

};


class Asis : public Xlate { // Creates a subclass Asis that inherits the accessible values of parent class Xlate

private:

public:

    char transform(char byte) override
    {

        return byte; // returns duplicate of what is given

    }

};



int main(int argc, char* argv[])
{

    string fileName; 

    cout << "Enter File Name.\n";
    cin >> fileName; // User inputs the name of the file on their computer they want to enter text into
    ofstream input(fileName); // This line puts the input from the user and attempts to open it with the .open function

    Asis x; // x is an instance of the Asis class (this object allows me to call the function doFilter within the parent class)

    if (input.is_open())
    {

        cout << "Enter Data Into Selected File. (CTRL Z to end stream)\n"; // asks the user input for what will display in the file

        x.doFilter(cin, input); //   
        cout.flush();

        input.close(); // closes file

    }

    else
    {
        cout << "File Not Opened (May Have Been Entered Incorrectly)\n";

        return 1; // terminates terminal window

    }

    ifstream output(fileName); // opens the file again

    cout << "Text Sucessfully Inputted to File.";
    x.doFilter(output, cout);

    output.close(); // closes the file 

    return 0;

}

Answer

Pseudo Code for File Transformation Program

Overview

This pseudo code represents a program that reads characters from standard input, applies a transformation via an abstract class mechanism, and writes the result to a specified file. It also reads from the file to display its contents to the standard output.

Pseudo Code Structure

Classes and Method Definitions

  1. Abstract Class Definition

    • Define an abstract class Xlate
      • Method: transform(byte: char) -> char (pure virtual)
      • Method: doFilter(in: InputStream, out: OutputStream)
        • Initialize byte as char
        • While there are bytes to read from in
          • Apply transform to byte and write to out
  2. Subclass Definition

    • Define the class Asis which inherits from Xlate
      • Implement transform(byte: char) -> char
        • Return byte as is

Main Program Logic

  1. Main Function

    • Initialize fileName as string
    • Prompt user for fileName
    • Attempt to open fileName for writing
    • Create instance of Asis class x
  2. File Handling

    • If file is successfully opened:

      • Prompt for user input (data entry)
      • Call doFilter method passing standard input and opened file
      • Flush output stream
      • Close the file
    • Else, display "File Not Opened" and terminate program

  3. Output File Reading

    • Open fileName for reading
    • Display confirmation message
    • Call doFilter method passing output file and standard output
    • Close output file

Pseudo Code

CLASS Xlate
    FUNCTION transform(byte: CHAR) -> CHAR // pure virtual function

    FUNCTION doFilter(in: InputStream, out: OutputStream)
        DECLARE byte AS CHAR
        WHILE in has more bytes
            READ byte FROM in
            WRITE transform(byte) TO out
        END WHILE
    END FUNCTION
END CLASS

CLASS Asis INHERITS Xlate
    FUNCTION transform(byte: CHAR) -> CHAR
        RETURN byte // return input character unmodified
    END FUNCTION
END CLASS

FUNCTION main()
    DECLARE fileName AS STRING

    PRINT "Enter File Name."
    READ fileName // user input for file name
    OPEN fileName FOR WRITE AS inputFile

    DECLARE x AS INSTANCE OF Asis

    IF inputFile is OPEN
        PRINT "Enter Data Into Selected File. (CTRL Z to end stream)"
        CALL x.doFilter(STANDARD_INPUT, inputFile)
        FLUSH output
        CLOSE inputFile
    ELSE
        PRINT "File Not Opened (May Have Been Entered Incorrectly)"
        RETURN 1 // terminate program
    END IF

    OPEN fileName FOR READ AS outputFile
    PRINT "Text Successfully Inputted to File."
    CALL x.doFilter(outputFile, STANDARD_OUTPUT)
    CLOSE outputFile

    RETURN 0
END FUNCTION

Key Points

  • The program utilizes class inheritance and abstract methods for transforming data.
  • User interaction is emphasized for both file name input and data entry.
  • Error handling is included for file operations.
  • The main logic is structured to ensure clarity and separation of responsibilities between file handling and data transformation.

This structured approach makes the underlying logic easily understandable for individuals who may be unfamiliar with specific programming language syntax or concepts.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This pseudo code outlines a program that reads character input, applies transformations via an abstract class, and writes results to a file, including functionality for displaying the file contents to standard output.