/*
I want to fix void make_flight(int counter, flight_t flights[])
Enter flight code>
Enter departure info for the flight leaving SYD.
Enter month, date, hour and minute separated by spaces>
Enter arrival city code>
Enter arrival info.
Enter month, date, hour and minute separated by spaces>
It should do all of this:
1-Flight - left aligned, MAX_FLIGHTCODE_LEN (i.e. 6) chars at most.
2-City - left aligned, MAX_CITYCODE_LEN 3 chars at most . For example( VA1 or LAX )
3- Month, day, hour, minute - two digits with leading zeros
Your program should be able to check the format of the flightcode.
The first two characters of the flightcode must be uppercase letters (A-Z)
representing the airline. The rest of the flightcode should be numerals (0-9)
representing the flight number.
There must be 1-4 numerals as the flight number part of the flightcode.
No spaces in the flightcode.
*/
Month, day, hour, minute - two digits with leading zeros
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_FLIGHTCODE_LEN 6
#define MAX_CITYCODE_LEN 3
#define MAX_NUM_FLIGHTS 5
#define DB_NAME "database"
struct date_time
{
int minute;
int hour;
int day;
int month;
};
typedef struct date_time date_time_t;
struct flight
{
char flightcode [MAX_FLIGHTCODE_LEN+1];
date_time_t departure_t;
char arrival_city [MAX_CITYCODE_LEN+1];
date_time_t arrival_t;
};
typedef struct flight flight_t;
void print_menu (void);
void make_flight(int counter, flight_t f[]);
int check_flight(int counter, flight_t flights[], char f[MAX_FLIGHTCODE_LEN+1]);
void print_flight(int counter, flight_t flights[], char f[MAX_FLIGHTCODE_LEN+1]);
void print_flights_all(int counter, flight_t flights[counter]);
int write_flight(flight_t flights[], int counter);
int read_flight(flight_t flights[], int counter);
/*******************************************************************************
* Main
*******************************************************************************/
int main(void)
{
int choice;
char second_choice[MAX_FLIGHTCODE_LEN+1];
int counter=0;
int test;
flight_t flights[MAX_NUM_FLIGHTS];
do
{
fflush(stdin);
print_menu();
scanf("%d", &choice);
switch(choice)
{
case 1:
{
make_flight(counter, flights);
counter++;
break;
}
case 2:
{
printf("Enter arrival city code or enter * to show all destinations>\n");
scanf("%s",second_choice);
if (second_choice[0]=='*')
{
print_flights_all(counter, flights);
}
else if (counter<=0)
{
printf("No flights\n");
}
else
{
test=check_flight(counter, flights, second_choice);
if (test==0)
{
printf("No flights\n");
}
else
{
print_flight(counter, flights, second_choice);
}
}
break;
}
case 3:
{
write_flight(flights, counter);
break;
}
case 4:
{
int read_counter;
FILE* fpr = NULL;
fpr = fopen(DB_NAME, "r");
if (fpr == NULL)
{
printf("Read error\n");
break;
}
fscanf(fpr, "%d", &counter);
for (read_counter=0; read_counter<counter; read_counter++)
{
fprintf(fpr, "%-6.6s SYD %02d-%02d %02d:%02d %-3.3s %02d-%02d %02d:%02d\n", flights[read_counter].flightcode, flights[read_counter].departure_t.month, flights[read_counter].departure_t.day, flights[read_counter].departure_t.hour, flights[read_counter].departure_t.minute, flights[read_counter].arrival_city, flights[read_counter].arrival_t.month, flights[read_counter].arrival_t.day, flights[read_counter].arrival_t.hour, flights[read_counter].arrival_t.minute);
}
fclose(fpr);
break;
}
case 5:
{
exit(1);
break;
}
default:
{
printf("Invalid choice\n");
break;
}
}
}
while(choice!=5);
return 0;
}
void print_menu (void)
{
printf("\n"
"1. add a flight\n"
"2. display all flights to a destination\n"
"3. save the flights to the database file\n"
"4. load the flights from the database file\n"
"5. exit the program\n"
"Enter choice (number between 1-5)>\n");
}
void make_flight(int counter, flight_t flights[])
{
printf("Enter flight code>\n");
scanf("%s", flights[counter].flightcode);
printf("Enter departure info for the flight leaving SYD.\n");
do
{
printf("Enter month, date, hour and minute separated by spaces>\n");
scanf("%d %d %d %d", &flights[counter].departure_t.month, &flights[counter].departure_t.day, &flights[counter].departure_t.hour, &flights[counter].departure_t.minute);
if (12<flights[counter].departure_t.month|| flights[counter].departure_t.month<=0 || 31<flights[counter].departure_t.day || flights[counter].departure_t.day<=0 || 24<=flights[counter].departure_t.hour || flights[counter].departure_t.hour<0 || 60<=flights[counter].departure_t.minute || flights[counter].departure_t.minute<0)
{
printf("Invalid input\n");
}
} while (12<flights[counter].departure_t.month|| flights[counter].departure_t.month<=0 || 31<flights[counter].departure_t.day || flights[counter].departure_t.day<=0 || 24<=flights[counter].departure_t.hour || flights[counter].departure_t.hour<0 || 60<=flights[counter].departure_t.minute || flights[counter].departure_t.minute<0);
printf("Enter arrival city code>\n");
scanf("%s", flights[counter].arrival_city);
printf("Enter arrival info.\n");
do
{
printf("Enter month, date, hour and minute separated by spaces>\n");
scanf("%d %d %d %d", &flights[counter].arrival_t.month, &flights[counter].arrival_t.day, &flights[counter].arrival_t.hour, &flights[counter].arrival_t.minute);
if (12<flights[counter].arrival_t.month|| flights[counter].arrival_t.month<=0 || 31<flights[counter].arrival_t.day || flights[counter].arrival_t.day<=0 || 24<=flights[counter].arrival_t.hour || flights[counter].arrival_t.hour<0 || 60<=flights[counter].arrival_t.minute || flights[counter].arrival_t.minute<0)
{
printf("Invalid input\n");
}
} while (12<flights[counter].arrival_t.month|| flights[counter].arrival_t.month<=0 || 31<flights[counter].arrival_t.day || flights[counter].arrival_t.day<=0 || 24<=flights[counter].arrival_t.hour || flights[counter].arrival_t.hour<0 || 60<=flights[counter].arrival_t.minute || flights[counter].arrival_t.minute<0);
}
int check_flight(int counter, flight_t flights[], char second_choice[MAX_FLIGHTCODE_LEN+1])
{
int second_counter;
int incrementer=0;
for (second_counter=0; second_counter<1; second_counter++)
{
if (strncmp(second_choice, flights[second_counter].arrival_city,4)==0)
{
incrementer++;
}
}
return incrementer;
}
/*
I've added two new functions for validation
insert in your code as shown
I've fixed the validations, this should work
also make your problem more clear weather the whole program is to be solved
*/
int check_filghtcode(char *fc) {
int ret = fc[0] >= 'A' && fc[0] <= 'Z'
&&
fc[1] >= 'A' && fc[1] <= 'Z' &&
fc[2] >= '0' && fc[2] <= '9', i;
for(i = 3; fc[i] != '\0'; i++) {
if(!(fc[i] >= '0' && fc[i] <= '9'))
return 0;
}
return ret && i < 7;
//checks if the string has ended
//returns 1 is success, 0 if failed
}
int check_date(int month, int date, int hour, int minute)
{
int days[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30,
31};
return month >= 0 && month < 12 &&
date >= 0 && date < days[month] &&
hour >= 0 && hour < 23 &&
minute >= 0 && minute < 59;
}
void make_flight(int counter, flight_t flights[]) {
do {
printf("Enter flight code>\n");
scanf("%s", flights[counter].flightcode);
if(check_filghtcode(flights[counter].flightcode) != 1)
printf("INvalid input\n");
} while(check_filghtcode(flights[counter].flightcode) != 1);
printf("Enter departure info for the flight leaving
SYD.\n");
do {
printf("Enter month, date, hour and minute separated by
spaces>\n");
scanf("%d %d %d %d", & flights[counter].departure_t.month,
& flights[counter].departure_t.day, &
flights[counter].departure_t.hour, &
flights[counter].departure_t.minute);
if (check_date(
flights[counter].departure_t.month,
flights[counter].departure_t.day,
flights[counter].departure_t.hour,
flights[counter].departure_t.minute
) != 1) {
printf("Invalid input\n");
}
} while (check_date(
flights[counter].departure_t.month,
flights[counter].departure_t.day,
flights[counter].departure_t.hour,
flights[counter].departure_t.minute
) != 1);
printf("Enter arrival city code>\n");
scanf("%s", flights[counter].arrival_city);
printf("Enter arrival info.\n");
do {
printf("Enter month, date, hour and minute separated by
spaces>\n");
scanf("%d %d %d %d", & flights[counter].arrival_t.month, &
flights[counter].arrival_t.day, &
flights[counter].arrival_t.hour, &
flights[counter].arrival_t.minute);
if (check_date(
flights[counter].arrival_t.month,
flights[counter].arrival_t.day,
flights[counter].arrival_t.hour,
flights[counter].arrival_t.minute
) != 1){
printf("Invalid input\n");
}
} while (check_date(
flights[counter].arrival_t.month,
flights[counter].arrival_t.day,
flights[counter].arrival_t.hour,
flights[counter].arrival_t.minute
) != 1);
}
/* I want to fix void make_flight(int counter, flight_t flights[]) Enter flight code> Enter departure info...
Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int *); void replaceAt(int *, int, int); int isEmpty(int *, int); int isFull(int *, int); void removeAt(int *, int); void printList(int *, int); int main() { int *a; int arraySize=0,l=0,loc=0; int choice; while(1) { printf("\n Main Menu"); printf("\n 1.Create list\n 2.Insert element at particular position\n 3.Delete list.\n4. Remove an element at given position \n 5.Replace an element at given position\n 6. Check the size of...
#include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here. */ int GetNumOfNonWSCharacters(const char usrStr[]) { int length; int i; int count = 0; char c; length=strlen(usrStr); for (i = 0; i < length; i++) { c=usrStr[i]; if ( c!=' ' ) { count++; } } return count; } int GetNumOfWords(const char usrStr[]) { int counted = 0; // result // state: const char* it = usrStr; int inword = 0; do switch(*it)...
Question: Please Provide Comments on each Line of code explaining what the C Function is doing throughout the code. // Function used for substitution encryption void SubEncrypt(char *message, char *encryptKey) { int iteration = 0; printf("Enter Aphabet Encryption Key: \n"); scanf("%s", encryptKey); for (iteration = 0; iteration < strlen(message); iteration++) { char letter = message[iteration]; if (letter >= 'A' && letter <= 'Z') { letter = encryptKey[letter - 'A']; } message[iteration] = letter; } printf("CipherText message: %s\n", message); } //_________________________________________________________________________________________________________________________________________________...
Description Data Engineers regularly collect, process and store data. In this task you will develop a deeper understanding of how C programming language can be used for collecting, processing and storing data. In this assignment you get the opportunity to build an interactive program that can manage the list of flights departing Sydney Airport. The list is stored as an array of flight_t type structures flight_t flights [MAX_NUM_FLIGHTS]; The flight_t is a structure typedef for struct flight. The struct flight...
create case 4 do Method 1:copy item by item and skip the item you want to delete after you are done, delete the old file and rename the new one to the old name. #include int main(void) { int counter; int choice; FILE *fp; char item[100]; while(1) { printf("Welcome to my shopping list\n\n"); printf("Main Menu:\n"); printf("1. Add to list\n"); printf("2. Print List\n"); printf("3. Delete List\n"); printf("4. Remove an item from the List\n"); printf("5. Exit\n\n"); scanf("%i", &choice); switch(choice) { case 1:...
Hardware Inventory – Write a database to keep track of tools, their cost and number. Your program should initialize hardware.dat to 100 empty records, let the user input a record number, tool name, cost and number of that tool. Your program should let you delete and edit records in the database. The next run of the program must start with the data from the last session. This is my program so far, when I run the program I keep getting...
This code in c evaluates a mathematical expression and checks that it is correctly balanced, then converts the expression to its postfix form (This part works). Now I need to evaluate the postfix expression with a function. I've been compiling it using dev c ++. #include #include #define SIZE 20 #include int profundidad(char expresion[]); int prec(char op1, char op2); void postfijo(char expresion[]); char funcion[SIZE]; float convierte(char car); float resultado(float opnd1, char symb, float opnd2); float evaluar(char expresion[]); #define SIZE 20...
Can someone fix my coding please it's a calendar some days are placed wrong. I just want the Main menu to display first and second option and four option to end the program properly. Please remove option number 3 Find the number of days between 2 selected dates and the code that belongs to this function. #include<stdio.h> void days(int,int,int,int,int,int); int month(int,int); int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31}; #define TRUE 1 #define FALSE 0 int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; char *months[]= { " ", "\n\n\nJanuary", "\n\n\nFebruary", "\n\n\nMarch", "\n\n\nApril",...
C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...
Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...