Jumat, 01 Juli 2011

Struct (C++)



#include "iostream.h"
#include "stdio.h"
#include "conio.h"

struct siswa{
    char nis[8];
    char nama[30];
    int tahun;
} rsiswa [40];
void main(){
    long uang;
    int i=0; int j;
    char lg='Y';
    do{
        gotoxy (20,5);cout<<"Input Data Siswa";
        gotoxy (20,6);cout<<"------------------------ ";
        gotoxy (20,7);cout<<"NIS :";gets(rsiswa[i].nis);
        gotoxy (20,8);cout<<"Nama :";gets(rsiswa[i].nama);
        gotoxy (20,9);cout<<"Tahun :";cin>>rsiswa[i].tahun;
        gotoxy (20,10);cout<<"Input Lagi [Y/T]:";cin>>lg;clrscr(); ++i;
    }while (lg=='Y' || lg=='y');
    clrscr();
    gotoxy (10,3);cout<<"Laporan Siswa";
    gotoxy (10,4);cout<<"---------------------------------------------------- ";
    gotoxy (10,5);cout<<"NO  NIS      NAMA       TAHUN       UANG SEKOLAH ";
    gotoxy (10,6);cout<<"---------------------------------------------------- ";
    for(j=0; j<i; j++){
            if (rsiswa[j].tahun==2008)uang=100000;
            else if (rsiswa[j].tahun==2009)uang=110000;
            else if (rsiswa[j].tahun==2010)uang=120000;
            else uang=0;
        gotoxy (10,7+j);cout<<j+1 <<" " <<rsiswa[j].nis;
        gotoxy (21,7+j);cout<<rsiswa[j].nama;
        gotoxy (41,7+j);cout<<rsiswa[j].tahun <<" " <<uang;
    }
    gotoxy (10,8+j);cout << "---------------------------------------";
}
 

Tidak ada komentar:

Posting Komentar