Program Parkir Dengan Bahasa C
DOWNLOAD === https://byltly.com/2tuQAS
How to Create a Parking Program Using C Language
A parking program is a software application that can manage the entry and exit of vehicles in a parking area. It can also calculate the parking fee based on the duration of stay and the type of vehicle. In this article, we will learn how to create a simple parking program using C language, one of the most popular and versatile programming languages in the world.
C language is a low-level language that can directly interact with the hardware and operating system. It is widely used for system programming, embedded systems, and software development. C language has a simple syntax and structure, but it also offers powerful features such as pointers, arrays, structures, functions, and file handling.
To create a parking program using C language, we need to follow these steps:
Define the variables and constants that we will use in the program. For example, we can use an integer variable to store the vehicle type (1 for car, 2 for motorcycle), a float variable to store the parking fee per hour, a char array to store the vehicle plate number, a structure to store the date and time information, and so on.
Get the input from the user, such as the vehicle type, plate number, entry time, and exit time. We can use scanf() function to read the input from the keyboard, or we can use fopen() and fscanf() functions to read the input from a file.
Calculate the parking fee based on the input. We can use if-else statements to check the vehicle type and apply different rates accordingly. We can also use arithmetic operators to calculate the duration of stay and multiply it by the parking fee per hour.
Display the output to the user, such as the vehicle plate number, entry time, exit time, duration of stay, and parking fee. We can use printf() function to print the output to the screen, or we can use fopen() and fprintf() functions to write the output to a file.
Here is an example of a parking program using C language:
// Define constants
#define CAR_RATE 3000 // Parking fee per hour for car
#define MOTOR_RATE 2000 // Parking fee per hour for motorcycle
#define MAX_PLATE 10 // Maximum length of plate number
// Define structure for date and time
struct datetime {
int year;
int month;
int day;
int hour;
int minute;
int second;
};
// Declare functions
void get_input(int *type, char *plate, struct datetime *entry);
void get_output(char *plate, struct datetime *entry, struct datetime *exit);
float calculate_fee(int type, struct datetime *entry, struct datetime *exit);
float get_duration(struct datetime *entry, struct datetime *exit);
// Main function
int main()
{
// Declare variables
int type; // Vehicle type (1 for car, 2 for motorcycle)
char plate[MAX_PLATE]; // Vehicle plate number
struct datetime entry; // Entry date and time
struct datetime exit; // Exit date and time
// Get input from user
get_input(&type, plate, &entry);
// Get current date and time as exit time
time_t t = time(NULL);
struct tm *tm = localtime(&t);
exit.year = tm->tm_year + 1900;
exit.month = tm->tm_mon + 1;
exit.day = tm->tm_mday;
exit.hour = tm->tm_hour;
exit.minute = tm->tm_min;
exit.second = tm->tm_sec;
// Display output to user
get_output(plate, &entry, &exit);
return 0;
}
// Function to get input from user
void get_input(int *type, char *plate, struct datetime *entry)
{
// Ask user for vehicle type
printf(\"Enter vehicle type (1 for car, 2 for motorcycle): \");
scanf(\"%d\", type);
// Ask user for plate number
printf(\"Enter plate number: \");
scanf(\"%s\", plate);
// Ask user for entry date and time
printf(\" ec8f644aee