Hello. This is my first C++ class, and my first go at writing loops. I have the first part of the code written, but I am confused about the for loop for this assignment. My textbook is giving me a headache. Are there better resources out there, or any advice? I am just not really sure how to approach it at this point. Here is the assignment:
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, following 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. The main program should do NO INPUT, and NO OUTPUT. No global variables may be used.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include <iostream>
#include <cmath>
using namespace std;
//Instructs the user.
void printInstructions()
{
cout << "This program will calculate and display" << endl;
cout << "the gross and net profits of today's sales." << endl << endl;
cout << "Enter the name of the item, the cost, the number" << endl;
cout << "of this item that sold, and the store's selling price." << endl << endl;
cout << "Press <return> after each entry." << endl << endl;
}
//Obtain name of item.
string getItem()
{
string item;
cout << "Enter name of item: ";
cin >> item;
return item;
}
//Obtain the price paid for the item.
double getPricePaid()
{
double pricePaid;
cout << "Enter the cost of item: ";
cin >> pricePaid;
return pricePaid;
}
//Obtain the number of this item that sold.
int numberSold()
{
int sold;
cout << "Enter the number of this item that sold: ";
cin >> sold;
return sold;
}
//Obtain the selling price.
double getSellingPrice()
{
double sellingPrice;
cout << "Enter the selling price of the item: ";
cin >> sellingPrice;
return sellingPrice;
}
//Calculate gross profits.
int main()
{
string item; //Item name.
double pricePaid; //Item cost.
int sold; //Number of item that sold.
double sellingPrice; //Selling price of the item.
printInstructions();
item = getItem();
pricePaid = getPricePaid();
sold = numberSold();
sellingPrice = getSellingPrice();
return 0;
}
|