Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
otsall
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3a9fb83f
authored
Nov 12, 2018
by
otsall
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace homework2.c
parent
d1b49423
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
12 deletions
Homework2/homework2.c
Homework2/homework2.c
View file @
3a9fb83f
#include <stdio.h>
//constant for the maximum number of carriers/destinations
#define MAXSIZE 15
//function prototypes
void
fillMatrix
(
int
flights
[][
MAXSIZE
],
int
dest
,
int
carrier
);
void
printMatrix
(
int
flights
[][
MAXSIZE
],
int
dest
,
int
carrier
);
void
totalFlights
(
int
flights
[][
MAXSIZE
],
int
sum
[],
int
dest
,
int
carrier
);
void
busiestCarrier
(
int
sum
[],
int
carrier
);
int
main
()
{
int
dest
,
carrier
;
//this is here because exciting the fillMatrix function otherwise changes the value of dest or carrier
int
cartonBuffer
[
MAXSIZE
];
//user inputs or file contains the number of destinations and carriers, which can only be positive and nonzero
puts
(
"please input the number of destinations"
);
scanf
(
"%d"
,
&
dest
);
while
(
dest
>
MAXSIZE
||
dest
<
1
){
...
...
@@ -24,9 +26,12 @@ int main() {
printf
(
"the number of carriers has to be between 1 and %d, try again
\n
"
,
MAXSIZE
);
scanf
(
"%d"
,
&
carrier
);
}
//an empty array called flightPlan is created in addition to an array called sum which will be used later
int
flightPlan
[
dest
][
carrier
],
sum
[
carrier
];
fillMatrix
(
flightPlan
,
dest
,
carrier
);
printMatrix
(
flightPlan
,
dest
,
carrier
);
...
...
@@ -38,6 +43,10 @@ int main() {
return
0
;
}
/* function takes in the empty array of flights and fills it with flights
* using a nested for loop based on user input or file.
* If the number of flights is negative, it asks for new input
*/
void
fillMatrix
(
int
flights
[][
MAXSIZE
],
int
dest
,
int
carrier
){
int
i
,
j
;
...
...
@@ -51,31 +60,33 @@ void fillMatrix(int flights[][MAXSIZE], int dest, int carrier){
scanf
(
"%d"
,
&
flights
[
i
][
j
]);
}
}
}
}
return
;
}
/*function uses the filled array of flights and the number of
* destinations and carriers to print out the array in full
*/
void
printMatrix
(
int
flights
[][
MAXSIZE
],
int
dest
,
int
carrier
){
int
i
,
j
;
puts
(
"Flights : "
);
printf
(
" "
);
for
(
i
=
0
;
i
<
carrier
;
i
++
){
printf
(
"C%
d,
"
,
i
+
1
);
printf
(
"C%
-3d
"
,
i
+
1
);
}
printf
(
"
\n
"
);
for
(
i
=
0
;
i
<
dest
;
i
++
){
printf
(
"DESTINATION%d "
,
i
+
1
);
for
(
j
=
0
;
j
<
carrier
;
j
++
){
printf
(
"%
d
"
,
flights
[
i
][
j
]);
printf
(
"%
-3d
"
,
flights
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
return
;
}
/*the function takes the flightplan array and the numbers of destinations and carriers to
* fill the array "sum" with the sums of flights for each carrier and prints them out.
*/
void
totalFlights
(
int
flights
[][
MAXSIZE
],
int
sum
[],
int
dest
,
int
carrier
){
int
i
,
j
,
...
...
@@ -89,11 +100,14 @@ void totalFlights(int flights[][MAXSIZE],int sum[], int dest, int carrier){
}
printf
(
" TOTAL "
);
for
(
i
=
0
;
i
<
carrier
;
i
++
){
printf
(
"%
d
"
,
sum
[
i
]);
printf
(
"%
-4d
"
,
sum
[
i
]);
}
return
;
}
/*the function uses the array of sums of flights and the carrier number to find the largest value
* in the array - the busiest carrier. This value is used to recheck the array for the same value to print out
* as the busiest carriers.
*/
void
busiestCarrier
(
int
sum
[],
int
carrier
){
int
i
,
j
=
0
,
...
...
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