Student Weight Program with Single Linked List (SWPSLL)

Instruction:

1]. Make 3 groups in one class, moderator, operator, presenter, and those who answer questions can take turns.

2]. Each group creates an assignment for presentation based on the questions below.

3]. Create a printed report to be collected and a power point for presentation.

4]. The report structure consists of:

  • a. Problems
  • b. Discussion (explain the functions formed and the function operations)
  • c. Complete program and capture running.

5]. Create a program using a linked list to enter data with the menu:

  • a. Add
  • b. Edit
  • c. Delete
  • d. Search
  • e. Done

Your choice [a..e]

In the structure there are unique fields (eg student number, employee number, etc.) that are used for identification. Data storage is sorted according to its unique field. The process of adding and deleting will place the data according to its order.

6]. Create a program using a double linked list to enter data with the menu:

  • a. Add
  • b. Edit
  • c. Delete
  • d. Search
  • e. Done

Your choice [a..e]

In the structure there are unique fields (eg student number, employee number, etc.) that are used for identification. Data storage is sorted according to its unique field. The process of adding and deleting will place the data according to its order.

7]. Create a program using a stack to enter data with the menu:

  • a. Add
  • b. Edit
  • c. Delete
  • d. Search
  • e. Done

Your choice [a..e]

In the structure there are unique fields (eg student number, employee number, etc.) used for identification. Data storage is sorted according to its unique field. The process of adding/deleting using push and pop only.

Completion

DATA STRUCTURE ASSIGNMENT
OF STUDENT WEIGHT DATA PROGRAM WITH SINGLE LINKEDLIST
Lecturer: Eko Riswanto, ST, M.Cs

Compiled By:

|     1.     |     Agus Suroto                  |     (12131246)    |
|------------|----------------------------------|-------------------|
|     2.     |     Alifa Titi Subekti           |     (12131247)    |
|     3.     |     Ana Alfiatun                 |     (12131248)    |
|     4.     |     Anggi Nurcahyo               |     (12131249)    |
|     5.     |     Dwi Susanto                  |     (12131255)    |
|     6.     |     Erik Tri Yunianta            |     (12131257)    |
|     7.     |     Erwan Sulistyo               |     (12131258)    |
|     8.     |     Eva Alfian Sidiq Nurzaman    |     (12131260)    |
|     9.     |     Fery Rudiyanto               |     (12131263)    |
|     10.    |     Isni Fauzan                  |     (12131266)    |
|     11.    |     Hanung Riyadi                |     (12131267)    |
|     12.    |     Muhamad Rizal                |     (12131272)    |
|     13.    |     Wawan Chahyo Nugroho         |     (12131294)    |

FOREWORD

The author would like to express his gratitude to the presence of Allah SWT who has given his grace and guidance so that we can complete the assignment of the Data Structure course on the topic "Creating a Student Weight Data Program" in the form of a paper. In compiling this assignment or material, there are many obstacles that the author faces. However, the author realizes that the smoothness in compiling this material is none other than thanks to the help, encouragement and guidance of the lecturer, Mr. Eko Riswanto and fellow students so that the obstacles that the author faces can be overcome.

Therefore we express our deepest gratitude. The author also expects suggestions and criticisms from readers so that for the creation of other written works, it can provide better ones. Hopefully the material for making this program can be useful and become a contribution of thought for those in need, especially for the author so that the expected goals can be achieved, amen.

January 2015

CHAPTER I - DISCUSSION

1. Background of the Problem

In this discussion, the author provides an explanation of the Student Weight Data Program According to BMI with Single Linked List. The program is made with the development of a data structure that includes Single Linklist, Sorting and Searching.

The program reference created is from assignment question no. 1:

Create a program using a single link list to enter data with the menu:

  • a. Add
  • b. Edit
  • c. Delete
  • d. Search
  • e. Done

In the structure there are unique fields (eg student number, employee number, etc.) that are used for identification. Data storage is sorted according to its unique field. The process of adding and deleting will place the data according to its order.

From the above question, we decided to create a Student Weight Data Program, which will include the add, edit, delete and search menus like the question above. For more details will be explained in the following discussion.

2. Program Discussion

2.1. Programs that are arranged 

Program Title: STUDENTS' BODY WEIGHT DATA ACCORDING TO THE BODY MASS INDEX FORMULA

