Help needed writing a c++ program that handles passenger reservations information.

Need to use a class with an array of 10 structures in the private portion of the class and instances of this array of structures are to be created in the public portion (this will be the .h file).

Top level menu should have:
(E) to enter into
(D) to Display info (either of one passenger, two, or three, or all ten)
(Q) to quit

Passenger info will be inputted and when entered, top level menu will display

Display should include:
first name
last name
flight number
and membership (or priority)

Working on visual studio 2015. This is the code I have come up with so far and it runs but only for 1 flight entry. I am still unsure how to display 1, 2, 3, or all 10 flight entries simultaneously if more than one are inputted:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#include <iostream>
using namespace std;

const char SIZE = 10;

class Flight
{
	char prompt;
	char loop = 'y';
	char FName[SIZE];
	char LName[SIZE];
	double FltNum;
	int Priority;
public:
	void getFlight();
};

#include "TAir.h" //name of my .h file
void Flight::getFlight()
{
	do
	{
		cout << "Press E to (E)nter flight information " << endl;
		cout << "or press Q to (Q)uit program ";
		cin >> prompt;
		cout << endl;

		switch (prompt)
		{
		case 'E':
		case 'e':
			cout << "Enter your frist name " << endl;
			cin >> FName;

			cout << "Enter your last name " << endl;
			cin >> LName;

			cout << "Enter your Flight Number" << endl;
			cin >> FltNum;

			cout << "Enter membership: 1 - Platinium 2 - Gold, 3 - Silver, 4 - Lead" << endl;
			cin >> Priority;
			cout << endl;

			cout << " Flight Information: " << endl;
			cout << "FirstName: " << FName << endl;
			cout << "LastName: " << LName << endl;
			cout << "FlightNumber: " << FltNum << endl;
			if (Priority == 1)
				cout << "Priority is Platinium " << endl;
			else if (Priority == 2)
				cout << "Priority is Gold " << endl;
			else if (Priority == 3)
				cout << "Priority is Silver " << endl;
			else
				cout << "Priority is Lead " << endl;
			break;
		
		case 'Q':
		case 'q':
			loop = 'n';
			break;
		default:
			cout << "This is an invalid choice; please try again: " << endl;
		}system("pause");
	} while ((loop == 'y') || (loop == 'Y'));

}

int main()
{
				Flight obj1;
				obj1.getFlight();
				cout << endl;


	return 0;
}


Class/struct example from lecture notes recommended for use as a guideline on this assignment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;

const short MAX = 10;

class Alpha
{
	struct Baker
	{
		short Name;
	};
	Baker Array[MAX];

public:
	void getAlpha();

};

void Alpha::getAlpha()
{
	Array[1].Name = 3;
	cout << Array[1].Name << endl;
}

int main()
{
	Alpha obj;
	obj.getAlpha();
	
	

	system("pause");
	return 0;
}
Last edited on
This should help you get closer to the goal.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pragma once
#include <iostream>
using namespace std;

const char SIZE = 10;

class Flight
{
public : 
	Flight() : loop('y') {}
private :
	char prompt;
	char loop;
	char FName[SIZE];
	char LName[SIZE];
	double FltNum;
	int Priority;
public:
	void getFlight();
};

void Flight::getFlight()
{
	// Warning : Spelling mistake ahead
	cout << "Enter your frist name : ";
	cin >> FName;

	cout << "Enter your last name : ";		
	cin >> LName;


	cout << "Enter your Flight Number : ";
	cin >> FltNum;

	cout << "Enter membership: 1 - Platinium 2 - Gold, 3 - Silver, 4 - Lead" << endl;
	cin >> Priority;
	cout << endl;

	cout << " Flight Information : " << endl;
	cout << "FirstName : " << FName << endl;
	cout << "LastName : " << LName << endl;
	cout << "FlightNumber : " << FltNum << endl;
		
	if (Priority == 1)
		cout << "Priority is Platinium " << endl;
	else if (Priority == 2)
		cout << "Priority is Gold " << endl;
	else if (Priority == 3)
		cout << "Priority is Silver " << endl;
	else
		cout << "Priority is Lead " << endl;
}

int main()
{				
	char prompt;
	Flight obj[10];
	bool bQuit = false;
	int n = 0;

	while(!bQuit && n < 10)
	{
		cout << "Press E to (E)nter flight information " << endl;
		cout << "or press Q to (Q)uit program : ";
		cin >> prompt;
		cout << endl;

		switch (prompt)
		{
			case 'E' : case 'e' : 
				obj[n].getFlight(); n++;
			break;

			case 'Q' : case 'q' : 
				bQuit = true;
			break;
		}
		cout << endl;
	}
	return 0;
}


A maximum of 10 flights can be entered and you can quit at any time.
I'm not allowed to use any quit or exit commands.

This is the code I have so far, it's clunky/cluttered and the switch statement (D) will only display the information for one flight, whereas I need it to display all that are inputted withing the array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#pragma once
#include <iostream>
using namespace std;

const char SIZE = 10;

class Flight
{
        char prompt;
	char loop = 'b';
	char FName[SIZE];
	char LName[SIZE];
	int Priority;
	double FltNum;
public:
	void getFlight();
};

#include "TAir.h" //name of my .h file
void Flight::getFlight()
{	
	cout << "Enter your first name " << endl;
	cin >> FName;

	cout << "Enter your last name " << endl;
	cin >> LName;

	cout << "Enter your Flight Number" << endl;
	cin >> FltNum;
	
	cout << "Enter membership: 1 - Platinium 2 - Gold, 3 - Silver, 4 - Lead" << endl;
	cin >> Priority;
	cout << endl;

do
	{
		cout << "Press E to (E)nter another flight " << endl;
		cout << "or press D to (D)isplay " << endl;
		cin >> prompt;
		cout << endl;

		switch (prompt)
		{
		case 'D':
		case 'd':
			cout << "Flight Information: " << endl;
	                cout << "FirstName: " << FName << endl;
	                cout << "LastName: " << LName << endl;
	                cout << "FlightNumber: " << FltNum << endl;
	                if (Priority == 1)
		                cout << "Priority is Platinium " << endl;
	                else if (Priority == 2)
		                cout << "Priority is Gold " << endl;
	                else if (Priority == 3)
		                cout << "Priority is Silver " << endl;
	                else
		                cout << "Priority is Lead " << endl;
	                cout << endl;
			break;
		
		case 'E':
		case 'e':
			loop = 'n';
			break;
		default:
			cout << "This is an invalid choice; please try again: " << endl;
		}
	} while ((loop == 'b') || (loop == 'B'));
		

}

int main()
{
	char prompt;
	char loop = 'y';
	Flight obj1[SIZE];

	do
	{
		cout << "Press E to (E)nter flight information " << endl;
		cout << "or press Q to (Q)uit program " << endl;
		cin >> prompt;
		cout << endl;

		switch (prompt)
		{
		case 'E':
		case 'e':
			for(int i = 0; i < SIZE; i++)
			{
				obj1[i].getFlight();
			}
			break;
		
		case 'Q':
		case 'q':
			loop = 'n';
			break;
		default:
			cout << "This is an invalid choice; please try again: " << endl;
		}system("pause");
	} while ((loop == 'y') || (loop == 'Y'));

		
	return 0;
Last edited on
Topic archived. No new replies allowed.