A question on designing using ADT

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nhd
    New Member
    • Aug 2006
    • 24

    A question on designing using ADT

    I know nothing about ADT but I was told to write a program that uses appropriate ADT used to provide the various functions needed. In particular, to develop 3 files, assuming that ADT is called Moss:
    1. Moss.h // the header file
    2. Moss.cpp // the implementation file
    3. useMoss.cpp // The file containing the main() that will handle the input, calling various functions implemented, and output the
    required information.

    Sample Input:
    File 1 File 2 Lines Matched
    File1-0(71%) File2-0(63%) 177
    File1-1(59%) File2-1(63%) 167
    File1-2(49%) File2-2(54%) 101
    File1-3(42%) File2-3(51%) 130
    File1-4(53%) File2-4(47%) 92

    Sample Output:
    number of records: 19
    maxp1 = 71 minp1 = 13 avgp1 = 35 stdevp1 = 19
    maxp2 = 63 minp2 = 10 avgp2 = 36 stdevp2 = 19
    maxnline = 183 minnline = 20 avgnline = 83 stdevnline = 50

    Explanation of the output:
    The statistics tells us that there are 19 records, the maximum p1 is 71%, minimum p1 13%, average p1 35%, and the
    standard deviation of p1 is 19%. The next line is for p2 and the last line is for the number of lines found similar.

    Can anyone help me atleast to get me started by showing me how do i get about doing this program... Thanks so much... :> I desperately need help in programming...
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    I am afraid I don't see the corrolation between input and output.

    an ADT (abstracted data type) is a method where you put your data into a separate file and rather than access it directly you write a set of functions to access an manipulate it. Then the external code just calls the functions rather than accessing the data directly.

    Comment

    • Nhd
      New Member
      • Aug 2006
      • 24

      #3
      Originally posted by Banfa
      I am afraid I don't see the corrolation between input and output.

      an ADT (abstracted data type) is a method where you put your data into a separate file and rather than access it directly you write a set of functions to access an manipulate it. Then the external code just calls the functions rather than accessing the data directly.
      Hi... I didnt actually paste the whole question in... Maybe thats y u cant see any correlation between the input and the output...

      This is the actual question:

      Sample Input:
      File 1 File 2 Lines Matched
      File1-0(71%) File2-0(63%) 177
      File1-1(59%) File2-1(63%) 167
      File1-2(49%) File2-2(54%) 101
      File1-3(42%) File2-3(51%) 130
      File1-4(53%) File2-4(47%) 92
      File1-5(58%) File2-5(57%) 109
      File1-6(43%) File2-6(48%) 183
      File1-7(48%) File2-7(50%) 80
      File1-8(38%) File2-8(45%) 81
      File1-9(40%) File2-9(41%) 71
      File1-10(38%) File2-10(32%) 64
      File1-11(17%) File2-11(29%) 61
      File1-12(28%) File2-12(26%) 65
      File1-13(22%) File2-13(18%) 50
      File1-14(13%) File2-14(11%) 20
      File1-15(16%) File2-15(14%) 28
      File1-16(17%) File2-16(16%) 34
      File1-17(14%) File2-17(13%) 23
      File1-18(14%) File2-18(10%) 41

      Sample Output:
      number of records: 19
      maxp1 = 71 minp1 = 13 avgp1 = 35 stdevp1 = 19
      maxp2 = 63 minp2 = 10 avgp2 = 36 stdevp2 = 19
      maxnline = 183 minnline = 20 avgnline = 83 stdevnline = 50

      I hope ur able to see the correlation now... This program is really complex and I hav no idea abt ADT... I hope ur able to help....

      Comment

      • D_C
        Contributor
        • Jun 2006
        • 293

        #4
        I believe I understand the problem now. It has a lot to do with statistics. Each file has a companion file, for example, File1-13 and File2-13. They each have some number of lines, not necessarily the same. The lines are then compared and see how many match. I'm not sure if this is done line by line, or by using an algorithm to minimize the differences.

        After this is done for all files that follow the naming convention, some statistics are computed. Max, min, avg and stdev refer to the maximum, minimum, average, and standard deviation, respectively. 'p' is for percent, and 1 or 2 is for File1 or File2, respectively. 'nlines' is for the number of lines (per file), this probably counts both sets of files.

        For example, avgp2 = 36 means that on average, 36% of the lines in File2* had matching lines in their companion file.

        1. Find all files that fit the naming scheme
        2. Open each file and it's companion
        3. Compare each file, line by line or by algorithm.
        4. For each file, record the number of lines total, and the number of lines matched.
        5. Calculate the statistics, based on the recorded data for each file.
        6. Print the results

        Comment

        • Nhd
          New Member
          • Aug 2006
          • 24

          #5
          Originally posted by D_C
          I believe I understand the problem now. It has a lot to do with statistics. Each file has a companion file, for example, File1-13 and File2-13. They each have some number of lines, not necessarily the same. The lines are then compared and see how many match. I'm not sure if this is done line by line, or by using an algorithm to minimize the differences.

          After this is done for all files that follow the naming convention, some statistics are computed. Max, min, avg and stdev refer to the maximum, minimum, average, and standard deviation, respectively. 'p' is for percent, and 1 or 2 is for File1 or File2, respectively. 'nlines' is for the number of lines (per file), this probably counts both sets of files.

          For example, avgp2 = 36 means that on average, 36% of the lines in File2* had matching lines in their companion file.

          1. Find all files that fit the naming scheme
          2. Open each file and it's companion
          3. Compare each file, line by line or by algorithm.
          4. For each file, record the number of lines total, and the number of lines matched.
          5. Calculate the statistics, based on the recorded data for each file.
          6. Print the results

          Hi thanks for the info... But i'm still facing problems as in i cant really understand how do i go abt doing this... this is a very tough assignment and i cant handle this... :(

          Comment

          • Nhd
            New Member
            • Aug 2006
            • 24

            #6
            Code:
             #include <iostream> 
            #include <string>
            #include <sstream>
            #include "Moss.h"
            using namespace std;
             
            int main() {
             
            int i=0;
            string oneline, sentence; 
             
            cout<<"File1" << " " << "File2" << " " << "Lines Matched" << endl; 
            cin>>sentence;
            i++;
             
            while(getline(cin,oneline))
            {
            istringstream is(oneline);
            while (is>>oneline)
            {
            i++;
            }
            }
            cout<<"number of records: "<<i<<endl;
             
            system("pause");
            	return 0;
            }
            Hi, actually im supposed to type in a number of lines and then count the number of lines/sentences... However, my program above only counts the number of words that i type in and not how many sentences... Can anyone check the program for me... Please help me.... thks...
            Last edited by Niheel; Sep 5 '06, 12:40 AM.

            Comment

            • D_C
              Contributor
              • Jun 2006
              • 293

              #7
              I suggest you tackle problem #1 first, then #2, ... and finally #6. Here's some information on #1.
              Originally posted by http://www.cs.rpi.edu/courses/fall01/os/FindFirstFile.h tml

              The FindFirstFile function opens a search handle and returns information about the first file whose name matches the specified pattern. Once the search handle is established, you can use the FindNextFile function to search for other files that match the same pattern. When the search handle is no longer needed, close it by using the FindClose function.
              If you only want to count the lines, then replace
              Code:
              while(getline(cin,oneline))
              {
                istringstream is(oneline);
                while (is>>oneline)
                {
                  i++;
                }
              }
              with
              Code:
              while(getline(cin,oneline))
                i++;
              Your code divided it into lines, then into words, and counted each word instead of dividing it into lines and counting each line.

              Comment

              • Nhd
                New Member
                • Aug 2006
                • 24

                #8
                hi D_C...

                I tried that before but it still doesnt count the number of lines...
                when i type in File1-0(71%) File2-0(63%) 177, it reads as 2... i have no idea why... shouldn't it read as 1 as i input only 1 sentence... please help me to rectify this problem... thanks so much

                Comment

                • dhawalshah
                  New Member
                  • Sep 2006
                  • 1

                  #9
                  dude... look through your code.. you have an extra "i++;" before your while loop. This is why your record shows an extra line. Now that is solved..
                  Let me elaborate on your other problem since I have a similar problem.

                  Sample Input:
                  File 1 File 2 Lines Matched
                  File1-0(71%) File2-0(63%) 177
                  File1-1(59%) File2-1(63%) 167
                  File1-2(49%) File2-2(54%) 101
                  File1-3(42%) File2-3(51%) 130
                  File1-4(53%) File2-4(47%) 92

                  If i wished to extract certain information from the above input, for eg. from the first line: File1-0(71%) File2-0(63%) 177
                  I wish to extract the info "71", "63" and "177" and store them in 3 separate integer arrays before incrementing the array and moving onto the next line. How would I go about doing that?

                  Comment

                  • D_C
                    Contributor
                    • Jun 2006
                    • 293

                    #10
                    I just answered a similar question in the thread How to get individual information from a file.

                    Comment

                    Working...