Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
krmaet
/
Lennubroneerimis_tarkvara
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2c9e945c
authored
Mar 18, 2023
by
karade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update broneering.c
parent
ecae42cc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
3 deletions
broneering.c
broneering.c
View file @
2c9e945c
...
@@ -9,19 +9,25 @@
...
@@ -9,19 +9,25 @@
int
main
(
void
)
int
main
(
void
)
{
{
int
seatmap
[
ROWS
][
COLS
]
=
{
0
};
srand
(
time
(
NULL
));
srand
(
time
(
NULL
));
int
i
=
0
;
int
i
=
0
;
users
data
[
SEAT_MAX
];
users
data
[
SEAT_MAX
];
int
cont
=
0
;
int
cont
=
0
;
puts
(
"Choose destination
\n
"
);
MYSQL
*
con
=
connectToMySQLServer
();
MYSQL
*
con
=
connectToMySQLServer
();
puts
(
"Choose destination
\n
"
);
int
flightId
=
ShowDestinations
(
con
);
int
flightId
=
ShowDestinations
(
con
);
data
[
i
].
flight_id
=
flightId
;
data
[
i
].
flight_id
=
flightId
;
FillSeatmap
(
seatmap
,
ROWS
,
COLS
,
con
,
flightId
);
PrintSeats
(
seatmap
,
ROWS
,
COLS
);
while
(
cont
==
0
)
while
(
cont
==
0
)
{
{
printf
(
"
\n
Choose seat"
);
//kontroll
i ja plaani kuvamise funktsioon lisad
a
printf
(
"
\n
Choose seat"
);
//kontroll
lisamat
a
char
seat
[
SEAT_MAX
];
char
seat
[
SEAT_MAX
];
scanf
(
"%s"
,
seat
);
scanf
(
"%s"
,
seat
);
strcpy
(
data
[
i
].
seat
,
seat
);
strcpy
(
data
[
i
].
seat
,
seat
);
...
@@ -58,7 +64,10 @@ int main(void)
...
@@ -58,7 +64,10 @@ int main(void)
data
[
i
].
checkedIn
=
false
;
data
[
i
].
checkedIn
=
false
;
printf
(
"
\n
What luggage do you want to bring with you:"
);
printf
(
"
\n
What luggage do you want to bring with you"
);
puts
(
"
\n
0-Small bag + Carry-On(default included in fare),"
"1-Check-In 20kg suitcase, 2-Oversized(bikes, 20+kg)"
);
puts
(
"Enter value:"
);
int
luggage
;
int
luggage
;
scanf
(
"%d"
,
&
luggage
);
scanf
(
"%d"
,
&
luggage
);
data
[
i
].
luggageClass
=
luggage
;
data
[
i
].
luggageClass
=
luggage
;
...
@@ -71,6 +80,115 @@ int main(void)
...
@@ -71,6 +80,115 @@ int main(void)
}
}
}
}
void
FillSeatmap
(
int
seats
[
ROWS
][
COLS
],
int
rows
,
int
cols
,
MYSQL
*
con
,
int
flightId
)
{
char
query
[
512
];
sprintf
(
query
,
"SELECT seat FROM users WHERE flight_id = %d;"
,
flightId
);
if
(
mysql_query
(
con
,
query
))
{
//päring serverile
printf
(
"Error getting seat data: %s
\n
"
,
mysql_error
(
con
));
exit
(
EXIT_FAILURE
);
}
MYSQL_RES
*
result
=
mysql_store_result
(
con
);
int
num_fields
=
mysql_num_fields
(
result
);
char
temp
[
4
];
char
tempRow
[
3
];
int
tempRowInt
;
char
colNum
;
int
col
;
MYSQL_ROW
row
;
while
((
row
=
mysql_fetch_row
(
result
)))
{
for
(
int
i
=
0
;
i
<
num_fields
;
i
++
)
{
//printf("%s ", row[i] ? row[i] : "NULL");
strcpy
(
temp
,
row
[
i
]);
strncpy
(
tempRow
,
temp
,
2
);
tempRow
[
2
]
=
'\n'
;
tempRowInt
=
atoi
(
tempRow
);
colNum
=
temp
[
2
];
if
(
colNum
==
'A'
)
{
col
=
0
;
}
else
if
(
colNum
==
'B'
)
{
col
=
1
;
}
else
if
(
colNum
==
'C'
)
{
col
=
2
;
}
else
if
(
colNum
==
'D'
)
{
col
=
3
;
}
seats
[
tempRowInt
][
col
]
=
1
;
}
//printf("\n");
}
}
void
PrintSeats
(
int
data
[
ROWS
][
COLS
],
int
rows
,
int
cols
)
{
int
i
,
j
;
char
colId
;
printf
(
"
\n
Seats available :
\n
"
);
for
(
i
=
0
;
i
<
rows
;
i
++
)
{
for
(
j
=
0
;
j
<
cols
;
j
++
)
{
if
(
j
==
0
)
{
colId
=
'A'
;
}
else
if
(
j
==
1
)
{
colId
=
'B'
;
}
else
if
(
j
==
2
)
{
colId
=
'C'
;
}
else
if
(
j
==
3
)
{
colId
=
'D'
;
}
if
(
data
[
i
][
j
]
==
1
)
{
printf
(
"
\033
[0;31m"
);
printf
(
" X "
);
printf
(
"
\033
[0m"
);
}
else
if
(
data
[
i
][
j
]
==
0
)
{
printf
(
"
\033
[0;32m"
);
if
(
i
<
10
)
printf
(
"0%d%c"
,
i
,
colId
);
else
printf
(
"%d%c"
,
i
,
colId
);
printf
(
"
\033
[0m"
);
}
if
(
j
==
1
)
printf
(
"
\t
"
);
else
printf
(
" "
);
}
printf
(
"
\n
"
);
}
}
void
insertPersonIntoTable
(
MYSQL
*
con
,
users
data
)
void
insertPersonIntoTable
(
MYSQL
*
con
,
users
data
)
{
{
char
query
[
1024
];
//salvestan mysql päringu stringi
char
query
[
1024
];
//salvestan mysql päringu stringi
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment