顧客マスタファイルを作っています。ポイントカードがあり、発行した日から一年間有効なものにしています。発効日と期限日は構造体を使用しています。うるう年の場合の計算も入れたつもりです。ポイントカードの期限が切れたら、顧客コードは変えずに新規発行するシステムです。コードはcushファイルのc_codeと比較して、なかったら新規発行にしています。ポイントは別なファイルで処理し、そこから持ってきます。(cushファイルのc_pointに入っています)作り方がまったく分からなく、ここから進めません。よろしかったら教えてください。
/*顧客マスタファイル cust.dat*/
#include <stdio.h>
#include <time.h>
int date(int );
void main()
{
struct kokyaku
{
int k_code;
short h_nen,h_tsuki,h_hi;
short k_nen,k_tsuki,k_hi;
}kokyaku;
FILE *cf;
int k_point=0;
int dt,year,month,day;
printf("今日の日付を入力(YYYY MM DD):");
scanf("%d %d %d",&kokyaku.h_nen,&kokyaku.h_tsuki,&kokyaku.h_hi);
year=kokyaku.h_nen;
month=kokyaku.h_tsuki;
day=kokyaku.h_hi
dt=date(int year,int month,int day);
}
int date(int year,int month,int day)
{
int k_year,k_month,k_day,pt;
kokyaku.k_nen=(kokyaku.h_nen)+1;
if((kokyaku.h_tsuki==3) && (kokyaku.h_hi==1)){
if((kokyaku.k_nen%4==0) && (kokyaku.k_nen%100!=0)){
kokyaku.k_tsuki=kokyaku.h_tsuki-1;
kokyaku.k_hi=29;
}else{
kokyaku.k_tsuki=kokyaku.h_tsuki-1;
kokyaku.k_hi=28;
}
}else if(kokyaku.h_hi==1){
kokyaku.k_tsuki=kokyaku.h_tsuki-1;
kokyaku.k_hi=kokyaku.h_hi;
}
cf=fopen("../datafile/cush.dat","r");
while((kokyaku.k_code) == c_code){
if((kokyaku.k_code)!=EOF){
dt=date();
}else if((kokyaku.k_nen) < (kokyaku.h_nen) || (kokyaku.k_tsuki) < (kokyaku.h_tsuki) || (kokyaku.k_hi) < (kokyaku.h_hi))
k_point=0;
}
}
k_year=kokyaku.k_nen;
k_month=kokyaku.k_tsuki;
k_day=kokyaku.k_hi;
pt=k_point;
return (k_year,k_month,k_day,pt);
}
無題
Re:無題
レジファイルはこれです。
/*レジファイル cush.dat*/
#include <stdio.h>
void main()
{
FILE *smf,*stf,*cuf,*cf;
int c_code;
int gokei=0;
int money;
smf=fopen("../datafile/s_mast.dat","r+");
cuf=fopen("../datafile/cush.dat","w");
cf=fopen("../datafile/cust.dat","r+");
while(scanf("%d",&c_code)!=NULL){
while(c_code==s_code){
gokei+=tanka;
zaiko-=1;
}
}
fseek(smf,0L,0);
printf("合計は%d円です",gokei);
scanf("%d",&money);
money-=gokei;
printf("おつりは%d円です",money);
k_point=gokei*(0.05);
printf("今回のポイントは%dポイントです",k_point);
}
/*レジファイル cush.dat*/
#include <stdio.h>
void main()
{
FILE *smf,*stf,*cuf,*cf;
int c_code;
int gokei=0;
int money;
smf=fopen("../datafile/s_mast.dat","r+");
cuf=fopen("../datafile/cush.dat","w");
cf=fopen("../datafile/cust.dat","r+");
while(scanf("%d",&c_code)!=NULL){
while(c_code==s_code){
gokei+=tanka;
zaiko-=1;
}
}
fseek(smf,0L,0);
printf("合計は%d円です",gokei);
scanf("%d",&money);
money-=gokei;
printf("おつりは%d円です",money);
k_point=gokei*(0.05);
printf("今回のポイントは%dポイントです",k_point);
}
Re:無題
商品マスターはこれです。
/*商品マスタファイル s_mast.dat*/
#include <stdio.h>
void main()
{
FILE *smf1,*smf2;
char s_name[20];
int tanka,zaiko;
int s_code=1;
printf("データを入力してください。(商品名、単価、在庫数)\n");
smf1=fopen("../datafile/s_mast.txt","a+");
while(scanf("%s %d %d",s_name,&tanka,&zaiko)!=EOF){
fprintf(smf1,"%d %s %d %d\n",s_code,s_name,tanka,zaiko);
s_code+=1;
}
fclose(smf1);
/*ファイル内容表示*/
printf("ファイルからデータを読み込みます。\n");
printf("商品コード 商品名 単価 在庫数 \n");
smf2=fopen("../datafile/s_mast.txt","r");
while(fscanf(smf2,"%d %s %d %d",&s_code,s_name,&tanka,&zaiko) != EOF)
printf("%d %s %d %d\n",s_code,s_name,tanka,zaiko);
fclose(smf2);
}
/*商品マスタファイル s_mast.dat*/
#include <stdio.h>
void main()
{
FILE *smf1,*smf2;
char s_name[20];
int tanka,zaiko;
int s_code=1;
printf("データを入力してください。(商品名、単価、在庫数)\n");
smf1=fopen("../datafile/s_mast.txt","a+");
while(scanf("%s %d %d",s_name,&tanka,&zaiko)!=EOF){
fprintf(smf1,"%d %s %d %d\n",s_code,s_name,tanka,zaiko);
s_code+=1;
}
fclose(smf1);
/*ファイル内容表示*/
printf("ファイルからデータを読み込みます。\n");
printf("商品コード 商品名 単価 在庫数 \n");
smf2=fopen("../datafile/s_mast.txt","r");
while(fscanf(smf2,"%d %s %d %d",&s_code,s_name,&tanka,&zaiko) != EOF)
printf("%d %s %d %d\n",s_code,s_name,tanka,zaiko);
fclose(smf2);
}
Re:無題
商品コード保存ファイルです。
いちおこれですべてのプログラムです。
/*商品コード保存ファイル*/
#include <stdio.h>
void main()
{
FILE *ssf,*smf;
int code;
int s_code;
char s_name[20];
int tanka,zaiko;
ssf=fopen("../datafile/s_stock.txt","w+");
smf=fopen("../datafile/s_mast.txt","r");
while(fscanf(smf,"%d %s %d %d",&s_code,s_name,&tanka,&zaiko)!=EOF);
code=s_code;
fprintf(ssf,"%d",code);
fclose(smf);
fclose(ssf);
}
いちおこれですべてのプログラムです。
/*商品コード保存ファイル*/
#include <stdio.h>
void main()
{
FILE *ssf,*smf;
int code;
int s_code;
char s_name[20];
int tanka,zaiko;
ssf=fopen("../datafile/s_stock.txt","w+");
smf=fopen("../datafile/s_mast.txt","r");
while(fscanf(smf,"%d %s %d %d",&s_code,s_name,&tanka,&zaiko)!=EOF);
code=s_code;
fprintf(ssf,"%d",code);
fclose(smf);
fclose(ssf);
}