0

I am writing a program called Pricing Optimiser. I would like based on the capacity (100, 200 or 300) given by the user and the number of seats sold suggest the optimal price. I will do it with the hep of Excel Database. Here is the code. The part I am missing I wrote as a text.

#include <iostream>
#include <fstream>//to work with files 
using namespace std;
int main()
{

    float capacity; //number of seats in plane/bus/train/stadium/concert hall/ 
    number of beds in a hotel
    float capacitysold;//number of seats/beds sold  


    cout << "State capacity 100 or 200 or 300:";
    cin >> capacity; //console input capacity
    cout << "State capacity sold:";
    cin >> capacitysold; //console input capacity
    //based on the capacity and capacitysold entered data by the user show me 
     from the Excel list the suggested price, please help me to write here a 
     suitable code
     system("PAUSE");

Here is the example of the Excel Data. Data is organized in excel in 3 columns (capacity, number of seats and price). Capacity will be 100, 200 or 300. Price increases with the number of seats sold and the row number of seats sold from 1 to max capacity

Capacity    Number of seats Price (EUR)
100 1   20
100 2   20
100 3   20
100 4   20
100 5   20
100 6   20
100 7   20
100 8   20
100 9   20
100 10  20
100 11  20
100 12  20
100 13  20
100 14  20
100 15  20
100 16  20
100 17  20
100 18  20
100 19  20
100 20  20
100 21  30
100 22  30
100 23  30
100 24  30
100 25  30
100 26  30
100 27  30
100 28  30
100 29  30
100 30  30
100 31  30
100 32  30
100 33  30
100 34  30
100 35  30
100 36  30
100 37  30
100 38  30
100 39  30
100 40  30
100 41  50
100 42  50
100 43  50
100 44  50
100 45  50
100 46  50
100 47  50
100 48  50
100 49  50
100 50  50
100 51  70

The data goes until 100 and the price is increased, the same below it is written for 200 and 300.

So for example if sb enters capacity 100 and number of seats sold 51 the suggested price will be 70. How to incorporate it to my C++ program?

Bo Persson
  • 88,437
  • 31
  • 141
  • 199
  • Is there some reason you're using Excel for this? Seems to me you'd be better of using a SQL database, perhaps SQLite if it's just needed for local storage. – MrEricSir Feb 27 '18 at 22:45
  • Will the code be easier to figure out in case of the SQL? Why do you reccommend SQL? – Monika C Feb 27 '18 at 22:49
  • "Easier" is a judgement call I can't make for you, but it would be more conventional to use SQL databases for storing data and retrieving/updating it programmatically. – MrEricSir Feb 27 '18 at 22:54
  • try solution from here: https://stackoverflow.com/questions/2876720/c-library-to-load-excel-xls-files – user3218782 Feb 27 '18 at 23:09
  • Looks like the better solution would be to process the Excel first. For instance, there is no need for entries `100, 1, 20` to `100, 20, 20`. You can join them as `100, [1-20], 20`. And it also appears you don't even need that `-20]` part, as it follows from the fact that the next entry is `[21-`. See C++ `std::lower_bound`. – MSalters Feb 28 '18 at 14:28

0 Answers0