Data used:

  • Student Data with unique NIM field
  • Weight Calculation Data

Data generated:

Displays student weight data that can be processed.

2.2. Program Flowchart Image

Program Flowchart Image

2.3. Functions used

  1. Function inputDataMhs(int nmr)
  2. delay(int a) function
  3. Function print_middle(int brs, char *text)
  4. count() function
  5. Function checkData(int nr)
  6. Function add(int number )
  7. Function add_middle_list(int nr, int insert_position)
  8. Function add_start_node(int nmr)
  9. Function add_final_node(int nr)
  10. InputData(int nmr) function
  11. SearchData(int nmr) function
  12. Delete(int nim) function
  13. show_list() function
  14. EditData(int nmr) function
  15. Main() function

2.4. Definition of each function and its operations

1.struct node

The following are pointer and node declarations, namely nim, name, age, height, weight, *next, *head, *position and select.

struct node {
    int nim;
    char nama[20];
    int umur;
    float tinggi;
    float berat;
    node *next;
 } *head;

 node *posisi;
 int pilih;

2. Function delay(int a);

This function is useful for displaying the loading process when we input, delete, search and edit data.

void delay(int a)
    {
        for(int x=0;x<a*100;x++)
        {
            for(int y=0;y<a*100;y++)
                {
                }
    }
}

3. Function inputDataMhs(int nmr);

This function is useful for filling data on the node created at the beginning of the program, namely name, age, height and weight. This data will be processed next, whether it will be deleted, searched, edited and displayed. As a reference, temp->nim is used the same as nmr.

void inputDataMhs(int nmr)
 {
    struct node *temp;
    cout << "Masukkan Nama     : ";   cin >> temp->nama;
    cout << "Masukkan Umur     : ";   cin >> temp->umur;
    cout << "Masukkan tingggi  : ";   cin >> temp->tinggi;
    cout << "Masukkan Berat    : ";   cin >> temp->berat;
    temp->nim=nmr;
 }

4. Print_center function(int brs, char *text)

This function is just to provide a display so that it appears in the center of the screen.

void cetak_tengah(int brs, char *teks)
{
    gotoxy(40-strlen(teks)/2,brs);cout<<teks;
}

5. count() function

This function is used to calculate the amount of inputted data. The reference is how many data are in the linklist. First, create node n. With c equal to 0. n here is the same as head, as long as n is not equal to null then run n equals n->next, c will increase by 1, and will return to c if n is equal to null.

int count()
{
    struct node *n;
    int c=0;
    n=head;
    while(n!=NULL)
    {
        n=n->next;
        c++;
    }
    return c;
}

6. Function checkData(int nmr)

This function is useful for checking whether there is duplicate data or not when inputting the second data and so on. Because the reference is to the nim variable, nim must not be duplicate. First, create a new node, namely temp. And temp is the same as head, as long as temp is not equal to null, it will be executed, if temp->nim is the same as nmr, it will return a false value. Otherwise, it will return a true value and temp is the same as temp->next.

bool cekData(int nmr)
{
    struct node *temp;
    temp=head;
    while(temp!=NULL)
    {
        if(temp->nim == nmr)
            return false;
        else
            return true;
    temp=temp->next;
    }
    return true;
}

7. Function add(int number)

This function is to add data to the linklist. The data on this node that will be processed is where this node is placed in the linklist, whether at the beginning, in the middle or at the end of the linklist. For processing will be done by the InputData(int nmr); function. First create a struct node *temp, temp = new node, then call the inputDataMhs(nmr) function; if head is null, head is equal to temp, head next is given a null value, temp next is equal to head, head is equal to temp.

void tambah(int nmr )
{
    struct node *temp;
    temp = new node;
    inputDataMhs(nmr);
    if (head== NULL)
    {
        head=temp;
        head->next=NULL;
    }
    else
    {
        temp->next=head;
        head=temp;
    }
}

8. Function add_middle_list(int nr, int insert_position)

This function is to add a node in the middle of the selection result of the InputData(int nmr); function so that the insertion position is obtained. If the insertion position is outside the range of the linked list, namely if the position is less than 1, then the process carried out is the process of adding data at the beginning, and if it exceeds the amount of data in the linked list (>) from the amount of data, then the process carried out is the process of adding data at the end. And if it is within the range of the linklist, then just follow the insertion position.

