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

C++ You are the owner of a pawnshop. Each and everyday you sell a number of item

ID: 3813341 • Letter: C

Question

C++

You are the owner of a pawnshop. Each and everyday you sell a number of items. At the end of the day you wish to know what your net profits are during the day. The gross profit is computed as the difference between the selling price and the price you paid for the item. To calculate the net profit you subtract 6% of the selling price from the gross profit and subtract 10% of the selling price for overhead. The resulting value is the net profit. Your program will read in the record of sales for the day. For each product sold there will be a record of sales for that product. We don’t know how many products were sold. The program will read in the name of the item, the actual cost of the item, and the number of this item that sold. Following this there will be data for each of this type of item. It will consist of the selling price for the item that was sold. When the program reads all of the data for an item it is to calculate the gross profit and net profit as described previously. The program is to output the name of the item, followed by the gross profit for the item, followed by the net profit for the item. The table is to be neatly displayed and money values should look like money. After this display the program will read the next item sold or it will read the word “fine” meaning that there are no more items sold to process. All of the tasks written for the program should be written as functions. The main function calls these functions to carry out the work of the program (Remember, functions can call other functions). The main program should do NO INPUT, and NO OUTPUT. No global variables may be used.

Explanation / Answer

#include <iostream>
#include <string>

using namespace std;

class Item {
public:
   string name;
   int units;
   double cp; //cost
   double sp; //sell price

   double netProfit;
   double grossProfit;
   Item() {
       name = "";
       units = 0;
       cp = 0;
       sp = 0;
       netProfit = 0;
       grossProfit = 0;
   }
};

int isEndReading(string name) {
   if (name.compare("fine") == 0 || name.compare("FINE") == 0) {
       return 1;
   }
   return 0;
}

void printItem(Item it) {
   cout <<" Item Name        : " << it.name <<endl;
   cout <<" Acutal Cost      : " << it.cp <<endl;
   cout <<" No of items Sold : " << it.units <<endl;
   cout <<" Selling Price    : " << it.sp <<endl;
   cout <<" Gross Profit     : " << it.grossProfit <<endl;
   cout <<" Net Profit       : " << it.netProfit <<endl <<endl;

}

Item readItem() {
   Item it = Item();
   cout << "Enter item name (Enter 'fine' to exit):" << endl;
   cin >> it.name;
   if (isEndReading(it.name ) == 0) {
       cout << "Enter acutual cost of time: " << endl;
       cin >> it.cp;
       cout << "Enter no of units of item sold: " << endl;
       cin >> it.units;
       cout << "Enter selling price of the item: " << endl;
       cin >> it.sp;
       return it;
   }

}

Item calculateProfits(Item it) {

   //gross profit
   //The gross profit is computed as the difference between the selling price and the price you paid for the item.
   it.grossProfit = (it.sp - it.cp) * it.units;
   //cout << (it.sp - it.cp) <<endl;
   //To calculate the net profit you subtract 6% of the selling price from the gross profit and subtract 10% of the selling price for overhead
   it.netProfit = it.grossProfit - ((0.06 * it.sp + 0.1 * it.sp) * it.units);
//   cout <<" Gross Profit     : " << it.grossProfit <<endl;
//   cout <<" Net Profit       : " << it.netProfit <<endl <<endl;
   return it;
}

int main() {
    Item item;
   do {
       item = readItem();
       if(isEndReading(item.name) == 1)
           break;
       else {
           item = calculateProfits(item);
           printItem(item);
       }
   } while (true);
   return 1;
}

------------------output----------------

DebugChegg-cpp-current.exe
Enter item name (Enter 'fine' to exit):
sweetpan
Enter acutual cost of time:
5.5
Enter no of units of item sold:
10
Enter selling price of the item:
8.5
Item Name        : sweetpan
Acutal Cost      : 5.5
No of items Sold : 10
Selling Price    : 8.5
Gross Profit     : 30
Net Profit       : 16.4

Enter item name (Enter 'fine' to exit):
extrasweet
Enter acutual cost of time:
6.5
Enter no of units of item sold:
20
Enter selling price of the item:
9
Item Name        : extrasweet
Acutal Cost      : 6.5
No of items Sold : 20
Selling Price    : 9
Gross Profit     : 50
Net Profit       : 21.2

Enter item name (Enter 'fine' to exit):
fine

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote