Quick actions

cmd+k|ctrl+k

Navigation

Languages

Algoritma12.1

Snippet info

Language

Cpp

Visibility

public

Author

syifanirwana

Created

2024-12-28T01:21:51.36247Z

Updated

2024-12-28T15:37:07.897283Z

#include <iostream>
using namespace std;

void garis(int a) {
    int i; //Local Variable
    for (i=1;i<=a;i++) { printf("="); }
    printf("\n");
}

void judul() {
    garis(40);
    puts("Contoh Program Struct");
    garis(40);
}

string cek_nama() {
    string nama = "Syifa Asih Nirwana";
    return nama;
}

string cek_email() {
    string email = "[email protected]";
    return email;
}

void author() {
    string get_nama = cek_nama();
    cout<<"Nama  :"<<get_nama<<endl;
    string get_email = cek_email();
    cout<<"Email :"<<get_email<<endl;
}

int main() {
    judul();
    /*
    By giving a name to the structure, you can treat it as a data type.
    This means that you can create variables with this structure anywhere
        in the program at any time.
    To create a named structure, put the name of the structure right
        after the struct keyword.
        */
        
    struct data {
        char nama[20];
        char nim[20];
        int nilai;
    };
    data mahasiswa;
    cout<<"Masukan Nama : <input>"; cin>>mahasiswa.nama; cout<<endl;
    cout<<"NIM          : <input>"; cin>>mahasiswa.nim; cout<<endl;
    cout<<"Nilai Total  : <input>"; cin>>mahasiswa.nilai; cout<<endl;
    garis(40);
    cout<<"Data Mahasiswa"<<endl;
    garis(40);
    cout<<"Nama Mahasiswa: "<<mahasiswa.nama<<endl;
    cout<<"NIM           : "<<mahasiswa.nim<<endl;
    cout<<"Nilai Total   : "<<mahasiswa.nilai<<endl;
    garis(40);
    author();
    return 0;
}
INFO