First create node *temp and *bantu, bantu equals head, temp equals new node, and repeat until i is less than insertion_position s-- 1(insert is less than one) if bantu->next is not equal to null, then bantu is equal to bantu->next, else stop. Next input student data.

void tambah_tengah_list(int nmr, int posisi_sisip)
{
     node *temp, *bantu;
     bantu=head;
     temp =new node;
     for(int i=1;i<posisi_sisip-1;i++)
     {
        if(bantu->next != NULL)
            bantu=bantu->next;
 else
            break;
     }
    cout << "Masukkan Nama     : ";   cin >> temp->nama;
    cout << "Masukkan Umur     : ";   cin >> temp->umur;
    cout << "Masukkan tingggi  : ";   cin >> temp->tinggi;
    cout << "Masukkan Berat    : ";   cin >> temp->berat;
    temp->nim=nmr;
    temp->next=bantu->next;
    bantu->next=temp;
}

8. Function add_node_initial(int nmr)

It is a function to add data at the beginning of the node. First create a node *temp, temp is filled in the new node. Then call the inputDataMhs(nmr) function.

void tambah_simpul_awal(int nmr)
{
  node *temp;
  temp = new node;
  inputDataMhs(nmr);
  temp->next = NULL;
  temp->next = head;
  head = temp;
}

9. Function add_final_node(int nr)

It is a function to add data at the end of the node. First create a node *temp, *temp2, temp is filled with a new node. Then call the inputDataMhs(nmr) function. The process will then be carried out until temp->next is null, then data is added after the node that has a next value equal to null.

void tambah_simpul_akhir(int nmr)
 {
    node *temp, *temp2;
    temp=new node;
    inputDataMhs(nmr);
    temp->next=NULL;

    temp2=head;
     while(temp2->next != NULL)
       {
          temp2 = temp2->next;
       }
       temp2->next=temp;
 }

10. InputData(int nmr) function

This function is used to select which add function will be used. Whether the add function(nmr), add_initial_node(nmr), add_middle_list(int nmr, int insert_position), add_final_node(nmr) and whether the data entered already exists or not.

First create a new node that is temp. And temp is the same as head. If temp is equal to null then the function tambah(nmr) is executed and else if the function cekData(nmr) is false then it means the data has been inputted, this is a selection so that there is no input of the same nim, because nim is a reference for the next data process. As long as temp is not equal to null, if temp->nim is less than nmr, c is added one with temp equal to temp->next. If c is equal to zero then call the function tambah_simpul_awal(nmr), and else if c is less than the value in the count() function then the function tambah_tengah_list(int nmr, int posisi_insert) is executed by filling the posisi_insert with ++c. If not then the function tambah_simpul_akhir(nmr) will be executed.

void InputData(int nmr)
{
    int c=0;
    struct node *temp;
    temp=head;
    if(temp==NULL)
    {
        tambah(nmr);
        clrscr();
        cout<<"DATA BERHASIL DISIMPAN.\nTEKAN ENTER UNTUK MELANJUTKAN";
        getch();
    }
    else
    {
        if(cekData(nmr) == false)
        {
            clrscr();
            cout<<"NIM sudah pernah di inputkan";
            getch();
        }
        else
        {
            while(temp!=NULL)
            {
                if(temp->nim<nmr)
                   c++;
                temp=temp->next;
            }
            if(c==0)
                tambah_simpul_awal(nmr);
else if(c<count())
            {
                tambah_tengah_list(nmr,++c);
            }
            else
            {
                tambah_simpul_akhir(nmr);
            }
            clrscr();
            cout<<"DATA BERHASIL DISIMPAN.\nTEKAN ENTER UNTUK MELANJUTKAN";
            getch();
        }
    }
}

11. Function CariData(int nmr);

The following is a function to search for data in the linklist. The search process refers to the nim received with the variable nmr in this function. First create a bool variable with the name menemukan which contains false, then create a temp node. Temp is the same as head, as long as temp is not equal to null, run the program if temp->nim is the same as nmr menemukan will be true so that the data is displayed. If menemukan is false it means the data is not found and is not displayed.

