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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <sstream>
#include <list>
void ReadShares();
//void GetShares();
//void GetHighestPrice();
//void GetLowestPirce();
using std::cout;
using std::endl;
using std::cin;
int main()
{
char menu = ' ';
ReadShares();
do {
cout << "The Menu Options available are as follows - "
"\n1: Date, highest price and Start time(s) of the highest share price"
"\n2: Date, Lowest price, Stat time(s) of the lowest share price"
"\n3: output.csv"
"\n4: Exit the program"
"\n\nEnter option: ";
cin >> menu;
cout << endl;
switch (menu)
{
case '1':
break;
case '2':
break;
case'3':
break;
case'4':
cout << "Exit, thank you" << endl;
break;
default:
cout << "Sorry, invalid option" << endl;
}
}
while (menu != '4');
return 0;
}
class Date {
int dd;
int mm;
int yyyy;
public:
Date() : dd(1), mm(1), yyyy(1900) { }
Date(int d, int m, int y) : dd(d), mm(m), yyyy(y) { }
friend std::ostream & operator<<(std::ostream & os, const Date & dt)
{
return os << dt.dd << '/' << dt.mm << '/' << dt.yyyy;
}
};
class Time24 {
int hh;
int mm;
int ss;
public:
Time24() : hh(0), mm(0), ss(0) { }
Time24(int h, int m, int s) : hh(h), mm(m), ss(s) { }
friend std::ostream & operator<<(std::ostream & os, const Time24 & tm)
{
char f = os.fill('0');
os << std::setw(2) << tm.hh << ':'
<< std::setw(2) << tm.mm << ':'
<< std::setw(2) << tm.ss;
os.fill(f);
return os;
}
};
class Shares {
Date date;
Time24 time;
double price;
int volume;
double value;
std::string cond;
public:
Shares() : price(0), volume(0), value(0) { }
Shares(Date dt, Time24 tm, double prc, int vol, double val, std::string cnd)
: date(dt), time(tm), price(prc), volume(vol), value(val) , cond(cnd) { }
friend std::ostream & operator<<(std::ostream & os, const Shares & sh)
{
return os << sh.date << ' '
<< sh.time << ' '
<< std::setw(10) << sh.price
<< std::setw(10) << sh.volume
<< std::setw(10) << sh.value
<< ' ' << std::left << sh.cond << std::right ;
}
};
void ReadShares()
{
std::ifstream inFile("Couse_of_sales.txt");
inFile.ignore(100, '\n');
inFile.ignore(100, '\n');
#define List std::list
List<Shares> shareList;
std::string line;
while (std::getline(inFile, line))
{
std::istringstream ss(line);
std::string dateTime;
std::getline(ss, dateTime, ',');
std::istringstream dttm(dateTime);
char c1, c2, c3, c4;
int d, m, y, hr, min, sec;
std::string ap;
dttm >> d >> c1 >> m >> c2 >> y;
dttm >> hr >> c3 >> min >> c4 >> sec >> ap;
if (ap == "PM" && hr != 12)
{
hr += 12;
}
Date date1(d, m, y);
Time24 time1(hr, min, sec);
double tPrice, val;
int vol;
std::string cond;
ss >> tPrice >> c1;
ss >> vol >> c2;
ss >> val >> c3;
getline(ss, cond);
Shares s1(date1, time1, tPrice, vol, val, cond);
cout << s1 << endl;
shareList.push_back(s1);
}
}
|