Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help Needed

Need Helps completing this Assignment,,,Started to code but now stuck,,,
Please can anyone help complete it .
Thanks.
(I have posted code on bottom)

A small shopkeeper uses a simple computer system to keep an up to date inventory of
all products stocked. Every week the shopkeeper updates the stock file with a series of
stock amendments, stored on another file. The format of both TEXT FILES is shown
below, with each record stored in ascending order of product code, and each field being
separated by a comma. Both files tenninate with a special "sentinel" product code of
9999.

Stock File.

Product Code 4 digits
Quantity 4 digits (in the range 1000 to 9999)
Buying Price 4 digits
Sale Price 4 digits

Stock Amendments File.

Product Code 4 digits
Amendment Type 1 character 'I' for an issue from stock.
'R' for a receipt into stock.
'B' for an amendment to the buying price.
'S' for an amendment to the sale price.
'D' for a deletion of the stock item.

Value 4 digits

NOTE
The data item "Value" will be zero in the case of a stock item deletion.

Write a program that will update the existing stock file, creating a new stock file, in the
same order as the original. It is possible that a stock item will have one, more than one,
or no transactions during a week. After the update of a master record, any stock item
that is outside the given range should also have the record written to a "query file".
You can assume that there are no transactions in the stock amendments file that do not
have matching product codes in the stock file.


#include
#include
#include
#define MIN 1000
#define MAX 9998

int main()
{
FILE *file_ptr;
int p_code, qty, amend_p_code, amend_value, *p, *p1;
float buy_price, sale_price;
char amend_type;
p1=&amend_p_code;
p=&p_code;
if ( (file_ptr = fopen("shoptext.dat","wt")) == NULL)
{
printf("

ERROR OPENING FILE
Suspending application");
exit(1);
}
printf("
ENTER AMENDMENT TYPE
'I'ssue from stock :
'R'eceipt into stock :");
printf("
'B'uying price amendment :
'S'ale price amendment :");
printf("
'D'eletion of stock item :

-> ");
amend_type=toupper(fgetc(stdin));
switch(amend_type)
{
case 'I':
case 'R':
break;
case 'D':amend_value=0;
case 'B':printf("

Please enter product code -> ");
fflush(stdin);
scanf("%d",&p_code);
printf("

Please enter quantity (1000 - 9999) -> ");
fflush(stdin);
scanf("%d",&qty);
if(qtyMAX)
fprintf(stderr,"OUTSIDE GIVEN RANGE");
printf("

Please enter new BUY PRICE -> ");
fflush(stdin);
scanf("%f",&buy_price);
printf("

Please enter sale price ->");
fflush(stdin);
scanf("%f",&sale_price);
fprintf(file_ptr,"%d,%d,%f,%f
",p_code,qty,buy_price,sale_price);
break;
case 'S':printf("

Please enter new SALE PRICE -> ");
fflush(stdin);
scanf("%f",&sale_price);
fprintf(file_ptr,"%d,%d,%f,%f
",p_code,qty,buy_price,sale_price);
break;
default:break;
}
fclose(file_ptr);
return 0;
}

Comments

  • speedsterspeedster Member Posts: 6
    : Need Helps completing this Assignment,,,Started to code but now stuck,,,
    : Please can anyone help complete it .
    : Thanks.
    : (I have posted code on bottom)
    :
    : A small shopkeeper uses a simple computer system to keep an up to date inventory of
    : all products stocked. Every week the shopkeeper updates the stock file with a series of
    : stock amendments, stored on another file. The format of both TEXT FILES is shown
    : below, with each record stored in ascending order of product code, and each field being
    : separated by a comma. Both files tenninate with a special "sentinel" product code of
    : 9999.
    :
    : Stock File.
    :
    : Product Code 4 digits
    : Quantity 4 digits (in the range 1000 to 9999)
    : Buying Price 4 digits
    : Sale Price 4 digits
    :
    : Stock Amendments File.
    :
    : Product Code 4 digits
    : Amendment Type 1 character 'I' for an issue from stock.
    : 'R' for a receipt into stock.
    : 'B' for an amendment to the buying price.
    : 'S' for an amendment to the sale price.
    : 'D' for a deletion of the stock item.
    :
    : Value 4 digits
    :
    : NOTE
    : The data item "Value" will be zero in the case of a stock item deletion.
    :
    : Write a program that will update the existing stock file, creating a new stock file, in the
    : same order as the original. It is possible that a stock item will have one, more than one,
    : or no transactions during a week. After the update of a master record, any stock item
    : that is outside the given range should also have the record written to a "query file".
    : You can assume that there are no transactions in the stock amendments file that do not
    : have matching product codes in the stock file.
    :
    :
    : #include
    : #include
    : #include
    : #define MIN 1000
    : #define MAX 9998
    :
    : int main()
    : {
    : FILE *file_ptr;
    : int p_code, qty, amend_p_code, amend_value, *p, *p1;
    : float buy_price, sale_price;
    : char amend_type;
    : p1=&amend_p_code;
    : p=&p_code;
    : if ( (file_ptr = fopen("shoptext.dat","wt")) == NULL)
    : {
    : printf("

    ERROR OPENING FILE
    Suspending application");
    : exit(1);
    : }
    : printf("
    ENTER AMENDMENT TYPE
    'I'ssue from stock :
    'R'eceipt into stock :");
    : printf("
    'B'uying price amendment :
    'S'ale price amendment :");
    : printf("
    'D'eletion of stock item :

    -> ");
    : amend_type=toupper(fgetc(stdin));
    : switch(amend_type)
    : {
    : case 'I':
    : case 'R':
    : break;
    : case 'D':amend_value=0;
    : case 'B':printf("

    Please enter product code -> ");
    : fflush(stdin);
    : scanf("%d",&p_code);
    : printf("

    Please enter quantity (1000 - 9999) -> ");
    : fflush(stdin);
    : scanf("%d",&qty);
    : if(qtyMAX)
    : fprintf(stderr,"OUTSIDE GIVEN RANGE");
    : printf("

    Please enter new BUY PRICE -> ");
    : fflush(stdin);
    : scanf("%f",&buy_price);
    : printf("

    Please enter sale price ->");
    : fflush(stdin);
    : scanf("%f",&sale_price);
    : fprintf(file_ptr,"%d,%d,%f,%f
    ",p_code,qty,buy_price,sale_price);
    : break;
    : case 'S':printf("

    Please enter new SALE PRICE -> ");
    : fflush(stdin);
    : scanf("%f",&sale_price);
    : fprintf(file_ptr,"%d,%d,%f,%f
    ",p_code,qty,buy_price,sale_price);
    : break;
    : default:break;
    : }
    : fclose(file_ptr);
    : return 0;
    : }
    :
    :
    Oh ok so you never been needing help when you lot started,,,,,thanks a frigging lot. cheers,,,,,you will need help one day.
  • jeffpostjeffpost Member Posts: 316
    : : Need Helps completing this Assignment,,,Started to code but now stuck,,,
    : : Please can anyone help complete it .
    : : Thanks.
    : : (I have posted code on bottom)
    : : :
    : Oh ok so you never been needing help when you lot started,,,,,thanks a frigging lot. cheers,,,,,you will need help one day.
    :

    www.tuxedo.org/~esr/faqs/smart-questions.html

    In particular note the sections titled "Don't post homework questions" and "On not reacting like a loser".

    Rather than give us a lot of unformatted code and asking us to do your homework assignment for you, try to solve the problem yourself, and if you're stuck at some point, [italic]politely[/italic] ask a [italic] pertinent [/italic] question, and you might get a useful reply.


Sign In or Register to comment.