Program 59) The price and quantity of items stocked in a store everyday. They may either increase or decrease. This program reads the incremental values of price and quantity and computes the total value of the item in stock.
The program illustrates the use of structure pointers as a function parameters. &item, the address of the structure item, is passed to the functions update() and mul(). The formal argument product and stock, which recieve the value of &item, are declared as pointers of type struct stores.
PROGRAM
struct stores
{
char name [20] ;
float price ;
int quantity ;
} ;
main ( )
{
void update (struct stores *, float, int) ;
float p_increment, value ;
int q_increment ;
struct stores item = {"XYZ", 25.75, 12) ;
struct stores *ptr = &item ;
printf ("\Input increment value:") ;
printf (" price increment and quantity increment\n") ;
scanf ("%f %d, &p_increment, &q-increment) ;
/* - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - /*
update (&item, p_increment, q_increment) ;
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*
printf ("Updated values of item\n\n") ;
printf ("Name : %s\n", ptr->name) ;
printf ("price : %f\n", ptr_>price) ;
printf ("Quantity : %d\n", ptr_>quantity) ;
/* - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - /*
value = mul (& item) ;
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*
printf ("\nValue of the item = %f\n", value) ;
}
void update (struct stores *product, float p, int q)
{
product->price += p ;
product->quantity += q ;
}
float mul (struct stores *stock)
{
return (stock->price * stock->quantity) ;
}
Output
Input increment value: price increment and quantity
increment
10 12
Updated value of item
Name : XYZ
price : 35.750000
Quantity : 24
Value of the item = 858.000000
No comments:
Post a Comment