Build an interpreter that allows users to enter two vectors of dimension 3 or less. The interpreter displays the sum, dot product, and equality of these vectors and the cycle repeats:
enter two vectors: (1 -2.3 4) (5 3 -1)
( 1 -2.3 4 ) + ( 5 3 -1 ) = ( 6 0.7 3 )
( 1 -2.3 4 ) * ( 5 3 -1 ) = -5.9
( 1 -2.3 4 ) == ( 5 3 -1 ) = false
enter two vectors: (2 2 2) (2 2 2)
( 2 2 2 ) + ( 2 2 2 ) = ( 4 4 4 )
( 2 2 2 ) * ( 2 2 2 ) = 12
( 2 2 2 ) == ( 2 2 2 ) = true
enter two vectors: (1 2 3) (4 5 6]
bad input
enter two vectors: (1 2 3) (4 5)
(1 2 3) + (4 5 0) = (5 7 3)
(1 2 3) * (4 5 0) = 14
(1 2 3) == (4 5 0) = false
enter two vectors: quit
bye
You should overload the following operators:
operator<<
operator>>
operator[]
operator+
operator*
Build and test a type for complex numbers. Recall that a complex number has the form a+bi where a (the real part) and b (the imaginary part) are real numbers and i represents the square root of –1 (so i * i = -1). Your complex numbers should encapsulate two doubles:
class Complex
{
public:
Complex(double a = 0, double b = 0)
{
realPart = a; imPart = b; // *this =
a+bi
}
// etc.
private:
double realPart, imPart;
};
Your implementation should include implementations of +, *, -, /, ==, !=, <<, and >>.
An indexer is a program that generates a line number index for all marked words in a document. For example, typing
indexer < document >> document
to a console prompt generates an index for a text file called document and appends the index to the end of the file.
An index entry for the phrase "life and liberty" that occurs on lines 3, 5, 12, and 13 of a document has the form:
(life and liberty, {3, 5, 12, 13})
Note: even if the entry occurs multiple times on line 5, 5 only appears once in the set of line numbers.
Users must explicitly mark all phrases in the document that are to be indexed. For example, each occurrence of the phrase "life and liberty" must be bracketed by asterisks:
*life and liberty*
before the indexer runs.
To prove your program runs, select a document, mark entries for indexing, run the indexer as described above, then turn in the marked document with the appended index.
Finally: your program should be as short as possible. Aim for less than 20 lines of code not counting util.h (see Appendix 3).
Implement a spell checking program. Here's how the program will be called from the command line:
check doc.txt
Internally, it opens a second file called dictionary.txt. For each word, w, in doc, the spell checker searches dictionary for w. If w is not found, the user is prompted for the correct spelling of w. An empty line signifies that w is already spelled correctly. In either case, the correct spelling is added to the dictionary. Future occurrences of w will not be flagged as errors. If w is incorrectly spelled, all occurrences of w in doc will be replaced. When the end of the document is reached, updates to the dictionary will be written back to dictionary.txt. Be sure to preserve punctuation and formatting in the user's document.