Solved

Airline Reservation System help

Posted on 2011-02-19
4
1,360 Views
Last Modified: 2012-05-11
I am brand new to programming and I need help debugging. I hope that I posted the question in the right place and in the right format. I am getting the errors listed below:

1>  Airline code.cpp
1>Airline code.cpp(2): warning C4627: '#include <fstream>': skipped when looking for precompiled header use
1>          Add directive to 'StdAfx.h' or rebuild precompiled header
1>Airline code.cpp(3): warning C4627: '#include <string>': skipped when looking for precompiled header use
1>          Add directive to 'StdAfx.h' or rebuild precompiled header
1>Airline code.cpp(4): warning C4627: '#include <vcclr.h>': skipped when looking for precompiled header use
1>          Add directive to 'StdAfx.h' or rebuild precompiled header
1>Airline code.cpp(480): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
1>  Airline reservation System.cpp
1>c:\users\user\documents\visual studio 2010\projects\airline reservation system\airline reservation system\Form1.h(122): error C2086: 'System::Windows::Forms::ListBox ^Lab7A::Form1::lbPlaneManifest' : redefinition
1>          c:\users\user\documents\visual studio 2010\projects\airline reservation system\airline reservation system\Form1.h(45) : see declaration of 'Lab7A::Form1::lbPlaneManifest'
1>Airline reservation System.cpp(6): error C2871: 'AirlinereservationSystem' : a namespace with this name does not exist
1>Airline reservation System.cpp(8): error C2337: 'STAThreadAttribute' : attribute not found
1>Airline reservation System.cpp(12): error C2653: 'Application' : is not a class or namespace name
1>Airline reservation System.cpp(12): error C3861: 'EnableVisualStyles': identifier not found
1>Airline reservation System.cpp(13): error C2653: 'Application' : is not a class or namespace name
1>Airline reservation System.cpp(13): error C3861: 'SetCompatibleTextRenderingDefault': identifier not found
1>Airline reservation System.cpp(16): error C2653: 'Application' : is not a class or namespace name
1>Airline reservation System.cpp(16): error C2061: syntax error : identifier 'Form1'
1>Airline reservation System.cpp(16): error C3861: 'Run': identifier not found
1>  AssemblyInfo.cpp
1>  Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.82
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
#pragma once
#include <fstream>
#include <string>
#include <vcclr.h>

using namespace std;


namespace Lab7A
{

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

	const int SIZE = 20;

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	private:

		// Declare data members
		bool activeFlight;
		int numFirstClass;
		int numBusinessClass;

		// Declare managed arrays
		array <String^>^ passNameAr;
		array <String^>^ seatAr;
		array <String^>^ flightClassAr;

	private: System::Windows::Forms::ListBox^ lbPlaneManifest;

	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
			//Create new managed arrays from the heap
			passNameAr = gcnew array <String^>(SIZE);
			seatAr = gcnew array <String^>(SIZE);
			flightClassAr = gcnew array <String^>{"First","Business"};

			//Assign values to the arrays
			for (int i = 0; i < SIZE; i++)
				passNameAr[i] = "";
			seatAr[0] = "1A";
			seatAr[1] = "1B";
			seatAr[2] = "2A";
			seatAr[3] = "2B";
			seatAr[4] = "4A";
			seatAr[5] = "4B";
			seatAr[6] = "4C";
			seatAr[7] = "4D";
			seatAr[8] = "5A";
			seatAr[9] = "5B";
			seatAr[10] = "5C";
			seatAr[11] = "5D";
			seatAr[12] = "6A";
			seatAr[13] = "6B";
			seatAr[14] = "6C";
			seatAr[15] = "6D";
			seatAr[16] = "7A";
			seatAr[17] = "7B";
			seatAr[18] = "7C";
			seatAr[19] = "7D";

			activeFlight = true;
			numFirstClass = 0;
			numBusinessClass = 0;
			flightClassAr[0] = "First";
			flightClassAr[1] = "Business";

			cboFlightClass->DataSource = flightClassAr;
			cboSeatNumber->Items->Clear();

