Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My Current State Diagram: I am having issues with the bottom left state NEXT_WHOLE due to two transitions out of that state which is illegal

image text in transcribed

image text in transcribed

image text in transcribed

My Current State Diagram: I am having issues with the bottom left state "NEXT_WHOLE" due to two transitions out of that state which is illegal so im trying to figure that out. But maybe the code you provide will help me wrap my head around that as well. Currently i got the open file function good to go but im having issues with Detect Floats function, thanks for all your help. Diagram, Header File, Driver File, and Test Text File Below.

image text in transcribed

INSTRUCTOR SUPPLIED HEADER FILE:

#ifndef C2A5E4_STATUSCODE_DRIVER_H #define C2A5E4_STATUSCODE_DRIVER_H

// The following enum defines the status codes returned by the DetectFloats // function. enum StatusCode {FAIL = -1, FLOAT, DOUBLE, L_DOUBLE};

#endif

INSTRUCTOR SUPPLIED DRIVER FILE:

#define INSTRUCTOR_FILE #ifdef INSTRUCTOR_FILE

#include #include #include #include using namespace std;

#include "C2A5E4_StatusCode-Driver.h"

const char * const FILENAME = "TestFile5.txt";

void OpenFile(const char *fileName, ifstream &inFile); StatusCode DetectFloats(const char *chPtr);

int main() { const int BUFSIZE = 128; // input string buffer size const int SAFEBUF = BUFSIZE - 1; // limit input string char buf[BUFSIZE]; // input buffer ifstream inFile;

OpenFile(FILENAME, inFile);

// Get one string at a time and pass it to the parser function. for (int stringNo = 1; inFile >> setw(SAFEBUF) >> buf; ++stringNo) { cout = 2 && stringNo 7) cout 14) cout 19) cout

inFile.close(); return EXIT_SUCCESS; } #endif

TEXT FILE TO TEST:

ZZZZZZZ 12.35F 6E6f 6e-6f .29F 1.e-35f 456.2E-0F 0. .0 0.0 3.0e0 0.0E-300 0.0e+0 0e-0 29.28L 554e0l 0E0L 2e+2L 001.100E-001L 0x15.920p-0f 0X.3P6F 0xa.bCDP20f 0X6Ab.CDep+591f 0xEF.p-98F 0X3P90F 0x015.020p0 0X.00P6 0xab.CDp20 0x6Ab.CDep+59 0xF.p-98 0XAP23 0X396P-78 0XFFFFp0L 0X.00P-426l 0xbb.122bb3p-20l 0x2p2L 0x0.p-98L 0o17.26e-89f 0O.3E6F 0o7.120f 0O.5e+591f 0o0.e-98F 0O3E90F 0o15. 0O0. 0o.47e20 0o6.e+59 0o3.e-98 0O2E3 0O316E-78 0O.0L 0O0E0L 0o26.75e-99l 0o2e2l 0O0.e-98L -2.3 +6.90 +4.5L -0x5.4p2F +0xF.4p-2 0xL.4p-2 -0o5.4e2L +0o7.4e-2 0o7.8e2F 0o1.9 3.3FF 0o1.1LL 0x1.1p0LL 3.3e+44+3F 0o3.3e+44F+ 0x3.3p+44F+ 0o1.1LL 0x1.1p0LL 3.3e+44F+ 0x3.3p+44F+ 7 0 0L 0F 0 0x0L 0o0F 0u 6.5L5L 0x6.5L5L 0o6.5L5L 6.5e3e3 0o6.5e3e3 0x6.5p3p3 0x8Pf-0 0x8e-0 0o8e-0 24.6FL x9.6 o2.3 6e 985L 68.88Le6 22.eL .e+8 5.77L6 2f2e 38.9E 6.2F6 6e+ 5.7E- 2.3-5 18.4E+0LL 4E+0F- 69.5E+-8

