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

In the below Visual Studio 2012 C++ Windows Forms snippet here are several compi

ID: 667065 • Letter: I

Question

In the below Visual Studio 2012 C++ Windows Forms snippet here are several compiler errors in the solution. Identify each compiler error and explain the source of the error and what you can do to fix the error.

#pragma once
#include "City.h"

namespace CPPWinForms {

   using namespace System;
   using namespace System::ComponentModel;
   using namespace System::Collections;
   using namespace System::Windows::Forms;
   using namespace System::Data;
   using namespace System::Drawing;

   /// <summary>
   /// Summary for MyMainForm
   /// </summary>
   public ref class MyMainForm : public System::Windows::Forms::Form
   {

   public:
       MyMainForm(void)
       {
           InitializeComponent();
           //
           //TODO: Add the constructor code here
           //
       }

   protected:
       /// <summary>
       /// Clean up any resources being used.
       /// </summary>
       ~MyMainForm()
       {
           if (components)
           {
               delete components;
           }
       }
   private: System::Data::DataSet^ dataSet1;
   protected:

       /// <summary>
       /// Declare two class variables for the departure point
       /// and the destination point for one specific flight.
       /// </summary>
       City departure, destination;

   protected:

   private:
       /// <summary>
       /// Required designer variable.
       /// </summary>
       System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
       /// <summary>
       /// Required method for Designer support - do not modify
       /// the contents of this method with the code editor.
       /// </summary>
       void InitializeComponent(void)
       {
           this->dataSet1 = (gcnew System::Data::DataSet());
           (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataSet1))->BeginInit();
           this->SuspendLayout();
           //
           // dataSet1
           //
           this->dataSet1->DataSetName = L"NewDataSet";
           //
           // MyMainForm
           //
           this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
           this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
           this->ClientSize = System::Drawing::Size(605, 411);
           this->Name = L"MyMainForm";
           this->Text = L"MyMainForm";
           this->Load += gcnew System::EventHandler(this, &MyMainForm::MyMainForm_Load);
           (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataSet1))->EndInit();
           this->ResumeLayout(false);

       }
#pragma endregion
   private: System::Void MyMainForm_Load(System::Object^ sender, System::EventArgs^ e)
           {
               // Try to create an exit button:
               Button exitButton = new Button();
               exitButton.Text = L"Exit";
           }


};
}

Explanation / Answer

errors are

prog.cs(16,11): error CS1525: Unexpected symbol `ref'

prog.cs(16,20): error CS1514: Unexpected symbol `class', expecting `.' or `{'

prog.cs(16,34): error CS1525: Unexpected symbol `public', expecting `type'

prog.cs(50,15): warning CS1633: Unrecognized #pragma directive

prog.cs(77,0): warning CS1633: Unrecognized #pragma directive

Compilation failed: 3 error(s), 2 warnings

The name of MyMainForm IS a namespace though defined in the main.cpp

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote