Convert to C++

I want to analyze this code, but I don't think it's in c++. Can anyone convert it.
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
  #include "stdafx.h"
#define MAX 11

struct airplane
{
	int seat;
	int occupied;
	char fName[20];
	char lName[20];
};

int emptySeatNum(airplane passenger[], int size)
int seatList(airplane passenger[], int list);
int assignSeat(int passenger[]);
int unassignSeat();

int _tmain(int argc, _TCHAR* argv[])
{
	struct airplane passenger[MAX];
	int choice = 0;
	int i;
	int numSeats;

	for(i = 1; i < MAX; i++)
	{
		passenger[i].seat = 0;
	}

	while(choice != 5)
	{
		printf("*** C & M Airlines ***\n");
		printf("Choose a funtion\n");
		printf("1) Show number of empty seats\n");
		printf("2) Show list of seats\n");
		printf("3) Assign a seat\n");
		printf("4) Un-assign a seat\n");
		printf("5) Quit\n");
		
		//Get the choice from the user
		printf("Enter your choice: ");
		scanf("%d", &choice);
		printf("\n");

		switch(choice)
		{
			case 1:
				numSeats = emptySeatNum(passenger, MAX);
				printf("The number of available seats are %d\n", numSeats);
				break;
			case 2:
				seatList(passenger, MAX);
				break;
			case 3:
				assignSeat(passenger, MAX);
				break;
			case 4:
				unassignSeat();
				break;
			case 5:
				break;
			default:
				printf("That is not one of the available functions, please retry.\n");
		}
	}

	return 0;
}

int emptySeatNum(airplane passenger[], int size)
{
	int i;
	int count = 0;

	for(i = 0; i < size; i++)
	{
		printf("There are %d seats available.", passenger[i].seat);
		count++;
	}
	return count;
}

int seatList(airplane passenger[], int size)
{
	int i;
	int count = 0;

	for(i = 1; i < size; i++)
	{
		if(passenger[i].seat == 0)
		{
			printf("Seat #%d is not assigned.\n", i);
		}
		else
		{
			printf("Seat #%d is assigned to %d\n", passenger[i].seat, passenger[i].fName, passenger[i].lName);
		}
	}
}

int assignSeat(int passenger[])
{
	int i;
	int num;

	printf("What seat number?");
	scanf("%d", &num);
	printf("What is the first name of the passenger? ");
	scanf("%s", &passenger[num].fName);
	printf("What is the last name of the passenger? ");
	scanf("%s", &passenger[num].lName);
	

	
	for (i = 0; i <= 12 ; i++)
	{
		if(passenger[i]==0)
			return 1;
	}
	return 0;
}
It is C, using an MS-variant of main() and the "stdafx.h" instead of all the proper headers.
We won't do your homework for you. But, if you need some hints as to where to start:

1) All the input and output is using C functions. You should switch to using C++ streams.

2) You might want turn your airplane struct into a proper class, following the OO principle of encapsulation to hide the data and provide a public interface. (You might also want to give it a more appropriate name, as it clearly doesn't represent an airplane.)
its c++ with a C flavor, I think. Note the format of the struct, in C you would need a typedef or a dummy variable on the end brace I think (?).

given that the program is tiny, 90% of the code is printf or scanf which is what you would want to change, I would say start over. But you could convert it with a lot of aggravation to use cout instead of printf and cin instead of scan.

Or you could leave it alone, a c++ compiler can compile this. The nonstanadard header stdafx can be removed for other compilers and main can be converted to int main () if you are not using visual studio.
jonnin is right. GCC complains about "unknown typename airplane"
Topic archived. No new replies allowed.