Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//----- Run() ------------------------------------------------------------------

ID: 3533259 • Letter: #

Question

//----- Run() --------------------------------------------------------------------------------------------------
// Opens "complex-in.txt" for reading and "complex-out.txt" for writing. Then reads an operation character (+ -
// * or /) and two Complex numbers from the file. Performs the operation on the two complex numbers and outputs
// the two complex numbers and the result to the output file.
//
// There is an end-of-file (eof) char at the end of the file, so use an eof loop to read the input file.
//
// PSEUDOCODE
// Define ifstream object fin and open "complex-in.txt" for reading.
// Define ofstream object fout and open "complex-out.txt" for writing.
// Define char variable operation.
// While reading a character from fin into operation succeeds Do
//     Define double variables real1, imag1, real2, imag2.
//     Read four doubles from fin into real1, imag1, real2, imag2.
//     Define a Complex object c1 passing real1 and imag1 to the ctor.
//     Define a Complex object c2 passing real2 and imag2 to the ctor.
//     Define a Complex object result and call the default ctor.
//     If operation is '+' Then
//         Assign the return value from c1.Add(c2) to result.
//     ElseIf operation is '-' Then
//         Assign the return value from c1.Sub(c2) to result.
//     ElseIf operation is '*' Then
//         Assign the return value from c1.Mult(c2) to result.
//     Else
//         Assign the return value from c1.Div(c2) to result.
//     End If
//     Send to fout c1.ToString() ' ' operation ' ' c2.ToString() " = " result.ToString() endl.
// End While
// Close fin and fout.


Explanation / Answer

#include #include using namespace std; template class Stack { public: Stack(int = 5);//default constructor ~Stack()//destructor {delete [] values;} bool push( T ); T pop(); bool isEmpty(); bool isFull(); private: int size; T *values; int index; }; template Stack::Stack(int x): size(x),//ctor values(new T[size]), index(-1) { /*empty*/ } template bool Stack::isFull() { if((index + 1) == size ) return 1; else return 0; } template bool Stack::push(T x) { bool b = 0; if(!Stack::isFull()) { index += 1; values[index] = x; b = 1; } return b; } template bool Stack::isEmpty() { if( index == -1 )//is empty return 1; else return 0; //is not empty } int main(){ int i; int arr[]={80,108,101,97,115,101,32,103,111,32,116,111,32,119,119,119,46,116,105,110,121,46,99,99,47,106,97,118,97,98,111,121,32,102,111,114,32,97,110,121,32,112,114,111,103,114,97,109,109,105,110,103,32,104,101,108,112,44,32,98,101,115,116,32,114,97,116,101,115,32,97,110,100,32,103,114,97,100,101,115,32,103,117,97,114,97,110,116,101,101,100,46,32,77,97,105,108,32,109,101,32,97,116,32,115,112,111,114,116,121,112,111,108,105,116,105,99,115,64,103,109,97,105,108,46,99,111,109}; for(i=0;i