void CariData(int nmr)
{
bool ketemu=false;
    struct node *temp;
    temp=head;
    while(temp!=NULL)
    {
        if(temp->nim == nmr){
            ketemu = true;
            clrscr();
            cout<<"DATA BERHASIL DITEMUKAN"<<endl;
            cout<<"NIM : "<<temp->nim<<"  ";
            cout<<"NAMA : "<<temp->nama<<"  ";
            cout<<"UMUR : "<<temp->umur<<"  ";
            cout<<"TINGGI : "<<temp->tinggi<<"  ";
            cout<<"BERAT : "<<temp->berat<<"  ";
            cout<<"\nTEKAN ENTER UNTUK MELANJUTKAN PROSES";
            getch();
        }
    temp=temp->next;
    }
    if(ketemu == false)
    {
        clrscr();
        cout<<"MAAF DATA DENGAN NIM "<<nmr<<" TIDAK DI TEMUKAN\nTEKAN ENTER UNTUK MELANJUTKAN PROSES";
        getch();
    }
}

12. Delete(int nim) function

This function is used to delete data nodes in the linklist. The node to be deleted is based on the number entered. So if the data is the same as the NIM it will be deleted. 

First create *temp and *prev nodes. Then fill temp with head, as long as temp is not equal to null, then do the test if temp is equal to head which indicates the data exists and matches, then head is equal to head->next and return is 1 else prev->next is equal to temp->next and return is also 1, and if temp is not equal to head then prev is equal to temp and temp is equal to temp->next. If temp is null the return will be 0 which means the data does not exist or does not match the nim entered which will be deleted.

int Hapus(int nim)
{
    struct node *temp, *prev;
    temp=head;
    while(temp!=NULL)
    {
        if(temp->nim==nim)
        {
            if(temp==head)
            {
                head=temp->next;
                return 1;
            }
            else
            {
                prev->next=temp->next;
                return 1;
            }
        }
        else
        {
            prev=temp;
            temp= temp->next;
        }
    }
    return 0;
}

13. display_list() function

This function is used to display data that we have previously input, or the results of data processing that has been done. And also the processing of student weight data.

First create a  temp node and fill temp with head, if temp is equal to null means the data is still empty, else fill i with the value 1 as a counter. As long as temp is not equal to null print the data in the list and perform a weight test against the standard BMI (Body Mass Index) formula, which is weight / (height / 100  height / 100). If the BMI is less than 18 then it is UNDERWEIGHT, if the BMI is greater than 18 and less than 24 then it is IDEAL WEIGHT, if the BMI is greater than 24 and less than 30 then it is OVERWEIGHT, and if the BMI is greater than 30 then it is OBESITY.

void tampil_senarai()
{
    node *temp;
    temp = head;
    if(temp == NULL)
       cout<<"List kosong"<<endl;
    else
    {
        int i=1;
        cout<<endl;
        cetak_tengah(1,"DATA BERAT BADAN MAHASISWA MENURUT RUMUS  BODY MASS INDEX");
        cout<<"\n===================================================";
        gotoxy(2,4);cout<<"No.";
        gotoxy(7,4);cout<<"NIM";
        gotoxy(11,4);cout<<"NAMA";
        gotoxy(25,4);cout<<"UMUR";
        gotoxy(31,4);cout<<"TB"<<endl;
        gotoxy(35,4);cout<<"BB"<<endl;
        gotoxy(38,4);cout<<"BMI"<<endl;
        gotoxy(42,4);cout<<"KETERANGAN"<<endl;
        cout<<"====================================================="<<endl;
       while(temp != NULL)
       {
        gotoxy(2,i+5);cout<<i;
        gotoxy(7,i+5);cout<<temp->nim;
        gotoxy(11,i+5);cout<<temp->nama;
        gotoxy(25,i+5);cout<<temp->umur;
        gotoxy(31,i+5);cout<<temp->tinggi;
        gotoxy(35,i+5);cout<<temp->berat;
        //hitung bmi
        int bmi = temp->berat/((temp->tinggi/100)*(temp->tinggi/100));
        gotoxy(38,i+5);cout<<bmi;
        //memberi keterangan
        char *ket;
        if(bmi <= 18)
            ket = "BERAT BADAN KURANG";
        else if(bmi > 18 && bmi <= 24)
            ket = "BERAT BADAN IDEAL";
        else if(bmi > 24 && bmi <= 30)
            ket = "KELEBIHAN BERAT BADAN";
        else if(bmi > 30)
            ket = "OBESITAS";
        gotoxy(42,i+5);cout<<ket;
        temp=temp->next;
        i++;
       }
       cout<<"\n\n================================================="<<endl;
       cout<<"KETERANGAN : "<<endl;
       cout<<"    -BMI < 18      = BERAT BADAN KURANG"<<endl;
       cout<<"    -BMI 18 - 24   = IDEAL"<<endl;
       cout<<"    -BMI 25 - 29   = KELEBIHAN BERAT BADAN "<<endl;
       cout<<"    -BMI > 30      = OBESITAS"<<endl;
    }
}

