delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/11/14:02:54

From: macko AT ix DOT netcom DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: Re: absolutely beginner
Date: Tue, 11 Mar 1997 16:10:37 GMT
Organization: Netcom
Lines: 256
Message-ID: <332582e8.51843288@nntp.ix.netcom.com>
References: <3324E0ED DOT 5634 AT ix DOT netcom DOT com> <33255DEF DOT 2DA7 AT cornell DOT edu>
NNTP-Posting-Host: nyc-ny49-25.ix.netcom.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Tue, 11 Mar 1997 08:28:15 -0500, "A. Sinan Unur" <asu1 AT cornell DOT edu>
wrote:

>MACKO wrote:
>> 
>> I've just started studying c++ via zd net online course. I was suggested
>> to try DJGPP as a compiler, and emcs as the editor program. I downloaded
>> and unzipped all the files according to the instructions, and want to
>> start using the programs.
>> I've downloaded and read a bunch of readme files, faq files, help files,
>> also read them online. 
>
>are you sure you read those files? the following is from readme.1st:
>
>Compilation
>-----------
>
>GCC is a command-line compiler, which you invoke from DOS command
>line.  To compile and link a single-file C program, use a command like
>this:
>
>        gcc myfile.c -o myfile.exe -lm
>
>The -lm links in the lib/libm.a library (trig math) if needed.  (Link
>order is significant, so if you need libm.a, always put `-lm' at the
>end of the command line.)
>
>etc etc
>
>if you want to use an integrated development environment, you will need
>to download rhide, it is available form the download site as well., and
>it is mentioned in the readme.1st file right below the preceding quote.
>
>sinan.
Thank you very much for your help.
Of course I have read readme.1st. The problem is that these commands
work with certain files only, do not work with others. Unable to
compile for example the test codes those were recommended to us by the
instructor to try first. According to him these files can test if the
compiler is able to handle exceptions and templates, which is a must. 
For IDE I downloaded and installed Emacs first, then  Rhide. I was
unable to use emacs at all, rhide gives me different error messages.
E.g. I open q2.txt in rhide then try to compile it says: "Don't know
how to build q2.o from q2.txt. I guess, it is because it can not
handle *.txt, so I rename it to q2.c then the message is  "error:
iostream.h: no such  file or directory (ENOENT)".
Could you give me more suggestions, please.
Thank you for your time.
Macko
I enclose the test codes below:
q2.txt:
  #include <iostream.h>

  template <class T>  
  class Array            
  {
  public:
     // constructors
     Array(int itsSize = 5);
     Array(const Array &rhs);
     ~Array() { delete [] pType; }

     // operators
     Array& operator=(const Array&);
     T& operator[](int offSet) { return pType[offSet]; }
     const T& operator[](int offSet) const { return pType[offSet]; }

     // accessors
     int GetSize() const { return itsSize; }

  private:
     T *pType;
     int  itsSize;
  };
Q3.txt:
  #include <iostream.h>
 
   const int DefaultSize = 10;
 
   class Array
   {
   public:
      // constructors
      Array(int itsSize = DefaultSize);
      Array(const Array &rhs);
      ~Array() { delete [] pType;}
 
      // operators
      Array& operator=(const Array&);
      int& operator[](int offSet);
      const int& operator[](int offSet) const;
 
      // accessors
      int GetitsSize() const { return itsSize; }
 
      // friend function
     friend ostream& operator<< (ostream&, const Array&);
 
    // define the exception classes
      class xBoundary {};
   private:
      int *pType;
      int  itsSize;
   };
 
 
   Array::Array(int size):
   itsSize(size)
   {
      pType = new int[size];
      for (int i = 0; i<size; i++)
        pType[i] = 0;
   }
 
    Array& Array::operator=(const Array &rhs)
    {
       if (this == &rhs)
          return *this;
       delete [] pType;
       itsSize = rhs.GetitsSize();
       pType = new int[itsSize];
       for (int i = 0; i<itsSize; i++)
          pType[i] = rhs[i];
	   return *this;
    }
 
    Array::Array(const Array &rhs)
    {
       itsSize = rhs.GetitsSize();
       pType = new int[itsSize];
       for (int i = 0; i<itsSize; i++)
          pType[i] = rhs[i];
    }
 
 
    int& Array::operator[](int offSet)
    {
       int size = GetitsSize();
       if (offSet >= 0 && offSet < GetitsSize())
          return pType[offSet];
       throw xBoundary();
	   return pType[0];			// appease MSC
    }
 
 
    const int& Array::operator[](int offSet) const
    {
       int mysize = GetitsSize();
       if (offSet >= 0 && offSet < GetitsSize())
          return pType[offSet];
       throw xBoundary();
	   return pType[0];			// appease MSC
    }
 
    ostream& operator<< (ostream& output, const Array& theArray)
    {
       for (int i = 0; i<theArray.GetitsSize(); i++)
          output << "[" << i << "] " << theArray[i] << endl;
       return output;
    }
 
 
   int main()
   {
	   int ArraySize;
	   int MAX;

	   cout << "Enter array size: ";
	   cin >> ArraySize;
      try
      {
         Array intArray(ArraySize);
		 cout << "Enter number of integers to initialize: ";
		 cin >> MAX;

         for (int j = 0; j< MAX; j++)
         {
            intArray[j] = j;
            cout << "intArray[" << j << "] okay..." << endl;
         }
      }
      catch (Array::xBoundary)
      {
         cout << "Boundary exception!\n";
      }
      catch (...)
      {
         cout << "Something went wrong, but I've no idea what!" <<
endl;
      }
      cout << "Done.\n";
	  return 0;
   }


  // implementations follow...

  // implement the constructor
  template <class T>
  Array<T>::Array(int size):
  itsSize(size)
  {
     pType = new T[size];
     for (int i = 0; i<size; i++)
        pType[i] = 0;
  }

  // copy constructor
  template <class T>
  Array<T>::Array(const Array &rhs)
  {
     itsSize = rhs.GetSize();
     pType = new T[itsSize];
     for (int i = 0; i<itsSize; i++)
        pType[i] = rhs[i];
  }

  // operator=
  template <class T>
  Array<T>& Array<T>::operator=(const Array &rhs)
  {
     if (this == &rhs)
        return *this;
     delete [] pType;
     itsSize = rhs.GetSize();
     pType = new T[itsSize];
     for (int i = 0; i<itsSize; i++)
        pType[i] = rhs[i];
     return *this;
  }


    template <class T>
    ostream& operator<< (ostream& output, const Array<T>& theArray)
    {
       for (int i = 0; i<theArray.GetSize(); i++)
          output << "[" << i << "] " << theArray[i] << endl;
       return output;
    }


  // driver program
  int main()
  {
     Array<int> theArray;      // an array of integers

     // fill the arrays
     for (int i = 0; i < theArray.GetSize(); i++)
        theArray[i] = i*2;

     // print the contents of the arrays
     for (int j = 0; j < theArray.GetSize(); j++)
        cout << "theArray[" << j << "]:\t" << theArray[j] << "\n";
	 return 0;
  }

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019