Use of Structs and Functions for Library Book Input Programs
Source Code:
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
/*
*bundet.com
*Wawan Beneran
*Penggunaan Struct dan Fungsi Untuk Program Input Buku Perpustakaan
*/
struct Buku
{
char kode[10];
char judul[50];
char author[20];
char penerbit[50];
int jmlhal;
};
//membuat variabel struk
Buku myBook;
void input()
{
// mengakses elemen struct
cout << "masukan kode buku : ";
gets(myBook.kode);
cout << "masukan judul buku : ";
gets(myBook.judul);
cout << "masukan pengarang buku : ";
gets(myBook.author);
cout << "masukan penerbit buku : ";
gets(myBook.penerbit);
cout << "masukan jumlah halaman buku : ";
cin >> myBook.jmlhal;
// silakan lengkapi untuk inputan
// pengarang, penerbit, jml Hal
}
void output()
{
cout << "\nKode : " << myBook.kode;
cout << "\nJudul : " << myBook.judul;
cout << "\nPengarang : " << myBook.author;
cout << "\nPenerbit : " << myBook.penerbit;
cout << "\nJumlah Hal. : " << myBook.jmlhal;
// silakan lengkapi untuk output
// pengarang, penerbit, jmlHal
}
void main()
{
input();
clrscr();
output();
getch();
}
Hope this is useful & happy learning!
Netizens
Wow
, why is there an error in the cout section?
- Edited
TasyaRefjuandani what kind of error is it? Please include a capture of the error, because we are not shamans who can see abstractions
For Tasya, it seems you should use std and iostream, not iostream.h if I'm not mistaken