Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Specification file for the NuberArrayClass
- //a.k.a NumberArrayClass.h file
- #ifndef NUMBERARRAYCLASS_H
- #define NUMBERARRAYCLASS_H
- using namespace std;
- // class declaration
- class NumberArrayClass
- {
- private:
- int arraySize;
- double * numberArray = nullptr;
- public:
- //constructor declaration
- NumberArrayClass();
- //member functions
- void readDataFromFile();
- void displayArray();
- //destructor
- ~NumberArrayClass()
- {
- delete[] numberArray;
- } // end of destructor
- };
- #endif // NUMBERARRAYCLASS_H
- //NumberArrayClass.cpp file
- #include "NumberArrayClass.h" //needed to access arry
- #include <iostream>
- #include <fstream> //needed for file read
- using namespace std;
- NumberArrayClass::NumberArrayClass()
- {
- arraySize = 250;
- numberArray = new double[arraySize];
- }
- void NumberArrayClass::readDataFromFile()
- {
- //creating a read object and opening file.
- ifstream inFile;
- inFile.open("DoubleData.txt");
- int countIt = 0; //this is a counter
- if (!inFile.fail())
- {
- cout << "File open!" << endl;
- //this should populate the
- while (countIt < arraySize && inFile >> numberArray[countIt]);
- {
- countIt++; //incramenting counter.
- }
- }
- else
- {
- cout << "File Read fail!" << endl;
- }//end of if/else statement.
- }//end of readDataFromFile
- void NumberArrayClass::displayArray()
- {
- for (int i = 0; i < arraySize; i++)
- {
- cout << numberArray[i] << endl;
- }
- }//end of displayArray
- //main .cpp file
- #include <iostream>
- #include "NumberArrayClass.h"
- using namespace std;
- int main()
- {
- //creating our class object.
- NumberArrayClass array1;
- array1.readDataFromFile();
- array1.displayArray();
- system("pause");
- return 0;
- }
- while (... && inFile >> numberArray[countIt]);
- numberArray = new double[arraySize];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement