Nuffnang

Sunday, March 29, 2009

mini project of C Programming

#include
#include
#include

#define flowrate_pm 5
#define flowrate_tsp 40

void print_id(long int);
void print_password(long int);
void print_infor(float, float, int);
void print_pm(float, float);
void print_tsp(float, float);
void print_infor_case1(float, float, int);
void print_pm_case1(float, float);
void print_tsp_case1(float, float);
void print_infor_case2(float, float, int);
void print_pm_case2(float, float);
void print_tsp_case2(float, float);

struct member
{
char first_name[10];
char second_name[10];
char last_name[10];
char ic[20];
char home[20];
char phone[20];
int age;
int date_bth;
char month_bth[20];
int year_bth;
char matric[10];
char course1[20];
char course2[20];
char email[50];
};

struct sampling
{
int actual_population;
int red_bean;
int soy_bean;
int no_sample[3];
int mark_red_bean[3];
float pai[3];
float varian[3];
};

int main()
{
long int id;
long int pass;
int choice, choice1, i, y, z, period;
float initial_weight, final_weight, volume, concentration;
char cont;
struct member detail;
struct sampling frequency;
FILE*lexa;
FILE*leix;

printf("Choose:");
printf("\n1. Member Login");
printf("\n2, Sign up");
printf("\n3, Proceed");

printf("\nPlease Enter Your Choice:");
scanf("%d", &choice);

switch(choice)
{
case 1:
{
printf("Please Enter Your ID:");
scanf("%ld", &id);
printf("Please Enter Your Password:");
scanf("%ld", &pass);

print_id(id);
print_password(pass);
};break;

case 2:
{
if((lexa=fopen("login.txt","a"))==NULL)
printf("File can't be opened");
else
{
printf("************************************************");
printf("\n******Welcome to the member sign up system******");
printf("\n************************************************\n");
printf("Enter your name:");
scanf("%s %s %s", detail.first_name, detail.second_name, detail.last_name);

printf("Enter your IC number:");
scanf("%s", detail.ic);

printf("Enter your matric number:");
scanf("%s", detail.matric);

printf("Enter your home number:");
scanf("%s", detail.home);

printf("Enter your cellphone number: ");
scanf("%s", detail.phone);

printf("Your age:");
scanf("%d", &detail.age);

printf("Enter your DOB(date month year):");
scanf("%d %s %d", &detail.date_bth, detail.month_bth, &detail.year_bth);

printf("Enter your course: ");
scanf("%s %s", detail.course1, detail.course2);

printf("Enter your e-mail address:");
scanf("%s", detail.email);

printf("\n\n");
printf("\nName: %s %s %s\t\tMatric Number: %s", detail.first_name, detail.second_name, detail.last_name, detail.matric);
fprintf(lexa, "Name: %s %s %s\t\tMatric Number: %s", detail.first_name, detail.second_name, detail.last_name, detail.matric);
printf("\nYour IC: %s\t\tAge: %d", detail.ic, detail.age);
fprintf(lexa, "\nYour IC: %s\t\tAge: %d", detail.ic, detail.age);
printf("\nYour DOB: %d %s %d", detail.date_bth, detail.month_bth, detail.year_bth);
fprintf(lexa, "\nYour DOB: %d %s %d", detail.date_bth, detail.month_bth, detail.year_bth);
printf("\nHome nember: %s\t\tCellphone number: %s", detail.home, detail.phone);
fprintf(lexa, "\nHome nember: %s\t\tCellphone number: %s", detail.home, detail.phone);
printf("\nCourse:%s %s", detail.course1, detail.course2);
fprintf(lexa, "\nCourse:%s %s", detail.course1, detail.course2);
printf("\ne-mail addres: %s", detail.email);
fprintf(lexa, "\ne-mail addres: %s", detail.email);
printf("\nYour ID: %s", detail.matric);
printf("\t\tYour Password:Will be send to your file.");
fprintf(lexa, "\nYour ID: %s\t\tYour Password: ", detail.matric);
for(i=1; i<=8; i++)
{
fprintf(lexa, "%d", 1+(rand()%9));
}
printf("\n\n");
fclose(lexa);
}

};break;

case 3:
printf("Proceed...");break;
}


switch(choice)
{
case 1:
{
do
{
printf("\nChoose:");
printf("\n1. Calculate Population Estimation");
printf("\n2. Calculate Concentration of Particulate Matter(PM)");
printf("\n3. Calculate Concentration of Total Suspended Particulate Matter(TSP)");

printf("\nPlease Enter Your Choice:");
scanf("%d", &choice1);

switch(choice1)
{

case 1:
{
if((leix=fopen("user.txt","a"))==NULL)
printf("File can't be opened");
else
{
printf("Please Enter Your Actual Population:");
scanf("%d", &frequency.actual_population);
printf("Please Enter Your Red Bean(Marked Bean):");
scanf("%d", &frequency.red_bean);
printf("Please Enter Your Yellow Bean(Unmarked Bean):");
scanf("%d", &frequency.soy_bean);

for(z=0; z<3; z++)
{
printf("Please Enter Your S(%d)(no of bean in sample):", z+1);
scanf("%d", &frequency.no_sample[z]);
printf("Please Enter Your R(%d)(no of red maeked bean in sample:", z+1);
scanf("%d", &frequency.mark_red_bean[z]);
}

for(y=0; y<3; y++)
{
frequency.pai[y]=(frequency.red_bean*frequency.no_sample[y])/frequency.mark_red_bean[y];
frequency.varian[y]=((frequency.pai[y]-frequency.actual_population)/frequency.actual_population)*100;
}

printf("********************************************************************************");
fprintf(leix, "\n********************************************************************************");
printf("\n %36s %10s %10s %10s", "Norminal", "1", "2", "3");
fprintf(leix, "\n %36s %10s %10s %10s", "Norminal", "1", "2", "3");
printf("\n********************************************************************************");
fprintf(leix, "\n********************************************************************************");
printf("\n %36s %10d %10d %10d", "Marked sample(Red Bean)", frequency.red_bean, frequency.red_bean, frequency.red_bean);
fprintf(leix, "\n %36s %10d %10d %10d", "Marked sample(Red Bean)", frequency.red_bean, frequency.red_bean, frequency.red_bean);
printf("\n %36s %10d %10d %10d", "Unmaeked sample(Yellow Bean)", frequency.soy_bean, frequency.soy_bean, frequency.soy_bean);
fprintf(leix, "\n %36s %10d %10d %10d", "Unmaeked sample(Yellow Bean)", frequency.soy_bean, frequency.soy_bean, frequency.soy_bean);
printf("\n %36s %10d %10d %10d", "Actual Population", frequency.actual_population, frequency.actual_population, frequency.actual_population);
fprintf(leix, "\n %36s %10d %10d %10d", "Actual Population", frequency.actual_population, frequency.actual_population, frequency.actual_population);
printf("\n %36s %10d %10d %10d", "S(no of bean in sample)", frequency.no_sample[0], frequency.no_sample[1], frequency.no_sample[2]);
fprintf(leix, "\n %36s %10d %10d %10d", "S(no of bean in sample)", frequency.no_sample[0], frequency.no_sample[1], frequency.no_sample[2]);
printf("\n %36s %10d %10d %10d", "R(no of marked bean in sample", frequency.mark_red_bean[0], frequency.mark_red_bean[1], frequency.mark_red_bean[2]);
fprintf(leix, "\n %36s %10d %10d %10d", "R(no of marked bean in sample", frequency.mark_red_bean[0], frequency.mark_red_bean[1], frequency.mark_red_bean[2]);
printf("\n %36s %10.0f %10.0f %10.0f", "Pai(Estimation Population", frequency.pai[0], frequency.pai[1], frequency.pai[2]);
fprintf(leix, "\n %36s %10.0f %10.0f %10.0f", "Pai(Estimation Population", frequency.pai[0], frequency.pai[1], frequency.pai[2]);
printf("\n %36s %10.2f %10.2f %10.2f", "% Varian", frequency.varian[0], frequency.varian[1], frequency.varian[2]);
fprintf(leix, "\n %36s %10.2f %10.2f %10.2f", "% Varian", frequency.varian[0], frequency.varian[1], frequency.varian[2]);
printf("\n********************************************************************************");
fprintf(leix, "\n********************************************************************************");
}
};break;

case 2:
{
printf("Insert the values for:\n(a) Initial weight of filter paper(micrograms):");
scanf("%f", &initial_weight);
printf("(b) Final weight of filter paper(micrograms):");
scanf("%f", &final_weight);
printf("(c) Sampling period(Hours):");
scanf("%d", &period);

print_infor_case1(initial_weight, final_weight, period);
volume=(flowrate_pm*period*(60/1000.0));
concentration=(final_weight-initial_weight)/volume;
print_pm_case1(volume, concentration);
};break;

case 3:
{
printf("Insert the values for:\n(a) Initial weight of filter paper(micrograms):");
scanf("%f", &initial_weight);
printf("(b) Final weight of filter paper(micrograms):");
scanf("%f", &final_weight);
printf("(c) Sampling period(Hours):");
scanf("%d", &period);

print_infor_case1(initial_weight, final_weight, period);
volume=(flowrate_tsp*period*(60/35.3147));
concentration=(final_weight-initial_weight)/volume;
print_tsp_case1(volume, concentration);
};break;
default:printf("Invalid Choice");
}
getchar();
printf("\n\nDo YOU Want to CONTINUE? (Y is Yes, N is No):");
scanf("%c", &cont);
}while(cont=='y'||cont=='Y');
printf("Terminated...Thank You!!!");
};break;

case 2:
{

do
{
printf("\nChoose:");
printf("\n1. Calculate Population Estimation");
printf("\n2. Calculate Concentration of Particulate Matter(PM)");
printf("\n3. Calculate Concentration of Total Suspended Particulate Matter(TSP)");

printf("\nPlease Enter Your Choice:");
scanf("%d", &choice1);

switch(choice1)
{

case 1:
{
if((lexa=fopen("login.txt","a"))==NULL)
printf("File can't be opened");
else
{
printf("Please Enter Your Actual Population:");
scanf("%d", &frequency.actual_population);
printf("Please Enter Your Red Bean(Marked Bean):");
scanf("%d", &frequency.red_bean);
printf("Please Enter Your Yellow Bean(Unmarked Bean):");
scanf("%d", &frequency.soy_bean);

for(z=0; z<3; z++)
{
printf("Please Enter Your S(%d)(no of bean in sample):", z+1);
scanf("%d", &frequency.no_sample[z]);
printf("Please Enter Your R(%d)(no of red maeked bean in sample:", z+1);
scanf("%d", &frequency.mark_red_bean[z]);
}

for(y=0; y<3; y++)
{
frequency.pai[y]=(frequency.red_bean*frequency.no_sample[y])/frequency.mark_red_bean[y];
frequency.varian[y]=((frequency.pai[y]-frequency.actual_population)/frequency.actual_population)*100;
}

printf("********************************************************************************");
fprintf(lexa, "\n********************************************************************************");
printf("\n %36s %10s %10s %10s", "Norminal", "1", "2", "3");
fprintf(lexa, "\n %36s %10s %10s %10s", "Norminal", "1", "2", "3");
printf("\n********************************************************************************");
fprintf(lexa, "\n********************************************************************************");
printf("\n %36s %10d %10d %10d", "Marked sample(Red Bean)", frequency.red_bean, frequency.red_bean, frequency.red_bean);
fprintf(lexa, "\n %36s %10d %10d %10d", "Marked sample(Red Bean)", frequency.red_bean, frequency.red_bean, frequency.red_bean);
printf("\n %36s %10d %10d %10d", "Unmaeked sample(Yellow Bean)", frequency.soy_bean, frequency.soy_bean, frequency.soy_bean);
fprintf(lexa, "\n %36s %10d %10d %10d", "Unmaeked sample(Yellow Bean)", frequency.soy_bean, frequency.soy_bean, frequency.soy_bean);
printf("\n %36s %10d %10d %10d", "Actual Population", frequency.actual_population, frequency.actual_population, frequency.actual_population);
fprintf(lexa, "\n %36s %10d %10d %10d", "Actual Population", frequency.actual_population, frequency.actual_population, frequency.actual_population);
printf("\n %36s %10d %10d %10d", "S(no of bean in sample)", frequency.no_sample[0], frequency.no_sample[1], frequency.no_sample[2]);
fprintf(lexa, "\n %36s %10d %10d %10d", "S(no of bean in sample)", frequency.no_sample[0], frequency.no_sample[1], frequency.no_sample[2]);
printf("\n %36s %10d %10d %10d", "R(no of marked bean in sample", frequency.mark_red_bean[0], frequency.mark_red_bean[1], frequency.mark_red_bean[2]);
fprintf(lexa, "\n %36s %10d %10d %10d", "R(no of marked bean in sample", frequency.mark_red_bean[0], frequency.mark_red_bean[1], frequency.mark_red_bean[2]);
printf("\n %36s %10.0f %10.0f %10.0f", "Pai(Estimation Population", frequency.pai[0], frequency.pai[1], frequency.pai[2]);
fprintf(lexa, "\n %36s %10.0f %10.0f %10.0f", "Pai(Estimation Population", frequency.pai[0], frequency.pai[1], frequency.pai[2]);
printf("\n %36s %10.2f %10.2f %10.2f", "% Varian", frequency.varian[0], frequency.varian[1], frequency.varian[2]);
fprintf(lexa, "\n %36s %10.2f %10.2f %10.2f", "% Varian", frequency.varian[0], frequency.varian[1], frequency.varian[2]);
printf("\n********************************************************************************");
fprintf(lexa, "\n********************************************************************************");
}
};break;

case 2:
{
printf("Insert the values for:\n(a) Initial weight of filter paper(micrograms):");
scanf("%f", &initial_weight);
printf("(b) Final weight of filter paper(micrograms):");
scanf("%f", &final_weight);
printf("(c) Sampling period(Hours):");
scanf("%d", &period);

print_infor_case2(initial_weight, final_weight, period);
volume=(flowrate_pm*period*(60/1000.0));
concentration=(final_weight-initial_weight)/volume;
print_pm_case2(volume, concentration);
};break;

case 3:
{
printf("Insert the values for:\n(a) Initial weight of filter paper(micrograms):");
scanf("%f", &initial_weight);
printf("(b) Final weight of filter paper(micrograms):");
scanf("%f", &final_weight);
printf("(c) Sampling period(Hours):");
scanf("%d", &period);

print_infor_case2(initial_weight, final_weight, period);
volume=(flowrate_tsp*period*(60/35.3147));
concentration=(final_weight-initial_weight)/volume;
print_tsp_case2(volume, concentration);
};break;
default:printf("Invalid Choice");
}
getchar();
printf("\n\nDo YOU Want to CONTINUE? (Y is Yes, N is No):");
scanf("%c", &cont);
}while(cont=='y'||cont=='Y');
printf("Terminated...Thank You!!!");
};break;

case 3:
{
do
{
printf("\nChoose:");
printf("\n1. Calculate Population Estimation");
printf("\n2. Calculate Concentration of Particulate Matter(PM)");
printf("\n3. Calculate Concentration of Total Suspended Particulate Matter(TSP)");

printf("\nPlease Enter Your Choice:");
scanf("%d", &choice1);

switch(choice1)
{

case 1:
{
printf("Please Enter Your Actual Population:");
scanf("%d", &frequency.actual_population);
printf("Please Enter Your Red Bean(Marked Bean):");
scanf("%d", &frequency.red_bean);
printf("Please Enter Your Yellow Bean(Unmarked Bean):");
scanf("%d", &frequency.soy_bean);

for(z=0; z<3; z++)
{
printf("Please Enter Your S(%d)(no of bean in sample):", z+1);
scanf("%d", &frequency.no_sample[z]);
printf("Please Enter Your R(%d)(no of red maeked bean in sample:", z+1);
scanf("%d", &frequency.mark_red_bean[z]);
}

for(y=0; y<3; y++)
{
frequency.pai[y]=(frequency.red_bean*frequency.no_sample[y])/frequency.mark_red_bean[y];
frequency.varian[y]=((frequency.pai[y]-frequency.actual_population)/frequency.actual_population)*100;
}

printf("********************************************************************************");
printf("\n %36s %10s %10s %10s", "Norminal", "1", "2", "3");
printf("\n********************************************************************************");
printf("\n %36s %10d %10d %10d", "Marked sample(Red Bean)", frequency.red_bean, frequency.red_bean, frequency.red_bean);
printf("\n %36s %10d %10d %10d", "Unmaeked sample(Yellow Bean)", frequency.soy_bean, frequency.soy_bean, frequency.soy_bean);
printf("\n %36s %10d %10d %10d", "Actual Population", frequency.actual_population, frequency.actual_population, frequency.actual_population);
printf("\n %36s %10d %10d %10d", "S(no of bean in sample)", frequency.no_sample[0], frequency.no_sample[1], frequency.no_sample[2]);
printf("\n %36s %10d %10d %10d", "R(no of marked bean in sample", frequency.mark_red_bean[0], frequency.mark_red_bean[1], frequency.mark_red_bean[2]);
printf("\n %36s %10.0f %10.0f %10.0f", "Pai(Estimation Population", frequency.pai[0], frequency.pai[1], frequency.pai[2]);
printf("\n %36s %10.2f %10.2f %10.2f", "% Varian", frequency.varian[0], frequency.varian[1], frequency.varian[2]);
printf("\n********************************************************************************");
};break;

case 2:
{
printf("Insert the values for:\n(a) Initial weight of filter paper(micrograms):");
scanf("%f", &initial_weight);
printf("(b) Final weight of filter paper(micrograms):");
scanf("%f", &final_weight);
printf("(c) Sampling period(Hours):");
scanf("%d", &period);

print_infor(initial_weight, final_weight, period);
volume=(flowrate_pm*period*(60/1000.0));
concentration=(final_weight-initial_weight)/volume;
print_pm(volume, concentration);
};break;

case 3:
{
printf("Insert the values for:\n(a) Initial weight of filter paper(micrograms):");
scanf("%f", &initial_weight);
printf("(b) Final weight of filter paper(micrograms):");
scanf("%f", &final_weight);
printf("(c) Sampling period(Hours):");
scanf("%d", &period);

print_infor(initial_weight, final_weight, period);
volume=(flowrate_tsp*period*(60/35.3147));
concentration=(final_weight-initial_weight)/volume;
print_tsp(volume, concentration);
};break;
default:printf("Invalid Choice");
}
getchar();
printf("\n\nDo YOU Want to CONTINUE? (Y is Yes, N is No):");
scanf("%c", &cont);
}while(cont=='y'||cont=='Y');
printf("Terminated...Thank You!!!");
};break;
}
return 0;
}

