Professional Documents
Culture Documents
h>
#include <stdlib.h>
#include <string.h>
#define TRUE 1
struct student {
char name[25];
int ID;
float cgpa;
};
struct SBI {
int Acno;
int ID;
int balance;
};
struct student S;
struct SBI M;
FILE *fp1, *fp2;
void nothing_input(FILE *fd);
int insert();
int operators();
int check;
int projection();
int uni_on();
int intersection();
int cartesian();
int naturaljoin();
int main(){
int ch;
char more;
fp1 = fopen("student.txt","a+");
fp2 = fopen("mcastd.txt","a+");
if(fp1 == NULL || fp2 == NULL){
printf("\n Files could not open\n");
return 0;
}
while(TRUE){
switch(ch){
case 1:
insert();
break;
case 2:
operators();
break;
default:
return 0;
}
}
return 0;
}
int insert(){
int choice,pkey,uniq;
char yes;
do {
int choice;
char yes;
do {
printf("\n\t\t Choose the Operator : \n");
printf("\t\t 1. Projection\n");
printf("\t\t 2. Union \n");
printf("\t\t 3. Intersection \n");
printf("\t\t 4. Cartetian product \n");
printf("\t\t 5. Natural Join \n");
scanf("%d",&choice);
//PROJECTION
switch(choice){
case 1 :
projection();
break;
case 2:
uni_on();
break;
case 3:
intersection();
break;
case 4:
cartesian();
break;
case 5:
naturaljoin();
break;
default :
return 0;
}
printf("_______________________________________________________________");
printf("\n Name ID Cgpa A/c.no ID balance
\n");
printf("_______________________________________________________________");
printf("\n");
while(fread(&S,sizeof(S),1,fp1) == 1){
rewind(fp2);
while(fread(&M,sizeof(M),1,fp2) == 1){
printf("| %s | %d | %f | ",S.name,S.ID,S.cgpa);
printf(" %d | %d | %d |
",M.Acno,M.ID,M.balance);
printf("\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _");
printf("\n");
}
}
return 0;
}
int uni_on(){ //UNION
rewind(fp1);
rewind(fp2);
printf("\t\t ID \n");
while(fread(&S,sizeof(S),1,fp1) == 1 ){
printf("\n\t\t %d",S.ID);
}
while(fread(&M,sizeof(M),1,fp2) == 1){
check = 0;
while(fread(&S,sizeof(S),1,fp1) == 1){
if(M.ID == S.ID){
check=1;
break;
}
if(check != 1)
printf("%d",M.ID);
}
}
return 0;
}
printf("\t__________________________________________________");
printf("\n\t ID | Name | cgpa | Acno | balance
\n");
printf("\t_________________________________________________\n");
printf("\t| %d | %s | %f | %d | %d |
\n",S.ID,S.name,S.cgpa,M.Acno,M.balance);
printf("\t_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _");
}
}
}
return 0;
}