title: Constructor Operator << Device and Test Dynamic Array
body: <pre><code>#include iostream
  #include cmath
  #include fstream
  #include cstdlib
  #include string
  using namespace std;
  class Device {//Input and store Device Description and Serial Numbers
  protected:
   static string  serial_number;
   static string device_description;
  public:
   Device() {
       serial_number = ("6DCMQ32");
       device_description = ("TheDell");
   }
   Device(string s, string d) {
       serial_number = s;
      device_description = d;
   }
  };
  string Device::device_description;
  string Device::serial_number;
  class Test {//Input and store Test Description, recent day, and month; 
  Calculate the next day
     protected:
        static string Test_Description;
        static int recent_month, recent_day, recent_year, new_month;
        static int nmonth, next_month, next_day, next_year, max_day;
     public:
     Test() {
          Test_Description = ("Virtual");
     }
     static void getMonth() {//Calculates the next/new month
      next_month = recent_month + nmonth;
      new_month = next_month % 12;
      if (next_month &gt;= 12) {
          cout &lt;&lt; "The next Date: " &lt;&lt; new_month &lt;&lt; " / ";
      }
      else {
          cout &lt;&lt; "The next Date: " &lt;&lt; next_month &lt;&lt; " / ";
      }
  }
  static void getDay() {  //Calculates day of next month
            if (new_month == 4 || new_month == 6 || new_month == 9 || new_month == 11) {
           max_day = 30;
       }
       else if (new_month == 2) {
          max_day = 29;
       }
       else {
           max_day = 31;
       }
       if (recent_day &gt; max_day) {
           cout &lt;&lt; max_day &lt;&lt; " / ";
       }
       else {
           cout &lt;&lt; recent_day &lt;&lt; " / ";
       }
   }
   static void getYear() {// Calculate the year of next month
       next_year = recent_year + next_month;
       if (next_year &gt;= 12) {
           cout &lt;&lt; recent_year + (next_month / 12) &lt;&lt; endl;
       }
       else {
           cout &lt;&lt; next_year &lt;&lt; endl;
       }
   }
   static void getDate() {// Collects the output of each element of next date
       Test::getMonth(), Test::getDay(), Test::getYear();
   }
    };
   string Test::Test_Description;
   int Test::recent_month;
   int Test::recent_day;
   int Test::recent_year;
   int Test::new_month;
   int Test::nmonth;
   int Test::next_month;
   int Test::next_day;
   int Test::next_year;
   int Test::max_day;
   class Lab : public Device, public Test {
   protected:
       static int n;
    public:
   friend istream &amp; operator&gt;&gt;(istream &amp; in, Lab &amp; lab) {// Inputs 
       cout &lt;&lt; "Enter Device Desciption and Serial Number: ";
       getline(in, device_description);
       getline(in, serial_number);
       cout &lt;&lt; "Enter Test Desciption: ";
       getline(in, Test_Description);
       cout &lt;&lt; "Enter the Number of months: ";
       in &gt;&gt; nmonth;
       cout &lt;&lt; "Enter the Most Recent Date(mm/dd/yyyy): ";
       in &gt;&gt; recent_month &gt;&gt; recent_day &gt;&gt; recent_year;
       return in;
     }
     friend ostream &amp; operator&lt;&lt;(ostream &amp; out, Lab &amp; lab) {//Outputs 
      everything in Device Class
       out &lt;&lt; Lab::device_description &lt;&lt; endl;
       out &lt;&lt; Lab::serial_number &lt;&lt; endl;
       out &lt;&lt; Lab::Test_Description &lt;&lt; endl;
       getDate();
       return out;
      }
      static void getN() {
       cout &lt;&lt; "Enter the number of devices: ";
       cin &gt;&gt; n;
      }
      static void getWrite() {        
       Lab *obj = new Lab[n];
         if (obj == 0) {
           cout &lt;&lt; "Memory Error";
           exit(1);
         }
       for (int i = 0; i&lt;n; i++) {
           cin &gt;&gt; obj[i];
           cout &lt;&lt; endl;
       }
       ofstream myfile("Device.txt");
       myfile.write((char *)obj, n * sizeof(Lab));
       delete[] obj;      
     }
     static void getRead() {
       ifstream file2("Device.txt");
       Lab *obj2 = new Lab[n];
       if (obj2 == 0) {
           cout &lt;&lt; "Memory Error";
           exit(1);
       }
       file2.read((char *)obj2, n * sizeof(Lab));
       for (int i = 0; i &lt; n; i++) {
           cout &lt;&lt; obj2[i];
           cout &lt;&lt; endl;
       }
       delete[] obj2;
   }
   /*void getSearch(){
  
   }*/
  };
  int Lab::n;
  void main() {
     Lab L;
     L.getN();
     L.getWrite();
     L.getRead();
     system("pause");
  }
  </code></pre>
  
  <blockquote>
    <p>The Output I get is TheDell 6DCMQ32, Virtual when I entered my inputs. The date is correct the only problem is the Device Description, Serial Number, and Test Device.</p>
  </blockquote>
  
  <p>Problem with Operator &lt;&lt; in File i/o reading where it outputs the values in the Constructor </p>
  
  <p>Purpose: is to enter the number of months for the next test date of device with input of serial number,
  Device Description, Test Description, recent date, and the number of months of two tests. At the end the 
  program must be searched by having the user to input the serial number and the next date, if these two are 
  valid everything in the device is listed out.</p>