void print_id(long int id)
{
FILE*leix;
if((leix=fopen("user.txt","a"))==NULL)
printf("File can't be opened");
else
{
if(id==81130276)
{
printf("Welcome Mr Khiew Siee Kung");
fprintf(leix, "\nWelcome Mr Khiew Siee Kung");
}
else
printf("Invalid ID");
}
}



void print_password(long int pass)
{
if(pass==88842585)
{
printf("\nPassword is correct");
printf("\nProceed......");
}
else
{
printf("\nInvalid Password");
printf("\nSystem Terminated......");
printf("\nThank You!");
}
}

void print_infor(float initial_weight, float final_weight, int period)
{
printf("\nInitial weight of filter paper= %.2f micrograms", initial_weight);
printf("\nFinal weight of filter paper= %.2f micrograms", final_weight);
printf("\nSampling period= %d hours", period);
printf("\n\n");
}

void print_pm(float volume, float concentration)
{
printf("\nVolume of air that passed through the filter during the sampling period= %.2f m3", volume);
printf("\nConcentration of Particulate Matter(PM)= %.2f micrograms/m3", concentration);
}

void print_tsp(float volume, float concentration)
{
printf("\nVolume of air that passed through the filter during the sampling period= %.2f m3", volume);
printf("\nConcentration of Total Suspended Particulate Matter(TSP)= %.6f micrograms/m3", concentration);
}