			for (int i = 0; i < 4; i++)
				cboSeatNumber->Items->Add(seatAr[i]);
			cboSeatNumber->SelectedIndex = 0;
			DisplayManifest();
			

		}
	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Label^  lblEntPassName;
	private: System::Windows::Forms::Label^  lblFlightClass;
	private: System::Windows::Forms::Label^  lblSeatNumber;


	private: System::Windows::Forms::TextBox^  txtPassengerName;
	private: System::Windows::Forms::ComboBox^  cboFlightClass;
	private: System::Windows::Forms::ComboBox^  cboSeatNumber;


	private: System::Windows::Forms::Button^  btnAddPassenger;
	private: System::Windows::Forms::Button^  btnCloseFlight;
	private: System::Windows::Forms::ListBox^  lbPlaneManifest;




	protected: 

	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->lblEntPassName = (gcnew System::Windows::Forms::Label());
			this->lblFlightClass = (gcnew System::Windows::Forms::Label());
			this->lblSeatNumber = (gcnew System::Windows::Forms::Label());
			this->txtPassengerName = (gcnew System::Windows::Forms::TextBox());
			this->cboFlightClass = (gcnew System::Windows::Forms::ComboBox());
			this->cboSeatNumber = (gcnew System::Windows::Forms::ComboBox());
			this->btnAddPassenger = (gcnew System::Windows::Forms::Button());
			this->btnCloseFlight = (gcnew System::Windows::Forms::Button());
			this->lbPlaneManifest = (gcnew System::Windows::Forms::ListBox());
			this->SuspendLayout();
			// 
			// lblEntPassName
			// 
			this->lblEntPassName->AutoSize = true;
			this->lblEntPassName->Location = System::Drawing::Point(37, 30);
			this->lblEntPassName->Name = L"lblEntPassName";
			this->lblEntPassName->Size = System::Drawing::Size(121, 13);
			this->lblEntPassName->TabIndex = 0;
			this->lblEntPassName->Text = L"Enter Passengers Name";
			this->lblEntPassName->Click += gcnew System::EventHandler(this, &Form1::lblEntPassName_Click);
			// 
			// lblFlightClass
			// 
			this->lblFlightClass->AutoSize = true;
			this->lblFlightClass->Location = System::Drawing::Point(37, 78);
			this->lblFlightClass->Name = L"lblFlightClass";
			this->lblFlightClass->Size = System::Drawing::Size(93, 13);
			this->lblFlightClass->TabIndex = 1;
			this->lblFlightClass->Text = L"Select Flight Class";
			this->lblFlightClass->Click += gcnew System::EventHandler(this, &Form1::lblflightClass_Click);
			// 
			// lblSeatNumber
			// 
			this->lblSeatNumber->AutoSize = true;
			this->lblSeatNumber->Location = System::Drawing::Point(284, 70);
			this->lblSeatNumber->Name = L"lblSeatNumber";
			this->lblSeatNumber->Size = System::Drawing::Size(62, 26);
			this->lblSeatNumber->TabIndex = 2;
			this->lblSeatNumber->Text = L"Select Seat\r\n      Number\r\n";
			this->lblSeatNumber->Click += gcnew System::EventHandler(this, &Form1::lblseatNumber_Click);
			// 
			// txtPassengerName
			// 
			this->txtPassengerName->Location = System::Drawing::Point(184, 22);
			this->txtPassengerName->Name = L"txtPassengerName";
			this->txtPassengerName->Size = System::Drawing::Size(233, 20);
			this->txtPassengerName->TabIndex = 3;
			this->txtPassengerName->TextChanged += gcnew System::EventHandler(this, &Form1::txtPassengerName_TextChanged);
			// 
			// cboFlightClass
			// 
			this->cboFlightClass->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
			this->cboFlightClass->FormattingEnabled = true;
			this->cboFlightClass->Location = System::Drawing::Point(136, 75);
			this->cboFlightClass->Name = L"cboFlightClass";
			this->cboFlightClass->Size = System::Drawing::Size(130, 21);
			this->cboFlightClass->TabIndex = 4;
			this->cboFlightClass->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::cboFlightClass_SelectedIndexChanged);
			// 
			// cboSeatNumber
			// 
			this->cboSeatNumber->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
			this->cboSeatNumber->FormattingEnabled = true;
			this->cboSeatNumber->Location = System::Drawing::Point(352, 75);
			this->cboSeatNumber->Name = L"cboSeatNumber";
			this->cboSeatNumber->Size = System::Drawing::Size(63, 21);
			this->cboSeatNumber->TabIndex = 5;
			// 
			// btnAddPassenger
			// 
			this->btnAddPassenger->Location = System::Drawing::Point(29, 128);
			this->btnAddPassenger->Name = L"btnAddPassenger";
			this->btnAddPassenger->Size = System::Drawing::Size(173, 23);
			this->btnAddPassenger->TabIndex = 6;
			this->btnAddPassenger->Text = L"Add Passenger";
			this->btnAddPassenger->UseVisualStyleBackColor = true;
			this->btnAddPassenger->Click += gcnew System::EventHandler(this, &Form1::btnAddPassenger_Click);
			// 
			// btnCloseFlight
			// 
			this->btnCloseFlight->Location = System::Drawing::Point(259, 128);
			this->btnCloseFlight->Name = L"btnCloseFlight";
			this->btnCloseFlight->Size = System::Drawing::Size(178, 23);
			this->btnCloseFlight->TabIndex = 7;
			this->btnCloseFlight->Text = L"Close Flight";
			this->btnCloseFlight->UseVisualStyleBackColor = true;
			this->btnCloseFlight->Click += gcnew System::EventHandler(this, &Form1::btnCloseFlight_Click);
			// 
			// lbPlaneManifest
			// 
			this->lbPlaneManifest->FormattingEnabled = true;
			this->lbPlaneManifest->Location = System::Drawing::Point(29, 178);
			this->lbPlaneManifest->Name = L"lbPlaneManifest";
			this->lbPlaneManifest->Size = System::Drawing::Size(408, 316);
			this->lbPlaneManifest->TabIndex = 8;
			this->lbPlaneManifest->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::lbPlaneManifest_SelectedIndexChanged);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(472, 507);
			this->Controls->Add(this->lbPlaneManifest);
			this->Controls->Add(this->btnCloseFlight);
			this->Controls->Add(this->btnAddPassenger);
			this->Controls->Add(this->cboSeatNumber);
			this->Controls->Add(this->cboFlightClass);
			this->Controls->Add(this->txtPassengerName);
			this->Controls->Add(this->lblSeatNumber);
			this->Controls->Add(this->lblFlightClass);
			this->Controls->Add(this->lblEntPassName);
			this->Name = L"Form1";
			this->Text = L"Bluebird Airlines Flight Reservation System";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void lblseatNumber_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
			 }
	private: System::Void lblflightClass_Click(System::Object^  sender, System::EventArgs^  e)
			 {
			 }
		 
	private: System::Void lblEntPassName_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
			 }
	private: System::Void txtPassengerName_TextChanged(System::Object^  sender, System::EventArgs^  e) 
			 {
		     }
	private: System::Void btnAddPassenger_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				 String^ errMess;
				 String^ passName = txtPassengerName->Text;
				 String^ flightClass = cboFlightClass->Text;
				 String^ seatNum = cboSeatNumber->Text;

				 if (passName == "")
				 {
					 errMess = "Must enter passenger name";
					 MessageBox::Show(errMess, "E R R O R");
					 txtPassengerName->Focus();
					 return;
				 }

				 int i = 0;
				 int seatIdx = 0;

				 for (i = 0; i < SIZE; i++)
					 if (seatNum == seatAr[i])
					 {
						 seatIdx = i;
						 break;
					 }

					 AssignSeat (passName, flightClass, seatIdx);
					 DisplayManifest();
					 PopulateSeatCombo();

			 }
    private: System::Void btnCloseFlight_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				 if (activeFlight)
				 {
					 DisplayManifest();
					 DisplayPassengerList();
					 btnCloseFlight->Text = "Start a New Flight";
					 activeFlight = false;
					 btnCloseFlight->Focus();
					 btnAddPassenger->Enabled = false;
				 }
				 else
				 {
					 btnCloseFlight->Text = "Close Flight";
					 btnAddPassenger->Enabled = true;

					 for (int i = 0; i < SIZE; i++)
						 passNameAr[i] = "";

					 Array::Sort(seatAr);
					 cboSeatNumber->Items->Clear();

					 for (int i = 0; i < 4; i++)
						 cboSeatNumber->Items->Add(seatAr[i]);

					 cboSeatNumber->SelectedIndex = 0;
					 numFirstClass = 0;
					 numBusinessClass = 0;
					 DisplayManifest();
					 activeFlight = true;
					 txtPassengerName->Focus();
				 }
			 }

    private: System::Void cboFlightClass_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) 
			 {
				 int i;
				 cboSeatNumber->Items->Clear();
				 if (cboFlightClass->Text == "First")
				 {
					 for (i = 0; i < 4; i++)
						 if (passNameAr[i] == "")
							 cboSeatNumber->Items->Add(seatAr[i]);
				 }
				 else
				 {
					 for (i = 4; i < SIZE; i++)
						 if (passNameAr[i] == "")
							 cboSeatNumber->Items->Add(seatAr[i]);
				 }
				 if (cboSeatNumber->Items->Count > 0)
					 cboSeatNumber->SelectedIndex = 0;

			 }

    private: System::Void lbPlaneManifest_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) 
			 {
			 }
	private: void DisplayPassengerList()
			 {
				 std::ofstream outFile;

				 outFile.open("PlaneManifest.txt");
				 outFile << "    P L A N E    M A N I F E S T\n";
				 outFile << " Seat           Passenger Name\n";

				 for (int i = 0; i < SIZE; i++)
				 {
					 String ^passS = passNameAr[i]; // convert passNameAr to char*
					 pin_ptr<const wchar_t> wchP = PtrToStringChars(passS); // Pin memory so GC can't move it 
																			// while native function is called
					 size_t convertedCharsP = 0; // convert to char*
					 size_t sizeInBytesP = ((passS->Length + 1) * 2);
					 errno_t errP = 0;
					 char    *pass = (char *)malloc(sizeInBytesP);
					 errP = wcstombs_s(&convertedCharsP, pass, sizeInBytesP, wchP, sizeInBytesP);


					 String ^seatS = seatAr[i]; // convert passNameAr to char*
					 pin_ptr<const wchar_t> wchS = PtrToStringChars(seatS); // Pin memory so GC can't move it 
																			// while native function is called
					 size_t convertedCharsS = 0; // convert to char*
					 size_t sizeInBytesS = ((seatS->Length + 1) * 2);
					 errno_t errS = 0;
					 char    *seat = (char *)malloc(sizeInBytesS);
					 errS = wcstombs_s(&convertedCharsS, seat, sizeInBytesS, wchS, sizeInBytesS);
					 outFile << "  " << seat << "\t\t" << pass << "\n";
					 //outFile << "  " << seatAr[i]->ToCharArray() << "\t\t" << passNameAr[i]->ToCharArray() << "\n";
				 }


				 Array::Sort(passNameAr, seatAr);
				 String^ str = String::Format("     First Class; (0)    Business Class: (1)", numFirstClass, numBusinessClass);
								              //"     First Class: " + numFirstClass + "   Business Class: " + numBusinessClass + "\n";

				 lbPlaneManifest->Items->Add(" N U M B E R   O F   P A S S E N G E R S");
				 lbPlaneManifest->Items->Add(str);
				 lbPlaneManifest->Items->Add("");

				 outFile << "\n\n  N U M B E R   O F   P A S S E N G E R S\n";
					 pin_ptr<const wchar_t> wch = PtrToStringChars(str);   // Pin memory so GC can't move it while native function is called
					 size_t convertedChars = 0;                            // Convert to Char
					 size_t sizeInBytes = ((str->Length + 1) * 2);
					 errno_t err = 0;
					 char    *ch = (char *)malloc(sizeInBytes);

				 err = wcstombs_s(&convertedChars, ch, sizeInBytes, wch, sizeInBytes);
				 outFile << ch << "\n" << "\n" << "\n";  // outFile << str->ToCharArray() << "\n" << "\n" << "\n";


				 lbPlaneManifest->Items->Add("         P A S S E N G E R   L I S T");
				 lbPlaneManifest->Items->Add("   Passenger Name                     seat");
				 outFile << "         P A S S E N G E R   L I S T\n";
				 outFile << "   Passenger Name                     seat\n";
				 
				 for (int i = 0; i < SIZE; i++)
				 {
				 if (passNameAr[i]->Length > 0)
				 {
					 str = String::Format("(0, -30)         (1)", passNameAr[i], seatAr[i]);
					 lbPlaneManifest->Items->Add(str);

					 pin_ptr<const wchar_t> wch = PtrToStringChars(str);   // Pin memory so GC can't move it while native function is called
					 size_t convertedChars = 0;                            // Convert to Char
					 size_t sizeInBytes = ((str->Length + 1) * 2);
					 errno_t err = 0;
					 char    *ch = (char *)malloc(sizeInBytes);

					 err = wcstombs_s(&convertedChars, ch, sizeInBytes, wch, sizeInBytes);
					 outFile << ch << "\n";  // outFile << str->ToCharArray() << "\n";

				 }
			 }
			 outFile.close();

		} 
	private: void DisplayManifest()
	    {
		    String^ str;
		    lbPlaneManifest->Items->Clear();
		    lbPlaneManifest->Items->Add("    P L A N E   M A N I F E S T");
		    lbPlaneManifest->Items->Add(" Seat          Passenger Name");
		    for (int i = 0; i < SIZE; i++)
		    {
			    str = "  " + seatAr[i] + "\t\t" + passNameAr[i];
			    lbPlaneManifest->Items->Add(str);
		    }
	    }
	private: void AssignSeat(String^ passName, String^ flightClass, int seatIdx)
		{
			passNameAr[seatIdx] = passName;

			if (flightClass == "First")
				numFirstClass++;
			else
				numBusinessClass++;

		}
	private: void PopulateSeatCombo()
		{
			int i;
			txtPassengerName->Text = "";
			flightClassAr = gcnew array<String^>(2);
			flightClassAr[0] = "First";
			flightClassAr[1] = "Business";
			cboFlightClass->DataSource = flightClassAr;
			cboFlightClass->SelectedIndex = 0;
			cboSeatNumber->Items->Clear();

			if (numFirstClass + numBusinessClass == 20)
			{
				btnCloseFlight->Focus();
				btnAddPassenger->Enabled = false;
				return;
			}

			txtPassengerName->Focus();

			if (numFirstClass < 4)
			{
				for (i = 0; i < 4; i++)
					if (passNameAr[i] == "")
						cboSeatNumber->Items->Add(seatAr[i]);
				
				if (numBusinessClass == 16)
				{
					flightClassAr = gcnew array<String^>(1);
					flightClassAr[0] = "First";
					cboFlightClass->DataSource = flightClassAr;
				}
			}
			else
			{
				flightClassAr = gcnew array<String^>(1);
				flightClassAr[0] = "Business";
				cboFlightClass->DataSource = flightClassAr;

				for (i = 4; i < SIZE; i++)
					if (passNameAr[i] == "")
						cboSeatNumber->Items->Add(seatAr[i]);
			}

			if (cboSeatNumber->Items->Count > 0)
				cboSeatNumber->SelectedIndex = 0;
		}
									  
    };
}

Open in new window

0
Comment
Question by:IbanezRG
  • 2
4 Comments
 
LVL 3

Expert Comment

by:gopisera
ID: 34933233
You can ignore the warnings.....

If you need you can add the required header files then the warnings will not come.

Please add .h to the predefined headers to identify.

Hoping for your error there is a missing of one namspace...

Please check for it
0
 

Author Comment

by:IbanezRG
ID: 34933284
Can you give me an example?
0
 
LVL 11

Accepted Solution

by:
cup earned 500 total points
ID: 34946546
Remove #pragma once.  This is a MS thing which doesn't work on all other compilers.

If you don't wish to use precompiled headers

Open project properties
Expand C++, precompiled headers
On the first line, change "Using Precompiled Header" to "Not Using Precompiled Headers"

If you wish to use precompiled headers add

#include "stdafx.h"

0
 

Author Closing Comment

by:IbanezRG
ID: 34984544
Thanks everyone for the help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
NotAlone Challenge 20 72
C++ question 3 48
Problem to event 3 52
White board coding practice 3 61
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article will show, step by step, how to integrate R code into a R Sweave document
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now