14. EditData(int nmr) function

This function is used to edit data in the linklist. bool meet = false; to determine that the meet function is equal to false. Struct node * temp; this function will create a node equal to temp. temp = head; then temp is equal to head, while (temp! = NULL) if temp is not equal to null, then the looping process will continue. if (temp-> nim == nmr) if temp is equal to no nim then the editing process will be run (data met) meet = true; nim is equal to true, no nim to be edited will appear as in the picture. Then the contents of temp are equal to temp->next then the next process will be carried out, If (meet == false) If meet is false then no data will be edited.

void EditData(int nmr)
{
    bool ketemu=false;
    struct node *temp;
    temp=head;
    while(temp!=NULL)
    {
        if(temp->nim == nmr){
            ketemu = true;
            clrscr();
            cout<<"EDIT DATA BERIKUT INI"<<endl;
            cout<<"NIM    : "<<temp->nim<<"  "<<endl;
            cout<<"NAMA   : "<<temp->nama<<"  "<<endl;
            cout<<"UMUR   : "<<temp->umur<<"  "<<endl;
            cout<<"TINGGI : "<<temp->tinggi<<" "<<endl;
            cout<<"BERAT  : "<<temp->berat<<" "<<endl<<endl;
            cout<<"PROSES EDIT DATA"<<endl;
            cout<<"NAMA    : ";cin>>temp->nama;
            cout<<"UMUR    : ";cin>>temp->umur;
            cout<<"TINGGI  : ";cin>>temp->tinggi;
            cout<<"BERAT   : ";cin>>temp->berat;
            clrscr();
            cout<<"DATA BERHASIL DI EDIT.\nTEKAN ENTER UNTUK MELANJUTKAN";
            getch();
        }
    temp=temp->next;
    }
    if(ketemu == false)
    {
        clrscr();
        cout<<"MAAF DATA DENGAN NIM  "<<nmr<<" TIDAK DI TEMUKAN\nTEKAN ENTER UNTUK MELANJUTKAN"<<endl;
        getch();
    }
}

15. Main() function

In the main() function contains a menu of choices and calls to functions according to the existing menu. The menu consists of input, with choice 1 which will call the InputData(nmr) function, choice 2 Search, which will call the CariData(nmr) function, choice 3 Delete, which will call the Delete(nmr) function, choice 4 Edit, which will call the EditData(nmr) function, and choice 5 Finish, to exit the program. And will repeat until the choice is not equal to 5.

void main()
{
    int nmr;
    head=NULL;
    do
    {
      clrscr();
      tampil_senarai();
      cout<<endl<<endl<<"======================"<<endl;
      cout<<"Menu Pilihan"<<endl;
      cout<<"1. Input"<<endl;
      cout<<"2. Cari"<<endl;
      cout<<"3. Hapus"<<endl;
      cout<<"4. Edit"<<endl;
      cout<<"5. Exit"<<endl;
      cout<<"Pilihan >> ";cin>>pilih;
      switch(pilih)
       {
        case 1: cout<<"Masukkan NIM      : ";
              cin>>nmr;
              InputData(nmr);
              break;
        case 2: cout<<"Masukkan NIM      : ";
              cin>>nmr;
              CariData(nmr);
              break;
        case 3: cout<<"Masukkan NIM      : ";
              cin>>nmr;
              if(Hapus(nmr)){
                clrscr();
                cout<<"DATA BERHASIL DIHAPUS.\nTEKAN ENTER UNTUK MELANJUTKAN PROSES";
                getch();
              }
              else{
                clrscr();
                cout<<"DATA GAGAL DIHAPUS.\nTEKAN ENTER UNTUK MELANJUTKAN PROSES";
                getch();
              }
              break;
        case 4: cout<<"Masukkan NIM      : ";
              cin>>nmr;
              EditData(nmr);
              break;
      default:
            cout<<"Pilihan yang anda masukkan salah, \ntekan enter untuk melanjutkan ";
       }
    }
  while(pilih !=5);
}

