Question

I need help with the creation of the pre and post conditions for each function of...

I need help with the creation of the pre and post conditions for each function of my program. Please see below.

#include <iostream>
#include <string.h>
using namespace std;
#define TOTAL_COMMANDS 7
struct command {
char name[1024];
// Store the name of the command
int *paramsCount;
// Stores the valid no. of params
char error[4096];
// Stores the valid errors
int differentParams;
// Store no. of different ways to specify params
int differentErrors; // Store no. of different ways to error can occur
char windows[1024]; // Store actual command for windows system
};
struct command* populateCommands(void);


void processCommands(char**, int, struct command*);

/* This function reads a line of words from the keyboard and puts them into array a
The size of the array is written into num
*/
void parse(char** a, int &num)
{ char c;
int i = 0, j = 0;
bool space = false; // Used to get rid of spaces in the end
bool nonempty = false; // Used to check whether the string is empty or not
cout << "dysh> " ; // Skip leading spaces
do{ c = cin.get(); }
while(c == ' ' && c != '\n'); // Now treat the main part of the line
while(c != '\n')
{
if(c == ' ')
{ // Space means new word
space = true;
a[i][j] = '\0';
i++;
j = 0;
while(c == ' ')
{
c = cin.get(); // Skip a bunch of consequent spaces
}
}
else
{ nonempty = true;
space = false;
a[i][j] = c;
j++;
c = cin.get();
}
}
a[i][j] = '\0'; // Terminate the very last word
if(!space)
num = i + 1; // User hits enter right after typing a word
else num = i; // There is a space in the end
if(!nonempty)
num = 0; // The line is empty or made of spaces only
}
  
int main()
{
int n;
// Create a dynamic two-dimensional array of characters a[30][1024]
char** a = new char*[30];
if(!a)
{
cerr << "Memory Allocation error.\n";
exit(1);
}
for(int i = 0; i < 30; i++)
{
a[i] = new char[1024];
if(!a[i])
{
cerr << "Memory allocation error.\n";
exit(1);
}
}
// Create a list of commands
command *commands = populateCommands();
do{ // Sentinel-controlled loop
parse(a, n);
processCommands(a, n, commands);
for(int i = 0; i < n; i++)
{ // Print the array
cout << "a[" << i << "] = '" << a[i] << "'" << endl;
}
cout << "# of items: " << n << endl; // Print the size of the array
} while(strcmp(a[0], "QUIT"));
// Delete the array
for(int i = 0; i < 30; i++)
{
delete [] a[i];
}
delete [] a;
return 0;
}
//Implementation to populate commands RUN, LIST, COPY, CD, SHOW, HELP, QUIT
struct command* populateCommands()
{
struct command* commands = new struct command[7];
strcpy(commands[0].name, "RUN");
strcpy(commands[1].name, "LIST");
strcpy(commands[2].name, "COPY");
strcpy(commands[3].name, "CD");
strcpy(commands[4].name, "SHOW");
strcpy(commands[5].name, "HELP");
strcpy(commands[6].name, "QUIT");
commands[0].paramsCount = new int[1];
commands[0].paramsCount[0] = 1;
strcpy(commands[0].error, "Please specify the command to execute.\n");
commands[0].differentParams = 1;
commands[0].differentErrors = 1;
strcpy(commands[0].windows, "cmd");
commands[1].paramsCount = new int[2];
commands[1].paramsCount[0] = 0;
commands[1].paramsCount[1] = 1;
strcpy(commands[1].error, "No Error.\n");
commands[1].differentParams = 2;
commands[1].differentErrors = 0;
strcpy(commands[1].windows, "dir");
commands[2].paramsCount = new int[1];
commands[2].paramsCount[0] = 1024;
strcpy(commands[2].error, "Please specify the Destination Address.\n");
commands[2].differentParams = 1024;
commands[2].differentErrors = 1;
strcpy(commands[2].windows, "copy");
commands[3].paramsCount = new int[1];
commands[3].paramsCount[0] = 1;
strcpy(commands[3].error, "Please specify the directory to change into.\n");
commands[3].differentParams = 1;
commands[3].differentErrors = 1;
strcpy(commands[3].windows, "cd");
commands[4].paramsCount = new int[1];
commands[4].paramsCount[0] = 1;
strcpy(commands[4].error, "Please specify filename to view.\n");
commands[4].differentParams = 1;
commands[4].differentErrors = 1;
strcpy(commands[4].windows, "more");
commands[5].paramsCount = new int[1];
commands[5].paramsCount[0] = 1;
strcpy(commands[5].error, "Please specify command to view help.\n");
commands[5].differentParams = 1;
commands[5].differentErrors = 1;
strcpy(commands[5].windows, "help");
commands[6].paramsCount = new int[1];
commands[6].paramsCount[0] = 1;
strcpy(commands[6].error, "No Error.\n");
commands[6].differentParams = 1;
commands[6].differentErrors = 0;
strcpy(commands[6].windows, "exit");
}
  
