Skip to content

Commit

Permalink
[Output/Style] Block Comments and Print Statements devprnvk
Browse files Browse the repository at this point in the history
  • Loading branch information
devprnvk committed Jun 11, 2024
1 parent 27d3ba6 commit e9e22a9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
20 changes: 18 additions & 2 deletions display.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Handles functions related to displaying information on the console.
* This could include functions for printing tables and data information.
*
* @file Display.c
* @author Pranav Kale pkale
*/
Expand All @@ -13,6 +14,13 @@
#include "flights.h"
#include "input.h"

/**
Compare countries a and b
This method is used as a comparator for the QSort() method
@param a void constant pointer to first country
@param b void constant pointer to second country
@return string comparison of both
*/
int compareCountries(const void *a, const void *b) {
return strcmp((*(CountryNode **)a)->country, (*(CountryNode **)b)->country);
}
Expand Down Expand Up @@ -114,12 +122,13 @@ void displaySingleFlightData(FlightDatabase *fdatab, char const *str) {
char * adding;
adding = readLine(stdin);
if (strcmp(adding, "more data") == 0) {

double avgMile = calculateAverageMilesPerFlight(flight->totalMiles, flight->totalTrips);
char *fTime = calculateFlightTime(flight->departTime, flight->arrivalTime);
double earnings = calculateTotalRevenue(flight->seats, 409.99)
printf("\nThis plane's average miles per trip: %.2f miles\n", avgMile);
printf("Total Travel Duration is %s\n", fTime);
free(fTime); // Freeing the allocated memory
printf("Total Expected Earnings: %f\n", earnings);
free(fTime);
}
break;
}
Expand All @@ -132,12 +141,19 @@ void displaySingleFlightData(FlightDatabase *fdatab, char const *str) {
}
}

/**
* Display the Header for the Airport Information to Console
*/
void dispAirportHeader()
{
printf("| Country | Airport |\n");
printf("|-----------------+-----------------------+\n");
}

/**
Display all available airports in the current flight database
@param fdatab the database to check
*/
void displayAllAirports(FlightDatabase *fdatab) {
HashTable *table = createTable(TABLE_SIZE);

Expand Down
12 changes: 10 additions & 2 deletions display.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Header file for the Main C program
*
* @file display.h
* @author Pranav Kale
*/
Expand All @@ -9,13 +10,20 @@
#ifndef DISPLAY_H
#define DISPLAY_H


void displayFlightTableRow(FlightDatabase *fdatab);
void displayFlightTableHeader();
void clearConsole();
void displayMenuOptions(const char options[][50]);
/**
* Display the Header for the Airport Information to Console
*/
void dispAirportHeader();
void displaySingleFlightData(FlightDatabase *fdatab, char const *str);
void displayAllAirports(FlightDatabase *fdatab);
/**
Display all available airports in the current flight database
@param fdatab the database to check
*/
void displayAllAirports(FlightDatabase *fdatab)
void displayApp();

#endif
12 changes: 9 additions & 3 deletions flights.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ void insertAirport(HashTable *table, const char *country, const char *airport) {
countryNode->airports = airportNode;
}

/**
Calculate all the Average Miles per Flight
Allows customer to know usual flight miles on each travel
@param miles the mileage of plane
@param trips the # of trips the plane has chartered
@return avgMiles the average miles per trip
*/
double calculateAverageMilesPerFlight(double miles, int trips) {
double average = (double) miles / trips;
return average;
Expand All @@ -168,7 +175,7 @@ double calculateAverageMilesPerFlight(double miles, int trips) {
*/
char* calculateFlightTime(const char departTime[], const char arrivalTime[])
{
int departHour, departMinutes, arrivalHour, arrivalMinutes;
int departHour, departMinutes, arrivalHour, arrivalMinutes;
char departFormat[3], arrivalFormat[3];

sscanf(departTime, "%d:%d %2s", &departHour, &departMinutes, departFormat);
Expand All @@ -193,7 +200,7 @@ char* calculateFlightTime(const char departTime[], const char arrivalTime[])
int minutes = totalMinutes % 60;

char* time = (char*)malloc(30);
// Format the result

sprintf(time, "%d hours and %d minutes", hours, minutes);
return time;
}
Expand All @@ -204,7 +211,6 @@ char* calculateFlightTime(const char departTime[], const char arrivalTime[])
*/
double calculateTotalRevenue(int numSeats, double pricePerSeat)
{
// Calculate price of seats using fixed price
double price = numSeats * pricePerSeat;
return price;
}
Expand Down
6 changes: 6 additions & 0 deletions flights.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ double calculateAverageMilesPerFlight(double miles, int trips);
*/
char* calculateFlightTime(const char departTime[], const char arrivalTime[]);

/**
* Calculate the total revenue of the flight
* Take the number of seats and multiply by fixed price
*/
double calculateTotalRevenue(int numSeats, double pricePerSeat);

/**
Insert an airport into the hash table
Use the provided information to traverse the table
Expand Down

0 comments on commit e9e22a9

Please sign in to comment.