void print_infor_case1(float initial_weight, float final_weight, int period)
{
FILE*leix;
if((leix=fopen("user.txt","a"))==NULL)
printf("File can't be opened");
else
{
printf("\nInitial weight of filter paper= %.2f micrograms", initial_weight);
fprintf(leix, "\nInitial weight of filter paper= %.2f micrograms", initial_weight);
printf("\nFinal weight of filter paper= %.2f micrograms", final_weight);
fprintf(leix, "\nFinal weight of filter paper= %.2f micrograms", final_weight);
printf("\nSampling period= %d hours", period);
fprintf(leix, "\nSampling period= %d hours", period);
printf("\n\n");
}
}

void print_pm_case1(float volume, float concentration)
{
FILE*leix;
if((leix=fopen("user.txt","a"))==NULL)
printf("File can't be opened");
else
{
printf("\nVolume of air that passed through the filter during the sampling period= %.2f m3", volume);
fprintf(leix, "\nVolume of air that passed through the filter during the sampling period= %.2f m3", volume);
printf("\nConcentration of Particulate Matter(PM)= %.2f micrograms/m3", concentration);
fprintf(leix, "\nConcentration of Particulate Matter(PM)= %.2f micrograms/m3", concentration);
}
}

void print_tsp_case1(float volume, float concentration)
{
FILE*leix;
if((leix=fopen("user.txt","a"))==NULL)
printf("File can't be opened");
else
{
printf("\nVolume of air that passed through the filter during the sampling period= %.2f m3", volume);
fprintf(leix, "\nVolume of air that passed through the filter during the sampling period= %.2f m3", volume);
printf("\nConcentration of Total Suspended Particulate Matter(TSP)= %.6f micrograms/m3", concentration);
fprintf(leix, "\nConcentration of Total Suspended Particulate Matter(TSP)= %.6f micrograms/m3", concentration);
}
}

void print_infor_case2(float initial_weight, float final_weight, int period)
{
FILE*lexa;
if((lexa=fopen("login.txt","a"))==NULL)
printf("File can't be opened");
else
{
printf("\nInitial weight of filter paper= %.2f micrograms", initial_weight);
fprintf(lexa, "\nInitial weight of filter paper= %.2f micrograms", initial_weight);
printf("\nFinal weight of filter paper= %.2f micrograms", final_weight);
fprintf(lexa, "\nFinal weight of filter paper= %.2f micrograms", final_weight);
printf("\nSampling period= %d hours", period);
fprintf(lexa, "\nSampling period= %d hours", period);
printf("\n\n");
}
}

void print_pm_case2(float volume, float concentration)
{
FILE*lexa;
if((lexa=fopen("login.txt","a"))==NULL)
printf("File can't be opened");
else
{
printf("\nVolume of air that passed through the filter during the sampling period= %.2f m3", volume);
fprintf(lexa, "\nVolume of air that passed through the filter during the sampling period= %.2f m3", volume);
printf("\nConcentration of Particulate Matter(PM)= %.2f micrograms/m3", concentration);
fprintf(lexa, "\nConcentration of Particulate Matter(PM)= %.2f micrograms/m3", concentration);
}
}

void print_tsp_case2(float volume, float concentration)
{
FILE*lexa;
if((lexa=fopen("login.txt","a"))==NULL)
printf("File can't be opened");
else
{
printf("\nVolume of air that passed through the filter during the sampling period= %.2f m3", volume);
fprintf(lexa, "\nVolume of air that passed through the filter during the sampling period= %.2f m3", volume);
printf("\nConcentration of Total Suspended Particulate Matter(TSP)= %.6f micrograms/m3", concentration);
fprintf(lexa, "\nConcentration of Total Suspended Particulate Matter(TSP)= %.6f micrograms/m3", concentration);
}
}

No comments: