Question
[C++] So I am suppose to read from the file and store the data in an array in class, Am I on the right track?
[C++] So I am suppose to read from the file and store the data in an array in class, Am I on the right track? How do I store the data with the class? Lastly, I would run it in main.
GDP.TXT FILE
1947q2 -0.6 1947q3 -0.3 1947q4 6.2 1948q1 6.5 1948q2 7.6 1948q3 2.2 1948q4 0.6 1949q1 -5.4
HERE IT THE ACTUAL PROGRAM REQUIREMENT:
Their read methods should receive the filename, try to open the file, display an error message if the file cannot be opened. If it can be opened, the method should read the data and store it in an array attribute of the class.
IN GDP.CPP
#include #include #include"GDP.h"
void GDP::get(){ int temp; cout << "Enter year from 1948-2009: "; cin >> temp; fstream file; file.open("Gdp.txt", ios::in); file.seekg(0,ios::beg);
if (!file){ cout << "File could not be opened." << endl; exit(EXIT_FAILURE); }
while(file >> year >> data){ if(year == temp){ cout << "Year: " << year << endl; cout << "Data: " << data << endl; } cout << year << data; file.close(); } }
********************************* This is all I have in MAIN... I wanted to check if my GDP.cpp file worked. Error occurs when I try to make an object of the class...
MAIN
int main() {
gdp.get();
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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