Senin, Maret 28

Source Code C++ Nilai Ujian

Program c++ ini memiliki fungsi menambah data,hapus,edit dan tampil. Bagi yang menbutuhkan silahkan di download, tetapi souce kode ini jauh dari kesempurnaan, mohon untuk diedit ulang,tks




#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<string.h>
typedef struct nilai
{
char nama[20];
int nilai1;
int nilai2;
int nilai3;
int nilai4;
int nilai5;
int nilai6;
int nilai7;
int nilai8;
int id;
}nilai;
int main()
{
float id;
FILE *fp,*ft;
char another, choice;
nilai stu;

long int recsize;
fp=fopen("master.DAT","rb+");
if(fp==NULL)
{
fp=fopen("master.DAT","wb+");
if(fp==NULL)
{
printf("File gagal diakses");
}
}
recsize=sizeof(stu);
while(!(choice=='5'))
{
printf("\n================");
printf("\nDATA NILAI UJIAN");
printf("\n================");
printf("\n1.TAMBAH DATA ");
printf("\n2.HAPUS DATA ");
printf("\n3.EDIT DATA ");
printf("\n4.TAMPIL DATA ");
printf("\n5.KELUAR ");
printf("\n===============================");
printf("\nPILIH SALAH SATU :");

fflush(stdin);
scanf("%c",&choice);
printf("\n===================");
switch(choice)
{
case'1':
fseek(fp,0,SEEK_END);
another='Y';
while(another=='Y'||another=='y')
{
clrscr();
printf("\n===================================");
printf("\nDATA NILAI UJIAN");
printf("\n===================================");
printf("\n Nama Mahasisiwa : ");scanf("%s",&stu.nama);
printf("\n Algoritma & Struktur Data : ");scanf("%s",&stu.nilai1);
printf("\n Logika Informatika : ");scanf("%d",&stu.nilai2);
printf("\n Pendidikan Agama Islam 2 : ");scanf("%s",&stu.nilai3);
printf("\n Fisika Dasar : ");scanf("%s",&stu.nilai4);
printf("\n Statistika Teknis : ");scanf("%s",&stu.nilai5);
printf("\n Kalkulus2 : ");scanf("%d",&stu.nilai6);
printf("\n Pemprograman Dasar : ");scanf("%d",&stu.nilai7);
printf("\n Prak. Pemprograman Dasar : ");scanf("%d",&stu.nilai8);
fwrite(&stu,recsize,1,fp);
printf("\n===================================");
printf("\nMAU TAMBAH DATA LAGI[Y/T]? ");
fflush(stdin);
another=getchar();
}break;
case'2':
another='Y';
while(another=='Y'||another=='y')
{
clrscr();
printf("\n");

printf("\n===========================");
printf("\nDATA YANG AKAN DIHAPUS");
printf("\n===========================");
printf("\n Nama Mahasisiwa : ");scanf("%s",&stu.nama);
printf("\n Algoritma & Struktur Data : ");scanf("%s",&stu.nilai1);
printf("\n Logika Informatika : ");scanf("%d",&stu.nilai2);
printf("\n Pendidikan Agama Islam 2 : ");scanf("%s",&stu.nilai3);
printf("\n Fisika Dasar : ");scanf("%s",&stu.nilai4);
printf("\n Statistika Teknis : ");scanf("%s",&stu.nilai5);
printf("\n Kalkulus2 : ");scanf("%d",&stu.nilai6);
printf("\n Pemprograman Dasar : ");scanf("%d",&stu.nilai7);
printf("\n Prak. Pemprograman Dasar : ");scanf("%d",&stu.nilai8);
printf("\n===========================");
ft=fopen("TEMP.DAT","wb");
rewind(fp);
while(fread(&stu,recsize,1,fp)==1)
{
if(stu.id!=0)
fwrite(&stu,recsize,1,ft);
}
fclose(fp);
fclose(ft);
remove("master.DAT");
rename("TEMP.DAT","master.DAT");
fp=fopen("master.DAT","wb+");
printf("\nMAU HAPUS DATA LAGI[Y/T]?");
fflush(stdin);
another=getchar();
}break;
case'3':
another='Y';
while(another=='Y'||another=='y')
{
clrscr();
printf("\n");
printf("\n===============================");
printf("\nDATA NILAI UJIAN ");
printf("\n===============================");
printf("\n Nama Mahasisiwa : ");scanf("%s",&stu.nama);
printf("\n Algoritma & Struktur Data : ");scanf("%s",&stu.nilai1);
printf("\n Logika Informatika : ");scanf("%d",&stu.nilai2);
printf("\n Pendidikan Agama Islam 2 : ");scanf("%s",&stu.nilai3);
printf("\n Fisika Dasar : ");scanf("%s",&stu.nilai4);
printf("\n Statistika Teknis : ");scanf("%s",&stu.nilai5);
printf("\n Kalkulus2 : ");scanf("%d",&stu.nilai6);
printf("\n Pemprograman Dasar : ");scanf("%d",&stu.nilai7);
printf("\n Prak. Pemprograman Dasar : ");scanf("%d",&stu.nilai8);
printf("\n===============================");
printf("\nMAU EDIT DATA LAGI[Y/T]?");
fflush(stdin);
another=getchar();
}break;
case'4':
rewind(fp);
clrscr();
printf("\n=====================================");
printf("\n DAFTAR DATA ");
printf("\n=====================================");
while(fread(&stu,recsize,1,fp)==1)
{
printf("\n=====================================");
printf("\nDAFTAR NILAI UJIAN ");
printf("\n=====================================");
cout<<"\nNama Mahasisiwa : "<<stu.nama;
cout<<"\nAlgoritma & Struktur Data : "<<stu.nilai1;
cout<<"\nLogika Informatika : "<<stu.nilai2;
cout<<"\nPendidikan Agama Islam 2 : "<<stu.nilai3;
cout<<"\nFisika Dasar : "<<stu.nilai4;
cout<<"\nStatistika Teknis : "<<stu.nilai5;
cout<<"\nKalkulus2 : "<<stu.nilai6;
cout<<"\nPemprograman Dasar : "<<stu.nilai7;
cout<<"\nPrak. Pemprograman Dasar : "<<stu.nilai8;
printf("\n=====================================");
}break;
case'5':
{
clrscr();

}
break;
}//switch(choice)
}//while(!(choice=='5'))
}
Previous Post
Next Post

0 komentar: