Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please hep me to modify the codes.i want the following codes in the following format date.h, time.h, weather.h, weather.cpp, vector.h, main.cpp,,,,add any if needed //header

please hep me to modify the codes.i want the following codes in the following format date.h, time.h, weather.h, weather.cpp, vector.h, main.cpp,,,,add any if needed

//header files #include#include#include#includeusing namespace std; //strcut to record data from file struct FileDataList{ public: string WAST; //WAST(date andtime) string S; //S(Wind Speed) string SR; //SR(Solar Radiation) string T; //T(Ambient airtemperature) FileDataList *next; }; FileDataList *head; //readingFromFile //reading from file //and store it in strcut attributes using linkList void readingFromFile(string fileName) { ifstream file; file.open(fileName.c_str()); if (file.fail()) cout << " Error! Open File."; else { string line; string token; int Linecount = 1; int Wordcount = 1; string Data[4]; int index = 0; while (getline(file, line)) { stringstream ss(line); if (Linecount !=1) { while (getline(ss, token, ',')) { if (Wordcount == 1) { Data[index] = token; index++; } else if (Wordcount==11) { Data[index] = token; index++; } else if (Wordcount == 12) { Data[index] = token; index++; } else if (Wordcount == 18) { Data[index] = token; index++; }

Wordcount++; if (index == 4) { FileDataList*list = new FileDataList(); list->WAST = Data[0]; list->S = Data[1]; list->SR= Data[2]; list->T = Data[3]; cout << list->WAST << " " << list->S <<" " << list->SR << " "<T<< endl; list->next = NULL; if (head == NULL) head = list; else { FileDataList*temp = head; while (temp->next!=NULL) { temp = temp->next; } temp->next = list; } index = 0; Wordcount = 1; break; } }} Linecount++; } } file.close(); }

class date //class date { public: //3 variables - day, month, year int day; int month; int year;

void setDay(int d) //setters { this->day = d; } void setMonth(int m) { this->month = m; }

void setYear(int y) { this->year = y; }

//getters int getDay() { return this->day; } int getMonth() { return this->month; } int getYear() { return this->year; } };

//class time

class time { public: //2 variables - minute, hour int minute; int hour; }; class weather : date //class weather inherited from date { date d; FileDataList *list; float wSpeed; float temperature; float solarRadiation; string token; int count = 1; bool match = false; public: //array to store months static const string months[12]; //function to show wind speed and temperature //passing month and year to it void showSandT(int m, int y) { list = head; while (list->next != NULL) { stringstream ss(list->WAST); while (getline(ss, token, '/')) { if (count == 1) { d.setDay(stoi(token)); count++; } else if (count == 2){ d.setMonth(stoi(token)); count++; } else if (count == 3){ count = 1; stringstream ss(token);

while (getline(ss, token, ' ')) { d.setYear(stoi(token)); break; } break; } } if (d.getMonth() == m) { if (d.getYear() == y) { for (int i = 0; i < 12; ++i) { if (i+1 == d.getMonth()) cout << " " << months[i]; }

cout << " " << d.getYear() << ": "; cout<< list->S << "km/h, " << list->T << " degree C"; match = true; } } if (match) return; list = list->next; } if (!match) { cout <<" "<< m << " " << y << ": No data"; } } //function to show wind speed and temperature using year void showSandT(int y) { match = false; list = head; cout << " " << y << endl; while (list->next!=NULL) { stringstream ss(list->WAST); while (getline(ss, token, '/')) { if (count == 1) { this->setDay(stoi(token)); count++; } else if (count == 2){ this->setMonth(stoi(token)); count++; } else if (count == 3){ count= 1; stringstream ss(token); while (ss, token, ' ') { this->setYear(stoi(token)); break; } break; } } if (getYear() == y) { for(int i = 0; i < 12; ++i) { if(i + 1 == getMonth()) cout << " " << months[i]; } cout << ": "; cout << list->S << "km/h, " << list->T << " degree C"<next;} if (!match) { cout <<" "<< y << ": No data"; }} //function to show solar rediation using year void showSR(int y) { match = false; list = head; cout << " " << y << endl; while (list->next != NULL) { stringstream ss(list->WAST); while (getline(ss, token, '/')) { if (count == 1) { this->setDay(stoi(token)); count++; } else if (count == 2){ this->setMonth(stoi(token)); count++; } else if (count == 3){ count = 1; stringstream ss(token); while (getline(ss, token, ' ')) { this->setYear(stoi(token)); break; break; } } if (getYear() == y) { for (int i = 0; i < 12; ++i) { if(i+1 == getMonth()) cout << " " << months[i]; } cout << ": "; cout << list->SR << "kWh/m2"<next; } if (!match) { cout <<" " << y << ": No data"; } }

//function to show all data fields using year

void showSTSR(int y) { match = false; list = head; cout << " "<< y << endl; while (list->next != NULL) { stringstream ss(list->WAST); while (getline(ss, token, '/')){ if (count == 1) { this->setDay(stoi(token)); count++;} else if (count == 2){ this->setMonth(stoi(token)); count++; } else if (count == 3){ count = 1; stringstream ss(token); while (getline(ss, token, ' ')) { this->setYear(stoi(token)); break; } break; } } if (getYear() == y) { for (int i = 0; i < 12; ++i) { if (i + 1 == getMonth()) cout << " " << months[i]; } cout << ", "; cout << list->S << ", " << list->T << ", " << list->SR << endl; match = true; } list = list->next; }

if (!match) { cout << " " << y << ": No data"; }}};

//initialising months array

const string weather::months[12] = { "January","February", "March","April", "May", "June","July", "August", "September", "October", "November", "December" }; //main function to test program //its provide menu for user int main() { //link list head to null head = NULL; //reading from file //which accepts file address readingFromFile("DataSample.txt"); //weather class object initialisation

weather *w = new weather(); int y; int m; string menue; int choice = 0; again: system("cls");

cout << "\t\t\t***Menu***" << endl; cout << " 1.wind speed and temperature (year & month)"<< " 2.wind speed and temperature (year)" << " 3.solar radiation in kWh/m2 (year)" <<" 4.wind speed (km/h), temperature and total solar radiation in kWh/m2 (year)" <<" 5.Exit"<< endl; cout << " Enter Your Choice: "; cin >> choice; switch (choice) { case 1: cout << " Enter year(like 2020): "; cin >> y; cout << " Enter month(like 03): "; cin >> m; w->showSandT(m, y); cout << " Want to Move In Menue -> yes or no : "; cin >> menue; if (menue == "yes") goto again; else return 0; break;

case 2: cout << " Enter year(like 2020): "; cin >> y; w->showSandT(y); cout << " Want to Move In Menue -> yes or no : "; cin >> menue; if (menue == "yes") goto again; else return 0; break; case 3 cout << " Enter year(like 2020): " cin >> y; w->showSR(y); cout << " Want to Move In Menue -> yes or no : "; cin >> menue; if (menue == "yes") goto again; else return 0; break; case 4 { cout << " Enter year(like 2020): "; cin >> y; w->showSTSR(y); cout <<" Want to Move In Menue -> yes or no : "; cin >> menue; if (menue == "yes") goto again; else return 0; break; } case 5:{return 0;}

default:{ cout << "Invalid Input!"; cout << " Want to Move In Menue -> yes or no : "; cin >> menue; if (menue == "yes") goto again; else return 0;}}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Accounting questions