-
Help needed.
I need some help with this program. I have posted what I have so far below. If you will look over it and give me any advice as to what I need to do based on these specifications:
PROBLEM : An airline flies between six cities. Whether or not there
is a direct flight from one city to another is indicated
in a table found in a data file called flights.241.
The table will have the following appearance, except the
row and column designators will not be present:
TO:
1 2 3 4 5 6
1 F T T F F T
2 T F T F F T
FROM: 3 F F F T F F
4 F T F F T F
5 F T F T F F
6 F T F F T F
On the left and across the top are the number codes of the cities.
If there is a T at the intersection of a row and column, then
there is a direct flight from the city marked on the left to
the city indicated at the top. An F indicates that there is
no direct flight between the two cities. The key of the city
names will follow the flight ( T-F ) matrix in the data file.
It will consist of six names, the first coinciding with matrix
code number 1, the second with number 2, etc.
Another file called customer.241 will contain a customer name,
customer number, and a request for a flight pattern. The
flight pattern indicates the cities between which that customer
wishes to fly. For example, a pattern of 13426 indicates that
the customer wishes to fly from city 1 to city 3, then from city
3 to city 4, then to city 2, and finally to city 6. The maximum
number of cities in a flight pattern is five. If a customer has
less than five cities in a flight pattern, then the remaining
fields are filled with zeros. Thus, a pattern of 62000
indicates that the customer wishes to fly from city 6 to
city 2 and does not wish to continue beyond that. The customer
file will have the following format:
(Cols 1 - 25) (Cols 26 - 30) (Cols 31 - 35)
CUSTOMER NAME CUSTOMER NUMBER FLIGHT PATTERN
John Smith 10232 13426
Write a C++ program that reads the flight matrix data and
city names from the flight file, reads the customer request
information from the customer file, prints at the top of a new
page the flight matrix with city labels, determines if each
customer's requested flight pattern is possible, and prints
a table containing the customer's names, flight patterns,
customer numbers, and a statement indicating whether or not a
ticket may be issued for the desired pattern.
Code:
#include <iostream>
#include <fstream>
using namespace std;
//prototype function headers
void Filecheck(ifstream&, char[]);
void ReadCities(ifstream&, char[6][6]);
void PrintOut(char[6][6]);
int main()
{
char flights[6][6];
ifstream Input;
ofstream Out;
char Cities;
ReadCities (Input, Cities);
//PrintOut (Cities);
return 0;
}
/**********************************/
void Filecheck(ifstream& In, char Name[])
{
do
{
cout << "File not found\n";
cout << "Enter file name >";
cin >> Name;
In.open(Name);
}
while(In.fail());
}
/**********************************/
void ReadCities(ifstream Input, char Cities[6][6])
{
int i=0;
int j=0;
Input.open ("flights.241");
while (!Input.eof())
{
for (i = 0; i < 6; i++)
for (j = 0; j < 6; j++)
Input >> Cities[i][j];
}
}
/**********************************/
void PrintOut(char Cities[6][6])
{
int i=0;
int j=0;
for (i=0; i<6; i++)
{
for (j=0; j<6; j++)
cout << Cities[i][j] << " ";
cout << endl;
}
}
-
Is this homework?
Looking at the data file,
I think the letters are separated by spaces. Therefore,
Code:
for (i = 0; i < 6; i++)
for (j = 0; j < 6; j++)
Input >> Cities[i][j];
should be modified to skip over spaces.
-
>> should be modified to skip over spaces
That code already skips over spaces. No change is necessary there.