Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The program must have functions as specified below: Design a C++ program that wi

ID: 669966 • Letter: T

Question

The program must have functions as specified below:

Design a C++ program that will assist a local bakery with record keeping. The input data will be in a text file called "sales.txt." The first line of the file will be the date; this can be read in as a string. Each row after that represents one item. The first integer in the row gives the amount sold of the individual item. This is followed by a float value that represents the price of the item. The last item in the row is the name of the item. A short sample content of "sales.txt" is given below.   
Write a program that will: 1. Find the total sales of the day. 2. Find the item that was sold the most using the sort() function template below. /*You Sort in descending order (i.e. largest number in location 0)*/
3. Find the item that was sold the least./*You do not have to sort again*/
4. Find the item that generated the most income. For this program, assume that the income can be found using this formula:
amount_sold_of_the_individual_item * price_of_the_item = item_income
5. Print the bakery items to the file sorted by least popular to most popular. Sort again using the sort() function template below. /*Yes. You must write two compare functions and sort again in ascending order (i.e. smallest value stored at location 0.*/

sort() function template void sort ( int listLength, int amount_sold[ ], float price[ ], string item_name[],bool (*compare) (int, int)) { …… if ((*compare) (amount_sold [i], amount_sold [j]) ) …. /*since they are parallel arrays, it is important that all arrays are sorted at the same time*/ }

Sample contents of sales.txt

February 12, 2015

17 $1.80 Premium Milk

10 $2.00 Berrytale

10 $3.50 Boroh Danish

15 $1.89 Marble Taro

12 $2.54 Chocolate Chip Bowl

15 $1.45 Mango Bread   


Sample content of report.txt: // Your Report Must Match this Report Format Exactly
Sales on February 12, 2015   
Total sales: $166.18
Most sold: Premium Milk Least sold: Boroh Danish, Berrytale   
Item with most income: Boroh Danish ($35)
Least Popular to Most Popular: 1. Berrytale (10) 2. Boroh Danish (10) 3. Chocolate Chip Bowl (12) 4. Marble Taro (15) 5. Mango Bread (15) 6. Premium Milk (17)

Explanation / Answer

#include<stdio.h>
int main()
{
int bread=15;
int breadsold,remainingbread=15,breadprofit=0;
int egg=72;
int eggsold,remainingegg=72,eggprofit=0;
int butter=25;
int buttersold,remainingbutter=25,butterprofit=0;
int milk=50;
int milksold,remainingmilk=50,milkprofit=0;
int item,x,profit1=0,profit2=0,profit3=0,profit4=0,megaprofit=0;
printf(" ****** ");
printf(" WELCOME TO BAKERY ");
printf(" CURRENTLY AVAILABLE ITEMS IN QUANTITY ");
printf(" BREAD         EGG        BUTTER        MILK ");
printf(" %d            %d         %dkg          %dl ",bread,egg,butter,milk);
printf("Current Market Rates for Respected Items are as Follow: Bread=4$ Egg=6$ Butter=2$/kg Milk=8$/ltr ");
printf("What would you like to sell ");
printf("1 for Bread ");
printf("2 for Egg ");
printf("3 for Butter ");
printf("4 for Milk ");
printf("Your choice:");
scanf("%d",&item);
if(item>4 || item<=0)
{
printf("Not a valid entry");
}
else
{
for(x=0;x!=6;x)  
{
if (item==1)
{
printf(" how much bread u want to sell ");
scanf("%d",&breadsold);
if (breadsold>remainingbread || breadsold<0)
{
printf("We dont have this much Bread to sell kindly keep it less or equal to quanitiy available ");}
else
{
remainingbread=bread-breadsold;
bread=remainingbread;
profit1= breadsold*40;
breadprofit=profit1 + breadprofit;
printf(" The quantity of Bread u have sold is %d The profit for this sale is %dRs Now you have %d bread remaining to sell ",breadsold,profit1,remainingbread);
megaprofit=breadprofit+eggprofit+butterprofit+milkprofit;
}
}
if (item==2)
{
printf("how much Egg u want to sell ");
scanf("%d",&eggsold);
if(eggsold>remainingegg || eggsold<0)
{
printf("We dont have this much Egg to sell kindly keep it less or equal to quantity available ");}
else
{
remainingegg=egg-eggsold;
egg=remainingegg;
profit2=eggsold*4;
eggprofit=profit2+eggprofit;
printf(" The quantity of Egg u have sold is %d The profit for this sale is %dRs Now you have %d Egg remaining to sell ",eggsold,profit2,remainingegg);
megaprofit=breadprofit+eggprofit+butterprofit+milkprofit ;
}
}
if (item==3)
{
printf("how much Butter u want to sell ");
scanf("%d",&buttersold);
if(buttersold>remainingbutter || buttersold<0 )
{
printf("We dont have this much Butter to sell kindly keep it less or equal to quantity available ");}
else
{
remainingbutter=butter-buttersold;
butter=remainingbutter;
profit3=buttersold*50;
butterprofit=profit3+butterprofit;
printf(" The quantity of Butter u have sold is %dkg The profit for this sale is %dRs Now you have %dkg Butter remaining to sell ",buttersold,profit3,remainingbutter);
megaprofit=breadprofit+eggprofit+butterprofit+milkprofit ;}
}
if (item==4)
{
printf("how much Milk u want to sell ");
scanf("%d",&milksold);
if(milksold>remainingmilk || milksold<0)
{
printf("We dont have this much Milk to sell kindly keep it less or equal to quantity available ");
}
else
{
remainingmilk=milk-milksold;
milk=remainingmilk;
profit4=milksold*50;
milkprofit=profit4+milkprofit;
printf(" The quantity of Milk u have sold is %dltr The profit for this sale is %dRs Now you have %dltr Milk remaining to sell ",milksold,profit4,remainingmilk);
megaprofit=breadprofit+eggprofit+butterprofit+milkprofit ;
}
}
if (item==5)
{
printf("Profit earned uptill now is %dRs",megaprofit);
}
printf(" What would you like to sell ");
printf(" 1 for Bread ");
printf(" 2 for Egg ");
printf(" 3 for Butter ");
printf(" 4 for Milk ");
printf("OR ");
printf(" 5 to view Profit earned uptill now ");
printf(" 6 if you are willing to Exit sale ");
printf("Your choice:");
scanf("%d",&item);
if( item<=0 || item>6)
{printf(" NOTE : There is no such choice Please select again ");
}
if(item==6)
{
x=6;
megaprofit=breadprofit+eggprofit+butterprofit+milkprofit ;
printf(" The Profit you earned for today's sale is %dRs You have %d BREAD %d EGG %dkg Butter %dltr MIlk left to sale HAVE A GOOD DAY ",megaprofit,remainingbread,remainingegg,remainingbutter,remainingmilk); }
}
}
printf(" ****** ");
return 0;
}