[SOLVED] 代写 CS 442/542 Homework 2
 I/O Manager

30 $

File Name: 代写_CS_442/542_Homework_2
_I/O_Manager.zip
File Size: 405.06 KB

SKU: 7469272330 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


CS 442/542 Homework 2
 I/O Manager
• Implement the I/O manager described in the following header file. This module will provide the sole access point for reading characters from the source program.
• “Due” Monday September 30

I/O Manager General Functionality
• Open source File
• Open a listing file if a listing file name is provided
• Close file(s)
• Return the next source character
• Write a indicator marker at a specified column – Used to mark the position of an error
• Write a message
– Used to write an error message
• Return the current line number
• Return the current column number

#include #include
#define MAXLINE 1024
IOMngr.h
Int OpenFiles(const char * ASourceName, const char * AListingName);
void CloseFiles();
char GetSourceChar();
void WriteIndicator(int AColumn);
void WriteMessage(const char * AMessage); int GetCurrentLine();
int GetCurrentColumn();

I/O Manager
• bool OpenFiles(const char * ASourceName, const char * AListingName);
• Open the source file whose name is given in
ASourceName
– You can assume ASourceName is assigned a legal
char* (i.e. a string)
• If ALisitingName is not NULL open the listing file whose name is given in AListingName
– If AListingName is NULL, the output goes to stdout
• Return 1 if the file open(s) were successful, otherwise return 0

I/O Manager • void CloseFiles()
• Close the source file and the listing file if one was created

I/O Manager
• char GetSourceChar()
• Return the next source char
• This function is also responsible for echoing the lines in the source file to the listing file (if one exists)
• The lines in the listing file should be numbered
• Return EOF when the end of the source file is reached

I/O Manager
• void WriteIndicator(int Acolumn)
• Write a line containing a single ‘^’ character in the indicated column
• If there is no listing file then the current line should be echoed to stdout the first time (for that line) that WriteIndicator or WriteMessage is called.

I/O Manager
• void WriteMessage(const char * Amessage) • Write the message on a separate line

Write Example with Listing File
1. float y; 2. floam x;
^
Unexpected character
3. y = 10;
4. x = 2*y@3;
^
Variable not declared
^ Unexpected character

Write Example without a Listing File
2. floam x; ^
Unexpected character 4. x = 2*y@3;
^
Variable not declared
^ Unexpected character

I/O Manager • int GetCurrentLine()
– Return the current line number
• int GetCurrentColumn()
– Return the current column number in the
current line.

I/O Manager
• Because the line must be echoed before error indicators and messages the implementation must buffer the current line.
• That is IOMngr should have an array of characters that hold the current line. When the last character of the current line is returned GetSourceChar will need to read another line

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 CS 442/542 Homework 2
 I/O Manager
30 $