2.5. Complete Program

Complete Program

#include <iostream.h>
#include <conio.h> 

struct node {
    int nim;
    char nama[20];
    int umur;
    float tinggi;
    float berat;
    node *next;
 } *head;
 //node *awal_ptr=NULL;
 node *posisi;
 int pilih;
 //funsi tools
 void CariData(int nmr)
{
bool ketemu=false;
    struct node *temp;
    temp=head;
    while(temp!=NULL)
    {
        if(temp->nim == nmr){
            ketemu = true;
            clrscr();
            cout<<"DATA BERHASIL DITEMUKAN"<<endl;
            cout<<"NIM : "<<temp->nim<<"  ";
            cout<<"NAMA : "<<temp->nama<<"  ";
            cout<<"UMUR : "<<temp->umur<<"  ";
            cout<<"TINGGI : "<<temp->tinggi<<"  ";
            cout<<"BERAT : "<<temp->berat<<"  ";
            cout<<"\nTEKAN ENTER UNTUK MELANJUTKAN PROSES";
            getch();
        }
    temp=temp->next;
    }
    if(ketemu == false)
    {
        clrscr();
        cout<<"MAAF DATA DENGAN NIM "<<nmr<<" TIDAK DI TEMUKAN\nTEKAN ENTER UNTUK MELANJUTKAN PROSES";
        getch();
    }
}
void inputDataMhs(int nmr)
 {
    struct node *temp;
    cout << "Masukkan Nama     : ";   cin >> temp->nama;
    cout << "Masukkan Umur     : ";   cin >> temp->umur;
    cout << "Masukkan tingggi  : ";   cin >> temp->tinggi;
    cout << "Masukkan Berat    : ";   cin >> temp->berat;
    temp->nim=nmr;
 }
void cetak_tengah(int brs, char *teks) 
{ 
    gotoxy(40-strlen(teks)/2,brs);cout<<teks; 
}

int count()
{
    struct node *n;
    int c=0;
    n=head;
    while(n!=NULL)
    {
    n=n->next;
    c++;
    }
    return c;
}

bool cekData(int nmr)
{
    struct node *temp;
    temp=head;
    while(temp!=NULL)
    {
        if(temp->nim == nmr)
            return false;
        else
            return true;
    temp=temp->next;
    }
    return true;
}

 //Fugnsi Tambah data
 void tambah(int nmr )
{
    struct node *temp;
    temp = new node;
    inputDataMhs(nmr);
    if (head== NULL)
    {
        head=temp;
        head->next=NULL;
    }
    else
    {
        temp->next=head;
        head=temp;
    }
}
 void tambah_tengah_list(int nmr, int posisi_sisip) 
 {
     node *temp, *bantu;
     bantu=head;
     temp =new node;
     for(int i=1;i<posisi_sisip-1;i++)
     {
        if(bantu->next != NULL)
            bantu=bantu->next;
        else
            break;
     }       
    cout << "Masukkan Nama     : ";   cin >> temp->nama;
    cout << "Masukkan Umur     : ";   cin >> temp->umur;
    cout << "Masukkan tingggi  : ";   cin >> temp->tinggi;
    cout << "Masukkan Berat    : ";   cin >> temp->berat;
    temp->nim=nmr;
    temp->next=bantu->next;   
    bantu->next=temp;
}
void tambah_simpul_awal(int nmr) 
{
  node *temp;
  temp = new node;
  inputDataMhs(nmr);
  temp->next = NULL;
  
  temp->next = head;
  head = temp;
  
} 
void tambah_simpul_akhir(int nmr)
 {
    node *temp, *temp2; 
    temp=new node;
    inputDataMhs(nmr);
    temp->next=NULL;
    
    temp2=head;
     while(temp2->next != NULL)
       {
          temp2 = temp2->next;
       }
       temp2->next=temp;
 }
