Connecting Tech Pros Worldwide Forums | Help | Site Map

A question on designing using ADT

Nhd Nhd is offline
Newbie
 
Join Date: Aug 2006
Posts: 24
#1: Sep 2 '06
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's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,200
#2: Sep 2 '06

re: A question on designing using ADT


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.
Nhd Nhd is offline
Newbie
 
Join Date: Aug 2006
Posts: 24
#3: Sep 3 '06

re: A question on designing using ADT


Quote:

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....
D_C D_C is offline
Needs Regular Fix
 
Join Date: Jun 2006
Posts: 294
#4: Sep 3 '06

re: A question on designing using ADT


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
Nhd Nhd is offline
Newbie
 
Join Date: Aug 2006
Posts: 24
#5: Sep 4 '06

re: A question on designing using ADT


Quote:

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... :(
Nhd Nhd is offline
Newbie
 
Join Date: Aug 2006
Posts: 24
#6: Sep 4 '06

re: A question on designing using ADT


Expand|Select|Wrap|Line Numbers
  1.  #include <iostream> 
  2. #include <string>
  3. #include <sstream>
  4. #include "Moss.h"
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9. int i=0;
  10. string oneline, sentence; 
  11.  
  12. cout<<"File1" << " " << "File2" << " " << "Lines Matched" << endl; 
  13. cin>>sentence;
  14. i++;
  15.  
  16. while(getline(cin,oneline))
  17. {
  18. istringstream is(oneline);
  19. while (is>>oneline)
  20. {
  21. i++;
  22. }
  23. }
  24. cout<<"number of records: "<<i<<endl;
  25.  
  26. system("pause");
  27.     return 0;
  28. }
  29.  
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...
D_C D_C is offline
Needs Regular Fix
 
Join Date: Jun 2006
Posts: 294
#7: Sep 4 '06

re: A question on designing using ADT


I suggest you tackle problem #1 first, then #2, ... and finally #6. Here's some information on #1.
Quote:

Originally Posted by http://www.cs.rpi.edu/courses/fall01/os/FindFirstFile.html


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
Expand|Select|Wrap|Line Numbers
  1. while(getline(cin,oneline))
  2. {
  3.   istringstream is(oneline);
  4.   while (is>>oneline)
  5.   {
  6.     i++;
  7.   }
  8. }
with
Expand|Select|Wrap|Line Numbers
  1. while(getline(cin,oneline))
  2.   i++;
Your code divided it into lines, then into words, and counted each word instead of dividing it into lines and counting each line.
Nhd Nhd is offline
Newbie
 
Join Date: Aug 2006
Posts: 24
#8: Sep 4 '06

re: A question on designing using ADT


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
Newbie
 
Join Date: Sep 2006
Posts: 1
#9: Sep 5 '06

re: A question on designing using ADT


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?
D_C D_C is offline
Needs Regular Fix
 
Join Date: Jun 2006
Posts: 294
#10: Sep 5 '06

re: A question on designing using ADT


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