Plot the graph of the stock price history to std::cout.
135 {
136 float highest_price;
137 float lowest_price;
138 string stockname;
139 vector<float> stockpricehistory =
graphinput(player, stocknum, stockname, width);
140
141 vector<string> color(width - 9,
textWhite);
143 if (stockpricehistory.size() <= 1) {
144 cout << "Why do you want to plot graph if there is only one data point?"
145 << endl;
146 return;
147 }
148 highest_price = *max_element(stockpricehistory.begin(), stockpricehistory.end());
149 lowest_price = *min_element(stockpricehistory.begin(), stockpricehistory.end());
150 float interval = (highest_price - lowest_price) / height;
151 vector<vector<string>> graph(width, vector<string>(height, " "));
152
153
154 string maxstring;
155 string minstring;
156 if (interval == 0) {
159 }
160 else {
163 }
164
165 for (int i = 0; i < 6; i++) {
166 graph[i][0] = maxstring[i];
167 graph[i][height - 1] = minstring[i];
168 }
169
170
171 for (unsigned int i = 0; i < stockpricehistory.size() - 1; i++) {
172 int start = 10;
173 int end = 10;
174 if (interval != 0) {
175 start = (height - 1) - (stockpricehistory[i] - lowest_price) / interval;
176 end = (height - 1) - (stockpricehistory[i + 1] - lowest_price) / interval;
177
178 if (start < 0) {
179 start = 0;
180 }
181 if (end < 0) {
182 end = 0;
183 }
184 if (start >= height) {
185 start = height - 1;
186 }
187 if (end >= height) {
188 end = height - 1;
189 }
190 }
191 if (start == end) {
192 graph[i + 9][start] = "■";
193 if (stockpricehistory[i] > stockpricehistory[i + 1]) {
195 }
196 else if (stockpricehistory[i] < stockpricehistory[i + 1]) {
198 }
199 }
200 if (start > end) {
201 for (int j = end; j <= start; j++) {
202 graph[i + 9][j] = "■";
203 }
205 }
206 else if (start < end) {
207 for (int j = start; j <= end; j++) {
208 graph[i + 9][j] = "■";
209 }
211 }
212
213
214 }
215 for (int i = 0; i < height; i++) {
216 graph[8][i] = "┃";
217 }
218 for (int i = 9; i < width; i++) {
219 graph[i][height - 1] = "━";
220 }
221 graph[8][height - 1] = "┗";
224}
void printstocknameandoverall(const string &stockname, vector< float > stockpricehistory, int stocknum)
string graphpriceformat(float price)
vector< float > graphinput(const string &player, int stocknum, string &stockname, unsigned int width)
void printgraphblocks(const vector< vector< string > > &screenElements, const vector< string > &specifiedColorCoordinates, const int width, const int height)