对于我的任务,我被要求这样做:
从名为“sales.txt”的文件中读取销售值,并将表示这些值的条形图输出到名为“graph.txt”的文件中。通过显示一行星号在条形图中创建每个条形。每个星号应代表100英镑的销售额 销售价值为:
1000
500
1200
600
200
图表应如下所示:
SALES BAR CHART
(each * equals £100)
Store 1: **********
Store 2: *****
Store 3: ************
Store 4: ******
Store 5: **
这是我到目前为止所做的代码:
#pragma once //stops duplicate library
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
using namespace std;
class SalesData
{
private:
ifstream inputfile;
ofstream outputfile;
vector<int> salesrecord;
public:
void loadDataFromFile(string filename);
void saveBarChartToFile(string filename);
};
void SalesData::loadDataFromFile(string filename)
{
ifstream sales;
sales.open("Sales.txt",ios::in);
cout << "opening file." << endl;
sales.close();
}
void SalesData::saveBarChartToFile(string filename)
{
ofstream graph;
graph.open("Graph.txt", ios::out);
graph << "SALES BAR CHART" << endl;
graph << " (each * equals £100)" << endl;
graph.close();
}
int main()
{
vector<int> salesrecord(5);
for (int i = 0; i < 0; i++)
{
salesrecord[i] = i;
}
SalesData Mydata;
return 0;
}