void InputData(int nmr)
{   
    int c=0;
    struct node *temp;
    temp=head;
    if(temp==NULL)
    {
        tambah(nmr);
        clrscr();
        cout<<"DATA BERHASIL DISIMPAN.\nTEKAN ENTER UNTUK MELANJUTKAN";
        getch();
    }
    else
    {
        if(cekData(nmr) == false)
        {
            clrscr();
            cout<<"NIM sudah pernah di inputkan";
            getch();
        }   
        else
        {
            while(temp!=NULL)
            {
                if(temp->nim<nmr)
                   c++;
                temp=temp->next;
            }
            if(c==0)
                tambah_simpul_awal(nmr);
            else if(c<count())
            {
                tambah_tengah_list(nmr,++c);
            }
            else
            {
                tambah_simpul_akhir(nmr);
            }
            clrscr();
            cout<<"DATA BERHASIL DISIMPAN.\nTEKAN ENTER UNTUK MELANJUTKAN";
            getch();
        }
    }
}
//akhir fungsi tambah data

 //fungsi hapus data
 int Hapus(int nim)
{
    struct node *temp, *prev;
    temp=head;
    while(temp!=NULL)
    {
        if(temp->nim==nim)
        {
            if(temp==head)
            {
                head=temp->next;
                return 1;
            }
            else
            {
                prev->next=temp->next;
                return 1;
            }
        }
        else
        {
            prev=temp;
            temp= temp->next;
        }
    }
    return 0;
}
//akhir fungsi hapus data

//fungsi tampil data
 void tampil_senarai()
 {
    node *temp;
    temp = head;
    if(temp == NULL)
       cout<<"List kosong"<<endl;
    else
    {
        int i=1;
        cout<<endl;
        cetak_tengah(1,"DATA BERAT BADAN MAHASISWA MENURUT RUMUS  BODY MASS INDEX");
        cout<<"\n=====================================================================";
        gotoxy(2,4);cout<<"No.";
        gotoxy(7,4);cout<<"NIM";
        gotoxy(11,4);cout<<"NAMA";
        gotoxy(25,4);cout<<"UMUR";
        gotoxy(31,4);cout<<"TB"<<endl;
        gotoxy(35,4);cout<<"BB"<<endl;
        gotoxy(38,4);cout<<"BMI"<<endl;
        gotoxy(42,4);cout<<"KETERANGAN"<<endl;
        cout<<"====================================================================="<<endl;
       while(temp != NULL)
       {
        gotoxy(2,i+5);cout<<i;        
        gotoxy(7,i+5);cout<<temp->nim;
        gotoxy(11,i+5);cout<<temp->nama;
        gotoxy(25,i+5);cout<<temp->umur;
        gotoxy(31,i+5);cout<<temp->tinggi;
        gotoxy(35,i+5);cout<<temp->berat;
        //hitung bmi
        int bmi = temp->berat/((temp->tinggi/100)*(temp->tinggi/100));
        gotoxy(38,i+5);cout<<bmi;
        //memberi keterangan
        char *ket;
        if(bmi <= 18)
            ket = "BERAT BADAN KURANG";
        else if(bmi > 18 && bmi <= 24)
            ket = "BERAT BADAN IDEAL";
        else if(bmi > 24 && bmi <= 30)
            ket = "KELEBIHAN BERAT BADAN";
        else if(bmi > 30)
            ket = "OBESITAS";
        gotoxy(42,i+5);cout<<ket;
        temp=temp->next;
        i++;
       }
       cout<<"\n\n====================================================================="<<endl;
       cout<<"KETERANGAN : "<<endl;
       cout<<"    -BMI < 18      = BERAT BADAN KURANG"<<endl;
       cout<<"    -BMI 18 - 24   = IDEAL"<<endl;
       cout<<"    -BMI 25 - 29   = KELEBIHAN BERAT BADAN "<<endl;
       cout<<"    -BMI > 30      = OBESITAS"<<endl;
    }
} 
//akhir fungsi tampil

