Notes
Notes - notes.io |
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node {
char nama_barang[100];
float harga;
float diskon;
int jumlah;
struct Node* next;
};
struct Node* head = NULL;
void tambah_simpul(char nama_barang[100], float harga, float diskon, int jumlah) {
struct Node* node_baru = (struct Node*)malloc(sizeof(struct Node));
strcpy(node_baru->nama_barang, nama_barang);
node_baru->harga = harga;
node_baru->diskon = diskon;
node_baru->jumlah = jumlah;
node_baru->next = NULL;
if (head == NULL || strcmp(nama_barang, head->nama_barang) < 0) {
node_baru->next = head;
head = node_baru;
} else {
struct Node* current = head;
while (current->next != NULL && strcmp(nama_barang, current->next->nama_barang) > 0) {
current = current->next;
}
node_baru->next = current->next;
current->next = node_baru;
}
}
void hapus_diskon_nol() {
struct Node* current = head;
struct Node* previous = NULL;
while (current != NULL) {
if (current->diskon == 0) {
if (current == head) {
head = current->next;
free(current);
current = head;
} else {
previous->next = current->next;
free(current);
current = previous->next;
}
} else {
previous = current;
current = current->next;
}
}
}
void tampilkan_harga_diatas_rata() {
float total_harga = 0;
int count = 0;
struct Node* current = head;
while (current != NULL) {
total_harga += current->harga;
count++;
current = current->next;
}
float rata_rata = total_harga / count;
current = head;
printf("Barang dengan harga di atas rata-rata:n");
while (current != NULL) {
if (current->harga > rata_rata) {
printf("%s: Harga = %.2fn", current->nama_barang, current->harga);
}
current = current->next;
}
}
float total_harga() {
float total = 0;
struct Node* current = head;
while (current != NULL) {
total += (current->harga - (current->diskon / 100.0) * current->harga) * current->jumlah;
current = current->next;
}
return total;
}
int main() {
// Tambahkan simpul
tambah_simpul("Barang A", 100, 0, 2);
tambah_simpul("Barang B", 150, 10, 3);
tambah_simpul("Barang C", 200, 0, 1);
tambah_simpul("Barang D", 120, 5, 4);
// Tampilkan data awal
struct Node* current = head;
printf("Data awal:n");
while (current != NULL) {
printf("%s: Harga = %.2f, Diskon = %.2f%%, Jumlah = %dn", current->nama_barang, current->harga, current->diskon, current->jumlah);
current = current->next;
}
// Hapus data dengan diskon 0%
hapus_diskon_nol();
// Tampilkan data setelah penghapusan
current = head;
printf("nData setelah menghapus diskon 0%%:n");
while (current != NULL) {
printf("%s: Harga = %.2f, Diskon = %.2f%%, Jumlah = %dn", current->nama_barang, current->harga, current->diskon, current->jumlah);
current = current->next;
}
// Tampilkan barang dengan harga di atas rata-rata
tampilkan_harga_diatas_rata();
// Tampilkan total harga
float total = total_harga();
printf("nTotal Harga: %.2fn", total);
return 0;
}
```
Anda dapat menyalin dan menjalankan kode di atas dalam bahasa C. Ini menciptakan struktur data penjualan barang dengan beberapa operasi yang Anda minta. Pastikan Anda menggantinya dengan data dan aturan yang sesuai untuk kasus Anda.
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team