| | |
Read File Issue
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
You need to make all your arrays that deal with the Loanc data type of that type - not int. In the case of function readData, it needs to have a return type of Loanc*, not int*. You will also need to modify your print function - it's fine for an int array, but has no clue about an array of Loanc object.
Remember, in a function, the type of value you return must agree with the datatype of the function header/prototype.
Remember, in a function, the type of value you return must agree with the datatype of the function header/prototype.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
•
•
Join Date: Nov 2008
Posts: 10
Reputation:
Solved Threads: 0
I understand that much but when I plug Loanc into the function type, the compiler starts cursing at me saying that it isnt a viable function type. I cant seem to get the return type and the function type to match.
And yeah print array was giving me difficulties so i commented it out till I get the first problem sorted out.
And yeah print array was giving me difficulties so i commented it out till I get the first problem sorted out.
Last edited by CMacDady; Nov 20th, 2008 at 6:33 pm.
Here's your loanclass.cpp fixe. It now compiles. I won't swear that it's actually working correctly, as I've no data file to test with. Things I fixed are commented.
cpp Syntax (Toggle Plain Text)
//#include "stdafx.h" //do you really need this? #include <iostream> #include <cmath> #include "Loanc.h" #include <fstream> using namespace std; Loanc* readData(string fname, int & arrSz); //FIXED void printArray(Loanc arr[], int sz); //FIXED int main(){ cout << "Test to Create and display Loans: " << endl; Loanc l1; Loanc l2('H', 'A', 700); Loanc l3('H', 'X', 400); cout << "Add $500 to AA, returns " << l1.changeBalance(500) << ", " << l1 << endl; cout << "Subtract $500 from HA, returns " << l2.changeBalance(-500) << ", " << l2 << endl; cout << "Subtract $600 from HX, returns " << l3.changeBalance(-600) << ", " << l3 << endl; cout << "END LOAN TEST." << endl; int resultSize = 0; int fileSize = 0; string fname = "cmpt128a4data1.txt"; //Read test file and print it Loanc* fileArr = readData(fname, fileSize); //FIXED if (fileArr != NULL){ printArray(fileArr, fileSize); //cout << "resultSize initially set to " << resultSize << endl; //int arr[] = {1,2,2,2,4,5,7,7,7}; }else{ cout << "File not read proporly"; } cout << endl; // Free up dynamic memory delete[] fileArr; system("pause"); return 0; } Loanc* readData(string fname, int & arrSz){ //FIXED Loanc* result = NULL; arrSz = 0; char f; char s; double bal; // Create a file object and open the file ifstream inStream; inStream.open(fname.c_str()); // Only process file if opening it is successful if(!inStream.fail()){ inStream >> arrSz; result = new Loanc[arrSz]; // Read file contents into result, now that size is known //create results array for(int i = 0; i < arrSz ; i++){ inStream >> f >> s >> bal; result[i] = Loanc(f,s,bal); } inStream.close(); //don't forget to close file } return result; } void printArray(Loanc arr[], int sz){ //FIXED //cout << "{"; //for (int i = 0; i < sz; i++){ // cout << arr[i]; // if (i < sz - 1){ //you gotta fix the body // cout << ","; // } //} //cout << "}"; }
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Similar Threads
- Error 624: The system could not update the phone book file (Windows NT / 2000 / XP)
- Writing to INI file issue (C#)
- Making a page read-only (PHP)
- script to address restartibily issue (Shell Scripting)
- Need help resolving background issue.. (Viruses, Spyware and other Nasties)
- Input Output File Streams - Sorting Help With Array (C++)
- 100% CPU Usage - No Virus, No gaming (Windows NT / 2000 / XP)
- IE TCP/IP Socket Issue? (Web Browsers)
- file unable to open (C++)
Other Threads in the C++ Forum
- Previous Thread: Free safe DLL to play with
- Next Thread: How do I get rid of this C4716: must return a value error I get every time i compile?
Views: 977 | Replies: 13
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy dll download dynamic encryption error file forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return simple sort spoonfeeding stream string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






