(
(
(救命
Write a program in C to input information of 8 computer suppliers who are participuting a tender to supply computers indentification number, supplier number, name, address and quotation price. The program reads the output file and finds the lowest quotation price and prints all the information of the supplier. Using the following structure supplier in the program.
struct Supplier
{
int tenderID;
int supplierNo;
char name[20];
char address[40];
float quotationPrice;
};
typedef struct Supplier Sup;
Sup dealer[8];
Filename:Supplier.dat
/*Name: Lynn*/
/*Date: 16-05-2007*/
#include <conio.h>
#include <stdio.h>
struct Supplier
{
int tenderID;
int supplierNo;
char name[20];
char address[40];
float quotationPrice;
};
typedef struct Supplier Sup;
main()
{
/*Function Prototype*/
void Info(Sup A[]);
void LowestPrice(Sup B[]);
/*Declaration*/
Sup dealer[8];
clrscr();
/*Call Function*/
Info(dealer);
LowestPrice(dealer);
gotoxy(30,24);
printf("Press ENTER to continue");
getch();
}
/**************************/
/*Function name : Info */
/*Input : Sup A[] */
/*Output : void */
/**************************/
void Info(Sup A[])
{
/*Declaration*/
FILE *fin;
int index;
/*Open File*/
fin=fopen("D:Supplier.dat","w");
/*Error Message*/
if(fin==NULL)
{
printf("CANNOT Create New File");
exit(1);
}
/*Input Records*/
for(index=0; index<8; index++)
{
clrscr();
gotoxy(30,5);
printf("Record No: %d",index+1);
gotoxy(30,6);
printf("Tender ID Number: ");
gotoxy(30,8);
printf("Supplier Number: ");
gotoxy(30,10);
printf("Name: ");
gotoxy(30,12);
printf("Address :");
gotoxy(30,14);
printf("Quotation Price: ");
gotoxy(45,6);
scanf("%d",&A[index].tenderID);
gotoxy(45,8);
scanf("%d",&A[index].supplierNo);
fflush(stdin);
gotoxy(45,10);
gets(A[index].name);
gotoxy(45,12);
gets(A[index].address);
gotoxy(45,14);
scanf("%f",&A[index].quotationPrice);
}
/*Write to disk*/
for(index=0; index<8; index++)
{
fprintf(fin,"%-6d",A[index].tenderID);
fprintf(fin,"%-5d",A[index].suplierNo);
fprintf(fin,"%-21s" A[index].name);
fprintf(fin,"%-41s",A[index].address);
fprintf(fin,"%-.2f\n",A[index].quotationPrice);
}
/*Close File*/
fclose(fin);
}
/********************************/
/*Function Name : LowestPrice */
/*Input : Sup B[] */
/*Output : void */
/********************************/
void LowestPrice(Sup B[])
{
/*Declaration*/
FILE *flow;
int index;
int pass;
Sup temp;
/*Open File*/
flow=fopen("D:Supplier.dat","r");
/*Error Message*/
if(flow==NULL)
{
printf("CANNOT read the FIle!!");
exit(1);
}
/*Read from disk*/
for(index=0; index<8; index++)
{
fscanf(flow,"%d",&B[index].tenderID);
fscanf(flow,"%d",&B[index].supplierNo);
fscanf(flow,"%s",&B[index].name);
fscanf(flow,"%s",&B[index].address);
fscanf(flow,"%f\n",&B[index].quotationPrice);
}
/*Print the List*/
clrscr();
gotoxy(30,5);
printf("%-6s%-5s%-21s%-41s%-s\n","ID","No","Name","Address","Price");
for(index=0; index<8; index++)
{
printf("%-6d",B[index].tenderID);
printf("%-5s",B[index].supplierNo);
printf("%-21s",B[index].name);
printf("%-41s",B[index].address);
printf("%.2f\n",B[index].quotationPrice);
}
/*Sorting*/
for(pass=1; pass<8; pass++)
{
for(index=0; index<8-pass; index++)
{
if(B[index+1].quotationPrice < B[index].quotationPrice)
{
/*Swap data*/
temp=B[index];
B[index]=B[index+1];
B[index+1]=temp;
}
}
}
}
/*print the lowest price*/
printf("%-6d%-5d%-21d%-41s%.2f",B[0].tenderID,B[0].supplierNo,B[0].name,B[0].address,B[0].quotationPrice);
/*Close File*/
fclose(flow);
}
在screen出現了
Quotation Price: floating point formats not linked
Adnormal program termination