-
November 14th, 2017, 07:48 PM
#1
C++ help
i am having trouble writing this code. could anybody help?
-
November 14th, 2017, 08:23 PM
#2
Re: C++ help
Code:
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
#include<cstdlib>
#include<climits>
const int MAX_ROWS = 10;
const int MAX_COLS = 10;
using namespace std;
typedef int BitArray[MAX_ROWS][MAX_COLS];
struct ResultArrays
{
BitArray orArray;
BitArray andArray;
BitArray xorArray;
int rows;
int cols;
};
struct AllArrays
{
ResultArrays resultarrays;
};
void OpenInputFile(ifstream&);
bool ReadInputFile(int arg[], ifstream&);
//void calculateOrArray();
//void calculateXOrArray();
//void calculateANDArray();
//void ArrayInt1(IntArray);
//void PrintArrays(IntArray, int[][COLS]);
int main()
{
ifstream inFile;
AllArrays info;
OpenInputFile(inFile);
if (inFile.fail() && !inFile.eof())
{
string infilename;
cout<<" \nProcessing information. Please wait...."<<endl;
cout << endl << string(15,'*') << "File Read Error"<<string(15,'*')<<endl;
cout << "==> An error has occured while reading\n";
cout << "==> the input file. Error in file content\n " << infilename <<endl;
cout << "==> Terminating program!!!"<<endl;
cout << string(47, '*')<< endl<<endl;
inFile.clear();
}
return 0;
}
void OpenInputFile(ifstream& inFile)
{
string infilename;
cout<<endl;
cout << " Enter name of input file:";
cin >> infilename;
cin.ignore(INT_MAX,'\n');
cout << infilename << endl;
inFile.open(infilename.c_str());
while (inFile.fail())
{
cout << endl << string(15,'*') << "File Open Error"<<string(15,'*')<<endl;
cout << "==> Input file failed to open properly!!\n";
cout << "==> Attempted to open file: " << infilename <<endl;
cout << "==> Please try again...\n";
cout << string(47, '*')<< endl<<endl;
inFile.clear();
cout << " Enter name of input file:";
cin >> infilename;
cin.ignore(INT_MAX,'\n');
cout << infilename << endl;
inFile.open(infilename.c_str());
}
}
bool ReadInputFile(AllArays[]& info,ifstream& inFile)
{
getline(inFile, info.resultarrays.orArray,'\n');
return bool(inFile);
}
this is what i have so far. I am already throwing a error.
Last edited by 2kaud; November 15th, 2017 at 04:48 AM.
Reason: Added code tags
-
November 15th, 2017, 02:52 AM
#3
Re: C++ help
Originally Posted by mpearson2
...
this is what i have so far. I am already throwing a error.
What error?
Victor Nijegorodov
-
November 15th, 2017, 05:00 AM
#4
Re: C++ help
When posting code, please use code tags so that the code is readable. Go Advanced, select the formatted code and click '#'.
By default, an array is effectively passed as a pointer so you don't need the & ref.
But you are not accessing info as an array - you are accessing as a struct. So do you mean
Also note that the function declarations need to match the function definition
Code:
bool ReadInputFile(int arg[], ifstream&);
...
bool ReadInputFile(AllArays[]& info,ifstream& inFile)
These need to be the same.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|