CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: C++ help

  1. #1
    Join Date
    Nov 2017
    Posts
    2

    C++ help

    Name:  Screen Shot 2017-11-14 at 3.36.25 PM.jpg
Views: 122
Size:  44.0 KBName:  Screen Shot 2017-11-14 at 3.37.49 PM.jpg
Views: 109
Size:  63.2 KB



    i am having trouble writing this code. could anybody help?

  2. #2
    Join Date
    Nov 2017
    Posts
    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

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: C++ help

    Quote Originally Posted by mpearson2 View Post
    ...
    this is what i have so far. I am already throwing a error.
    What error?
    Victor Nijegorodov

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: C++ help

    When posting code, please use code tags so that the code is readable. Go Advanced, select the formatted code and click '#'.

    Code:
    AllArays[]& info
    By default, an array is effectively passed as a pointer so you don't need the & ref.

    Code:
    AllArays info[]
    But you are not accessing info as an array - you are accessing as a struct. So do you mean

    Code:
    AllArays& info
    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
  •  





Click Here to Expand Forum to Full Width

Featured