Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3021

Help with Coding (Newbie)

$
0
0
Hi Guys, Need help with this code. Using codeblocks and getting error that the template is not being recognised. Code is as follows: Code: --------- #include #include #include #include #include #include void menu(vector& windlog); void readFile(ifstream& inputFile, vector& windlog); void averageWind(int monthNum, vector& windlog); int main() { vector windlog; ifstream inputFile("MetData-31-3.csv"); if(!inputFile) return -1; readFile(inputFile, windlog); menu(windlog); return 0; } void readFile(std::ifstream& inputFile, std::vector& windlog) { float tempSpeed; int timeIndex, windSpeedIndex, radiationIndex; int columns = 18, field = 0; std::string tempDate, tempTime; std::string headers[20]; std::string nStream; for(int i = 0; i < columns -1; i++) { getline(inputFile, headers[i], ','); if(headers[i] == "WAST") timeIndex = i; if(headers[i] == "S") windSpeedIndex = i; if(headers[i] == "SR") radiationIndex = i; } getline(inputFile, headers[17]); if(inputFile) { std::string token; std::stringstream iss, dateStream; while(getline(inputFile, nStream)) { iss << nStream; while(getline(iss, token, ',')) { if(field == timeIndex) { dateStream << token; getline(dateStream, tempDate, ' '); getline(dateStream, tempTime); } if(field == windSpeedIndex) { tempSpeed = std::atof(token.c_str()); } field++; } field = 0; iss.clear(); dateStream.clear(); WindData windSpeed(tempDate, tempTime, tempSpeed); windlog.push_back(windSpeed); windSpeed.print(); } std::cout << "Vector Size: " << windlog.size() << std::endl; } } void averageWind(int yearNum, std::vector& windlog) { std::string month[12] = {"January", "February", "March", "April", "May", "June", "July", "August" "September", "October", "November", "December"}; int monthCount = 0, monthNum[12] = {0}, monthAverage[12] = {0}; int dayCount[12] = {0}, totalWindSpeed[12] = {0}, totalRadiation[12] = {0}, mWindAverage[12] = {0}; for (WindData& windData : windlog) { if (windData.getYear() == yearNum) { int i = windData.getMonth() - 1; totalWindSpeed[i] += windData.getSpeed(); dayCount[i]++; } } std::cout << "Wind Speed: " << totalWindSpeed[i] << std::endl; std::cout << "Day Count: " << dayCount[i] << std::endl; for (int i = 0; i < 12; i++) { mWindAverate[i] = totalWindSpeed[i] / dayCount[i]; } std::cout << mWindAverage[i]; std::cout << month[i]; } void menu(std::vector& windlog) { int option = 0; while(option != 5) { std::cout << "Menu:" << std::endl; std::cout << "1: \tPrint the maximum wind speed for a specified month & year" << std::endl; std::cout << "2: \tPrint the average wind speed for each month of a specified year" << std::endl; std::cout << "3: \tPrint the total solar radiation for each month of a specified year" << std::endl; std::cout << "4: \tAverage wind speed & solar radiation for each month of a specified year\n\tSaved to file." << std::endl; std::cout << "5: \tExit the program.\n\n" << std::endl; std::cin >> option; switch(option) { case 1: break; case 2: int year; std::cout << "Please enter a year" << std::endl; std::cin >> year; averageWind(year,windlog); break; case 3: break; case 4: break; case 5: std::cout << "Exiting..." << std::endl; break; } } } --------- *winddata.h:* Code: --------- #ifndef WINDDATA_H #define WINDDATA_H using namespace std; template class vector{ public: /**default constructor*/ vector(int size = 100000); vector(Vector& otherList); ~vector(); /**data members*/ private: WindData *list ; int length; int maxSize; }; /** implementation of template class*/ template vector::vector(int size) { maxSize = listSize; length = 0; list = new WindData[maxSize]; } template vector::~vector() { delete[] list; } /**end of class*/ #endif ---------

Viewing all articles
Browse latest Browse all 3021