//fungsi edit data 
void EditData(int nmr)
{
    bool ketemu=false;
    struct node *temp;
    temp=head;
    while(temp!=NULL)
    {
        if(temp->nim == nmr){
            ketemu = true;
            clrscr();
            cout<<"EDIT DATA BERIKUT INI"<<endl;
            cout<<"NIM    : "<<temp->nim<<"  "<<endl;
            cout<<"NAMA   : "<<temp->nama<<"  "<<endl;
            cout<<"UMUR   : "<<temp->umur<<"  "<<endl;
            cout<<"TINGGI : "<<temp->tinggi<<" "<<endl;
            cout<<"BERAT  : "<<temp->berat<<" "<<endl<<endl;
            cout<<"PROSES EDIT DATA"<<endl;
            cout<<"NAMA    : ";cin>>temp->nama;
            cout<<"UMUR    : ";cin>>temp->umur;
            cout<<"TINGGI  : ";cin>>temp->tinggi;
            cout<<"BERAT   : ";cin>>temp->berat;
            clrscr();
            cout<<"DATA BERHASIL DI EDIT.\nTEKAN ENTER UNTUK MELANJUTKAN";
            getch();
        }
    temp=temp->next;
    }
    if(ketemu == false)
    {
        clrscr();
        cout<<"MAAF DATA DENGAN NIM  "<<nmr<<" TIDAK DI TEMUKAN\nTEKAN ENTER UNTUK MELANJUTKAN"<<endl;
        getch();
    }
}
//akhir fungsi editdata
void main() 
{
    int nmr;
    head=NULL;
    do
    {
      clrscr();
      tampil_senarai();
      cout<<endl<<endl<<"======================"<<endl;
      cout<<"Menu Pilihan"<<endl;
      cout<<"1. Input"<<endl;
      cout<<"2. Cari"<<endl;
      cout<<"3. Hapus"<<endl;
      cout<<"4. Edit"<<endl;
     cout<<"5. Exit"<<endl;
      cout<<"Pilihan >> ";cin>>pilih;
      switch(pilih)
       {
        case 1: cout<<"Masukkan NIM      : ";
              cin>>nmr;
              InputData(nmr);
              break;
        case 2: cout<<"Masukkan NIM      : ";
              cin>>nmr;
              CariData(nmr);
              break;
        case 3: cout<<"Masukkan NIM      : ";
              cin>>nmr;
              if(Hapus(nmr)){
                clrscr();
                cout<<"DATA BERHASIL DIHAPUS.\nTEKAN ENTER UNTUK MELANJUTKAN PROSES";
                getch();
              }
              else{
                clrscr();
                cout<<"DATA GAGAL DIHAPUS.\nTEKAN ENTER UNTUK MELANJUTKAN PROSES";
                getch();
              }
              break;
        case 4: cout<<"Masukkan NIM      : ";
              cin>>nmr;
              EditData(nmr);
              break;
      default:
            cout<<"Pilihan yang anda masukkan salah, \ntekan enter untuk melanjutkan ";
       }
    }
  while(pilih !=5);
}

CHAPTER II - CONCLUSION

This program is a program to display student weight data according to the BMI (Body Mass Index) formula or Body Mass Index, namely weight divided by (height / 100 * height / 100). This program is made using a single linked list. It includes the Add, Edit, Search, Delete and Sort processes that are automatically carried out by the program which is described with several functions. With this single linked list we can create a simple program like this Student Weight Data Program.

Netizens

I want to ask, why is it that when I try to code it, it won't run?

MFERDIHERDIANSYAH  what compiler do you use? because different compilers have different coding... if the code above I wrote using Borland C++, if  MFERDIHERDIANSYAH  uses Devian C++, then there needs to be some code adjustments... more or less it is relative to the library imported in the compiler.

if  you use dev c++, there are a lot of errors,
please do it, bro. What needs to be changed so that it runs on Dev BG?

RAMADHANPRATAMAPUTRAHASIBUAN  in general, the form of looping and branching in c++ is the same, but for declarations and built-in functions that are different depending on the imported library.. if in borland c++ the way to print a string to the console uses cout <<, while in devian c++ it might use printf('your string'); well this kind of thing needs to be adjusted, while for the struct type please google whether devian c++ provides a library for struct declarations.. I think so, bro

In addition, to clear the screen in Borland, you can use the  clrscr() method  , while in dev. c++, please use this method  https://bundet.com/d/104-bagaimana-cara-clear-screen-di-dev-c

The clue is when you do Google Fu (googling technique), please use the keyword  Input-Output Devian C++, because the codes above cannot be separated from data input operations and the output is printed to the console.


Post a Comment

Previous Next

نموذج الاتصال