CZASE4 (5 points - C++ Program) Exclude any existing source code files that may already be in your IDE project and add two new ones, naming them C2A5E4_OpenFile.cpp and C2A5E4_DetectFloats.cpp. Also add instructor-supplied source code files C2A5E4_StatusCode-Driver.h and C2A5E4_main-Driver.cpp. Do not write a main function! main already exists in the instructor-supplied implementation file and it will use the code you write. statuscode is an enumeration type consisting of members FAIL, FLOAT, DOUBLE, and L_DOUBLE and is defined in instructor-supplied header file C2A5E4_StatusCode-Driver.h Any file that uses this enumeration type must include this header file using #include. File C2A5E4_OpenFile.cpp must contain a function named OpenFile. OpenFile syntax: void openFile(const char *filename, ifstream &infile); Parameters: fileName - a pointer to the name of a file to be opened inFile - a reference to the ifstream object to be used to open the file Synopsis: Opens the file named in filename in the read-only text mode using the inFile object. If the open fails an error message is output to cerr and the program is terminated with an error exit code. The error message must mention the name of the failing file. Return: void if the open succeeds; otherwise, the function does not return. File C2A5E4_DetectFloats.cpp must contain a function named DetectFloats. DetectFloats syntax: StatusCode DetectFloats(const char *chptr); Parameters: chPtr - a pointer to the first character of a string to be analyzed Synopsis: Analyzes the string in chptr and determines if it represents a syntactically legal decimal floating literal, and if so, its type (but not its value) Return: one of the following statusCode enumerations representing the result of the string analysis: FAIL, FLOAT, DOUBLE, or L_DOUBLE *** IMPORTANT *** No credit will be given if the directions below are not followed, even if your code produces the correct results. The DetectFloats function: 1. must exactly implement every state and transition in the previous exercise's state diagram. 2. must only contain one loop statement, and it must contain a switch statement with a case for each diagrammed state. Those case names must exactly match the diagram's state names. (Code within each case may use switch statements and/or if/else statements, as you prefer.) 3. must make all transition decisions based only upon the current character and the current state. Looking backward/forward at a previousext character or state is not permitted. 4. must use at least 2 but no more than 3 variables, but only as follows: a. required - formal parameter chptr b. required - a state variable c. OPTIONAL - a variable that indicates the kind of item the current character represents, such as a digit, a radix point, a sign, a suffix, etc. I did not do this, but you are welcome to. Test your program with instructor-supplied data file TestFile5.txt, which must be placed in the program's "working directory". However, do not assume your program works correctly based strictly upon the results with this file. The test strings it contains do not represent all possible character combinations and your program could parse them correctly while still containing one or more significant bugs. Submitting your solution Send all four source code files to the assignment checker with the subject line C2A5E4_ID, where ID is your 9-character UCSD student ID. See the course document titled "How to Prepare and Submit Assignments" for additional exercise formatting, submission, and assignment checker requirements. Hints: Each state represents a new character to be examined. When you are ready to return out of the state machine function do not go to another state, but instead immediately return an appropriate status value. Do not use a separate variable to indicate a potential type float or type long double. Instead, use different states to differentiate these findings ENTER FAIL START FAIL DIGIT POINT FAIL DIGIT WHOLE NO WHOLE POINT DIGIT Ele DOUBLE EXPONENT FRACT Ele DIGIT FAIL FAIL SIGN DIGIT F/f L1 NEXT WHOLE WHOLE FLOAT DIGIT F/f L_DOUBLE FAIL FLOAT FAIL WHOLE LONG FAIL L/1 DOUBLE CZASE4 (5 points - C++ Program) Exclude any existing source code files that may already be in your IDE project and add two new ones, naming them C2A5E4_OpenFile.cpp and C2A5E4_DetectFloats.cpp. Also add instructor-supplied source code files C2A5E4_StatusCode-Driver.h and C2A5E4_main-Driver.cpp. Do not write a main function! main already exists in the instructor-supplied implementation file and it will use the code you write. statuscode is an enumeration type consisting of members FAIL, FLOAT, DOUBLE, and L_DOUBLE and is defined in instructor-supplied header file C2A5E4_StatusCode-Driver.h Any file that uses this enumeration type must include this header file using #include. File C2A5E4_OpenFile.cpp must contain a function named OpenFile. OpenFile syntax: void openFile(const char *filename, ifstream &infile); Parameters: fileName - a pointer to the name of a file to be opened inFile - a reference to the ifstream object to be used to open the file Synopsis: Opens the file named in filename in the read-only text mode using the inFile object. If the open fails an error message is output to cerr and the program is terminated with an error exit code. The error message must mention the name of the failing file. Return: void if the open succeeds; otherwise, the function does not return. File C2A5E4_DetectFloats.cpp must contain a function named DetectFloats. DetectFloats syntax: StatusCode DetectFloats(const char *chptr); Parameters: chPtr - a pointer to the first character of a string to be analyzed Synopsis: Analyzes the string in chptr and determines if it represents a syntactically legal decimal floating literal, and if so, its type (but not its value) Return: one of the following statusCode enumerations representing the result of the string analysis: FAIL, FLOAT, DOUBLE, or L_DOUBLE *** IMPORTANT *** No credit will be given if the directions below are not followed, even if your code produces the correct results. The DetectFloats function: 1. must exactly implement every state and transition in the previous exercise's state diagram. 2. must only contain one loop statement, and it must contain a switch statement with a case for each diagrammed state. Those case names must exactly match the diagram's state names. (Code within each case may use switch statements and/or if/else statements, as you prefer.) 3. must make all transition decisions based only upon the current character and the current state. Looking backward/forward at a previousext character or state is not permitted. 4. must use at least 2 but no more than 3 variables, but only as follows: a. required - formal parameter chptr b. required - a state variable c. OPTIONAL - a variable that indicates the kind of item the current character represents, such as a digit, a radix point, a sign, a suffix, etc. I did not do this, but you are welcome to. Test your program with instructor-supplied data file TestFile5.txt, which must be placed in the program's "working directory". However, do not assume your program works correctly based strictly upon the results with this file. The test strings it contains do not represent all possible character combinations and your program could parse them correctly while still containing one or more significant bugs. Submitting your solution Send all four source code files to the assignment checker with the subject line C2A5E4_ID, where ID is your 9-character UCSD student ID. See the course document titled "How to Prepare and Submit Assignments" for additional exercise formatting, submission, and assignment checker requirements. Hints: Each state represents a new character to be examined. When you are ready to return out of the state machine function do not go to another state, but instead immediately return an appropriate status value. Do not use a separate variable to indicate a potential type float or type long double. Instead, use different states to differentiate these findings ENTER FAIL START FAIL DIGIT POINT FAIL DIGIT WHOLE NO WHOLE POINT DIGIT Ele DOUBLE EXPONENT FRACT Ele DIGIT FAIL FAIL SIGN DIGIT F/f L1 NEXT WHOLE WHOLE FLOAT DIGIT F/f L_DOUBLE FAIL FLOAT FAIL WHOLE LONG FAIL L/1 DOUBLE

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

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions

Question

=+ Why do we have markets and, according to economists,

Answered: 1 week ago

Question

1. Which is the most abundant gas presented in the atmosphere?

Answered: 1 week ago