Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include #include #include #include / / Function to calculate the mean price for bid and ask of each product std::unordered _ map >
#include #include #include #include #include #include Function to calculate the mean price for bid and ask of each product std::unorderedmap calculatemeanpricesconst std::string& filename std::ifstream filefilename; if file.isopen std::cerr "Error opening file: filename std::endl; return ; Map to store accumulated prices and counts for bid and ask for each product std::unorderedmap productPrices; std::string line; while std::getlinefile line std::istringstream issline; std::string product, bidAsk; double price; Assuming the product is in the second column, bidask in the third column, and price in the fifth column if iss std::quotedproduct std::quotedbidAsk price if bidAsk "BID" bidAsk "ASK" Accumulate prices and counts separately for bid and ask auto& pair productPricesproduct; bidAsk "BID" pair.first price : pair.second price; Calculate mean prices for bid and ask for each product for auto& entry : productPrices auto& pair entry.second; pair.first pair.second; Calculate mean for bid pair.second pair.second; Calculate mean for ask return productPrices; int main Example CSV file name replace with your actual file name std::string filename csv; Calculate mean prices for bid and ask auto meanPrices calculatemeanpricesfilename; Print the results std::cout std::left std::setw "Product" std::setw "Mean Bid Price" "Mean Ask Price" std::endl; for const auto& entry : meanPrices std::cout std::setw entry.first std::setw entry.second.first entry.second.second std::endl; return ; so for some reason the output doesnt want to take the info from my csv file and idk why so it just outputs an empty table of Product Mean Bid Price Mean Ask Price would appreciate any quick fix
#include
#include
#include
#include
#include
#include
Function to calculate the mean price for bid and ask of each product
std::unorderedmap calculatemeanpricesconst std::string& filename
std::ifstream filefilename;
if file.isopen
std::cerr "Error opening file: filename std::endl;
return ;
Map to store accumulated prices and counts for bid and ask for each product
std::unorderedmap productPrices;
std::string line;
while std::getlinefile line
std::istringstream issline;
std::string product, bidAsk;
double price;
Assuming the product is in the second column, bidask in the third column, and price in the fifth column
if iss std::quotedproduct std::quotedbidAsk price
if bidAsk "BID" bidAsk "ASK"
Accumulate prices and counts separately for bid and ask
auto& pair productPricesproduct;
bidAsk "BID" pair.first price : pair.second price;
Calculate mean prices for bid and ask for each product
for auto& entry : productPrices
auto& pair entry.second;
pair.first pair.second; Calculate mean for bid
pair.second pair.second; Calculate mean for ask
return productPrices;
int main
Example CSV file name replace with your actual file name
std::string filename csv;
Calculate mean prices for bid and ask
auto meanPrices calculatemeanpricesfilename;
Print the results
std::cout std::left std::setw "Product" std::setw "Mean Bid Price" "Mean Ask Price" std::endl;
for const auto& entry : meanPrices
std::cout std::setw entry.first std::setw entry.second.first entry.second.second std::endl;
return ;
so for some reason the output doesnt want to take the info from my csv file and idk why so it just outputs an empty table of Product Mean Bid Price Mean Ask Price
would appreciate any quick fix
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started