[ create a new paste ] login | about

Link: http://codepad.org/XiQwdxXZ    [ raw code | output | fork ]

C++, pasted on May 10:
#include<iostream>
using namespace std;
struct Airport
{
  std::string Name, Acronym, Country;
};

void DisplayAirports(Airport [], int);
int main()
{
	
	Airport * airports = new Airport[4];
	airports[0].Name = "Heathrow";
	airports[0].Acronym = "LHR";
	airports[0].Country = "England";

	airports[1].Name = "Paris";
	airports[1].Acronym = "PR";
	airports[1].Country = "France";

	airports[2].Name = "Madrid";
	airports[2].Acronym = "MAD";
	airports[2].Country = "Spain";

	airports[3].Name = "Vegas";
	airports[3].Acronym = "LVS";
	airports[3].Country = "America";

	
	//cout << size << endl;                          //ignore this, this is just error checking
	//cout << airports[0].Name << endl;
	//DisplayMenu();
	//DisplayAirports();

	//int size;
	//size = sizeof( airports );
	//cout << size;		        			//error checking, this returns the value 4 
	
	//for( int i = 0; i < 4; i++)	                        //This displays the result I want but I want it within a function
	//{	
	//cout << "Name   : " << airports[i].Name << endl;	//Name   : Heathrow
	//cout << "Acronym: " << airports[i].Acronym << endl;	//Acronym: LHR
	//cout << "Country: " << airports[i].Country << endl;	//Country: England
	//cout << endl;				        	//etc
	//}																
	
	DisplayAirports(airports, 4);


	//keep_window_open();
	return 0;
}

void DisplayAirports(Airport arg[], int length)
{
	for (int i = 0; i < length; i++)
	{
		cout << arg[i].Name << endl;
	}
}


Output:
1
2
3
4
Heathrow
Paris
Madrid
Vegas


Create a new paste based on this one


Comments: