filing

This is a discussion on filing within the C++ Programming forums, part of the General Programming Boards category; hey guys ! i have been given an assignment as pasted below : You will be given two files. Grid.txt ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    27

    filing

    hey guys ! i have been given an assignment as pasted below :
    You will be given two files.
    Grid.txt will contain a grid of letters (as shown below)

    Code:
    j q v r l k u v e r s i o n l
    d v k e r n e l t u m e d i a
    i e c k s n d y v x k d n w e
    r k u c w g e c b a l z u s j
    r p h a l d a t a o t w h x d
    q x p h d s i f w m a c a p a
    w d p b d q f r t o z r r o o
    p a o m o u s e f n r l d t l
    r t l s c a a t c i b k w p n
    o a i u u p z n j t l z a a w
    g b a v m b n i z o x e r l o
    r a m g e e a r n r j g e q d
    a s e w n y c p y c v b b t z
    m e q d t n s e q j f g v x b
    v x i n i v b o i p v v t j b
    Words.txt: containing a list of words as shown below.
    data database document download email file hacker hardware kernel keyboard laptop media monitor mouse network printer program scan undo version

    You have to write a program which find all the words given in Words.txt from the gird given in Grid.txt. The words can be in any direction - horizontal, vertical or diagonal. It should write a new file Output.txt which writes a modified grid such that letters not in any word are replaced by blanks. (See example below)

    Code:
    - - - r - k - v e r s i o n -
    - - k e r n e l - - m e d i a
    - - - k - n - y - - - - n - -
    - - - c - - e - b - - - u - -
    - - - a - d a t a o - - h - d
    - - - h - - - - w m a - a p a
    - d - - d - - r - o - r r o o
    p a - m o u s e f n r - d t l
    r t l - c - - t - i - k w p n
    o a i - u - - n - t l - a a w
    g b a - m - n i - o - e r l o
    r a m - e - a r - r - - e - d
    a s e - n - c p - - - - - - -
    m e - - t - s - - - - - - - -
    - - - - - - - - - - - - - - -

    Your code should work for a grid of any size and a word list of any size as well (Use dynamic memory allocation, static arrays are not allowed; wasting memoery is not allowed). Your program should be able to figure out the size of the grid by reading the file (No user input!)
    So far i have written this much code :

    Code:
     
    #include <iostream>
        
    #include <fstream>
        
    using namespace std;
    
    char **Read_Grid(ifstream & inFile, int Rows, int Cols);
    
    int main()
        
    {
      int Rows = 0;
      int Cols = 0;
      ifstream inFile;
      inFile.open("grid.txt");
      char **ptr = Read_Grid(inFile, Rows, Cols);
      for (int i = 0; i < Rows; i++)
         {
        for (int j = 0; j < Cols; j++)
           {
          cout << ptr[i][j] << " ";
          }
        cout << endl;
        }
      
          system("pause");
      return 0;
    }
    
    
    char **Read_Grid(ifstream & inFile, int Rows, int Cols)
        
    {
      
      char **grid = new char *[Rows];
      
          if (!inFile.is_open())
         {
        cout << " opening of file failed " << endl;
        }
      for (int i = 0; i < Rows; i++)
         {
        grid[i] = new char[Cols];
        }
      
          for (int i = 0; i < Rows; i++)
         {
        for (int j = 0; j < Cols; j++)
           {
          inFile >> grid[i][j];
          }
        }
      
          return grid;
    }
    i have a problem that it does not display anything .,. how will my code be able to know the size of the grid ??
    Last edited by Salem; 03-03-2013 at 07:06 AM. Reason: fixed horrible mess of tags - next time "PASTE AS TEXT"

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    Your third thread with the same meaningless 1-word topic.
    How To Ask Questions The Smart Way
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    27
    Quote Originally Posted by Salem View Post
    Your third thread with the same meaningless 1-word topic.
    How To Ask Questions The Smart Way


    ????

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    2,484
    This line wastes memory and is not portable!

    Code:
    system("pause");
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. filing
    By waqas94 in forum C++ Programming
    Replies: 3
    Last Post: 03-03-2013, 04:56 AM
  2. filing
    By waqas94 in forum C++ Programming
    Replies: 4
    Last Post: 03-03-2013, 01:32 AM
  3. A little problem with filing in C
    By TheUmer in forum C Programming
    Replies: 19
    Last Post: 03-22-2010, 11:33 AM
  4. how to make a program using Filing in C++?
    By zedora in forum C++ Programming
    Replies: 1
    Last Post: 01-14-2010, 10:24 AM
  5. filing problems..urgent...
    By must in forum C++ Programming
    Replies: 0
    Last Post: 07-23-2002, 04:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21