Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you fix the error messages... Error message: In function 'std::vector > splitedString(std::string, char)': [Error] variable 'std::stringstream ss' has initializer but incomplete type [Error] expected

Can you fix the error messages... Error message:

In function 'std::vector > splitedString(std::string, char)': [Error] variable 'std::stringstream ss' has initializer but incomplete type [Error] expected initializer before ':' token [Error] 'splittedstr' was not declared in this scope [Error] expected ';' before ':' token [Error] expected primary-expression before ':' token At global scope: [Error] expected unqualified-id before 'public'

I've added the question for the program if you want to refer to any instructions.

#include

#include

#include

using namespace std; void parseLine(char * B[], int & m) { char c; char * tempnewStr = new char[40]; int total = 0; m = 0; while (true) { c = cin.get(); if (c == ' ') { if (total != 0) { tempnewStr[total] = 0; B[m++] = tempnewStr; } break; } else { if (c == ' ') { if (total != 0) { tempnewStr[total] = 0; B[m++] = tempnewStr; total = 0; tempnewStr = new char[40]; } } else { tempnewStr[total++] = c; } } } } int main() { char * B[40]; int m; parseLine(B, m); for (int i = 0; i cout } return 0; }

vector splitedString(string strSplit, char chdelim) { stringstream ss(strSplit); string item; vector splittedstr: while (getline(ss, item, chdelim)) { splittedstr.push_back(item); } return splittedstr: }

public bool GetCommand(string command) { char spacedelim = " "; public vector strsinglevector = { LIST, HELP, QUIT, RUN executable - file, LIST directory, COPY old - filename new - filename, CD directory, SHOW file }; vector strinputvecor = splitedString(command, spacedelim); if (strvec.len() >= 0) { char spacedelim = " "; for (int i = 0: strsinglevector.len(): i++) { vector strsplitvec = splitedString(strsinglevector[i], spacedelim); if (strinputvecor.len() == strsplitvecor.len()) { for (int j = 0; j => if (strinputvecor[j] != strsplitvecor[j]) return FALSE } return TRUE; } else return FALSE } } int main() { system("dir C:\\");

string keyword; cout cin >> keyword;

bool bval = GetCommand(keyword) if (bval == TRUE) cout else cout return 0; }

Question

In Phase 1, you created a program that reads a line of input from the user and creates an array of strings containing the strings in the line of input and counts the number of strings.

For the second phase of your final project, you will provide the functionality to yourcommand interpreter. In this phase, you will add the functionality for command recognition and implement the HELP, QUIT, COPY, LIST, CD, SHOW and RUN functions.

Recall that some commands have no arguments, some have one and some have two and so your interface must handle a variable number of parameters.

Your command interpreter should do the following.

  • Display a prompt for the user.
  • Read the user's input.
  • Determine if the entered command is valid
  • If it is valid, execute it and then re-display the prompt.
  • If the command is not valid, display aspecific, appropriateerror message and re-display the prompt. Be sure that your command interpreter differentiates between different errors that render a command invalid.
  • Continue until the user enters the command QUIT.

If the entered command is invalid or if the number of parameters to that command is incorrect your program will print the error message and then redisplay the prompt.

If the command is valid, your program will carry out the command.

Here are specifics for each of the commands.

HELP

List the valid commands and their proper syntax. E.g.

You rang? > HELP

The valid commands are:

RUN executable-file

LIST

LIST directory

COPY old-filename new-filename

HELP

QUIT

SHOWfile

Simply prints the given file to standard output.

QUIT

Terminates the session. E.g.

You rang? > QUIT

Goodbye.

COPYold-filenamenew-filename

Creates a copy of the source file.

When you implement the COPY command, you should verify that the source file exists and is readable. If the destination file exists you should ask the user if they wish to overwrite it before opening it to write. Once both files have been successfully opened simple read the characters on at a time from the source file and write them to the destination file.

CDdirectory

Changes the working directory to the argument if it is a valid directory name.

Your shell should display a message indicating the new directory upon successful execution o the command. You will need to use thechdirandgetcwdcommands as illustrated in the sample program chDir.cpp

LIST

Displays the files in a directory

Your LIST command takes either no arguments or one argument. The contents of the directory specified by the argument should be listed or in the case of no argument, the contents of the current directory should be listed. The syntax is:

LIST

or

LISTdirectory

The algorithm for LIST is reasonable simple.

Open the directory

Read the first entry in the directory

While not all of the directory has been displayed

Display the entry just read

Read the next entry

Close the directory

Working with directories is a relatively low-level operation. To access the contents of a directory we need to use a collection of system calls declared in the header file.

opendir(dname) is passed a c-stringdnameand returns a pointer to the directorydname(type DIR*) if it is found and NULL otherwise.

readdir(dPointer) is passed a DIR* and returns a pointer to the next entry in the directory linked todPointeror NULL if there are no more entries.

closedir(dPointer) closes the link to the directory

The directory entries are of typedirent, a structure that contains the memberd_name, which contains the name of the current entry.

Refer to chapter 17 of your UNIX text for more on programming with directories.

RUNexecutable-file

Executes the given program.

Your RUN command takes one argument. The executable file specified by the argument should be run and when finished, the prompt displayed. The syntax is:

RUNexecutable-file

The algorithm for RUN would be as follows.

Fork a child process.

Execute the program in the child process.

Have the parent wait until the child is finished before continuing.

This will require the following library functions

fork( ) creates a child process and returns the PID of the child process to the parent. The child gets 0.

execl(list of cstrings) executes a program in the current process the first argument is the path to the executable file, the remaining arguments are the strings of the command line

wait( ) causes the parent to block until the child finishes

Refer to chapter 18 of your UNIX text for more extensive discussion of these concepts.

As always, your program should:

  • Contain carefully worded pre and post conditions for all functions.
  • Be readable with appropriate documentation and formatting.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Core Concepts Of Accounting Information Systems

Authors: Nancy A. Bagranoff, Mark G. Simkin, Carolyn Strand Norman

11th Edition

9780470507025, 0470507020

Students also viewed these Programming questions