//
void processCommands(char** a, int num, struct command* commands)
{
if(num == 0)
{
cout << "Please enter the command.\n";
return;
}
for(int i = 0; i < TOTAL_COMMANDS; i++)
{
cout << i << commands[i].name << a[0] << "sdsd";
if(strcmp(commands[i].name, a[0]) == 0)
{
if( (num - 1) != commands[i].differentParams)
cout << commands[i].error;
else
{
char actualCommand[4096];
}
break;
}
}
return;
}

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
I need help with the creation of the pre and post conditions for each function of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • This is for a C++ program: I'm almost done with this program, I just need to...

    This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...

  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

  • Code in C++: Please help me fix the error in function: void write_account(); //function to write...

    Code in C++: Please help me fix the error in function: void write_account(); //function to write record in binary file (NOTE: I able to store data to a txt file but however the data get error when I try to add on data the second time) void display_all(); //function to display all account details (NOTE: This function is to display all the info that save account.txt which is ID, Name, and Type) void modify_account(int); //function to modify record of file...

  • I JUST NEED HELP WITH DISPLAY PART! please help! thanks in advance // This function saves...

    I JUST NEED HELP WITH DISPLAY PART! please help! thanks in advance // This function saves the array of structures to file. It is already implemented for you. // You should understand how this code works so that you know how to use it for future assignments. void save(char* fileName) { FILE* file; int i; file = fopen(fileName, "wb"); fwrite(&count, sizeof(count), 1, file); for (i = 0; i < count; i++) { fwrite(list[i].name, sizeof(list[i].name), 1, file); fwrite(list[i].class_standing, sizeof(list[i].class_standing), 1, file);...

  • Am I getting this error because i declared 'n' as an int, and then asking it...

    Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() {    int n;    double avg, sum = 0;;    string in_file, out_file;    cout << "Please enter the name of the input file: ";    cin >> in_file;   ...

  • Hi there! I need to fix the errors that this code is giving me and also...

    Hi there! I need to fix the errors that this code is giving me and also I neet to make it look better. thank you! #include <iostream> #include <windows.h> #include <ctime> #include <cstdio> #include <fstream> // file stream #include <string> #include <cstring> using namespace std; const int N=10000; int *freq =new int [N]; int *duration=new int [N]; char const*filename="filename.txt"; int songLength(140); char MENU(); // SHOWS USER CHOICE void execute(const char command); void About(); void Save( int freq[],int duration[],int songLength); void...

  • C++ language I need to update this code with the following: ask the user for how...

    C++ language I need to update this code with the following: ask the user for how many structures they would like. Once you get the number, allocate an array of pointers. Once they have been created, proceed to loop through and get the data as usual, and display it back to the screen. struct record {    int age;    string name; }; int check(record r[], int n, string nm) {    for (int i = 0; i < n;...

  • Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */...

    Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */ struct myWord{    char Word[21];    int Length; }; int tokenizeLine(char line[], struct myWord wordList[]); void printList(struct myWord wordList[], int size); void sortList(struct myWord wordList[], int size); /** * main function */ int main() {    struct myWord wordList[20];    char line[100];    printf("Enter an English Sentence:\n");    gets(line);    int size = tokenizeLine(line, wordList);    printf("\n");    printf("Unsorted word list.\n");    printList(wordList, size);...

  • (Coding done in c++, Virtual Studio) Having a problem with the line trying to compare the...

    (Coding done in c++, Virtual Studio) Having a problem with the line trying to compare the date of birth.            **fall.sort(compare_DOB); //Here lies your error** #include <fstream> #include <iostream> #include <string> #include <list> #include <cctype> using namespace std; const char THIS_TERM[] = "fall.txt"; const string HEADER = "\nWhat do you want to do ?\n\n" "\t. Add a new friend name and DOB ? \n" "\t. Edit/Erase a friend record ? \n" "\t. Sort a Friend's record ? \n"...

  • #include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”,...

    #include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”, “Hanenburg”, “Rhoderick”, “Pearce”, “Raymond”, “Kamphuis”}; for(int i=0; i<8;i++){ for(int j=0; j<9; j++){ if(strcmp(array[j],array[j+1])>0){ char temp[20]; strcpy(temp,array[j]); strcpy(array[j],array[j+1]); strcpy(array[j+1],temp); } } } printf(“---------File Names---------\n”); for(inti=0; i<9; i++){ printf(“\t%s\n”,array[i]); } printf(-------5 Largest Files according to sorting----\n”); for(int i=0;i>=5;i--) { printf(“\t%s\n”,array[i]); } return0; } Consider the "sort" program (using with void* parameters in the bubblesort function) from the week 10 "sort void" lecture. Modify it as follows...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT