Thread: output statistics for software similarity

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    29

    Exclamation need help...does anyone knows how to write header and implementation code for ADT?

    I'm working on a ADT. I'm writing a program to cin a software similarity report and to cout output on a number of statistics after running MOSS. So far, I've only been able to piece together a rudimentary code for the header and implementation file. (because i'm new to C++)...
    a sample line of output from MOSS(which is the input for my program)

    File1-111(71%) File2-111(63%) 101

    means that 71% of code of file1 is similar to 63% code of file2 , 177 lines similar and is the record number 101. if record number is 101, means there are 101 files received. this match is based on the highest level of similarity so file1 will not be matched to another file for another percentage rating..

    now i've to refine my header...

    Code:
    // File: Moss.h
    using namespace std;
    class Moss {                    //class definition for Moss
    
    //private:
    //protected:
    
    public:
    Moss(double p1_cent, double p2_cent, int nlines, int rec_num);
    
    double get_p1_cent() const;
    double get_p2_cent() const;
    int get_nlines() const;
    int get_rec_num() const;
    double get_stdev() const;
    
    };
    and my implementation file

    Code:
    // File name: Moss.cpp
    #include "Moss.h"
    #include <iostream>
    #include <cmath>
    
    //Moss method definitions
    
    Moss::Moss(double pp1_cent, double pp2_cent, int nnlines, int nrec_num)
    {
    p1_cent = pp1_cent;
    p2_cent = pp2_cent;
    nlines = nnlines;
    rec_num = nrec_num;
    }
    
    double Moss::get_p1_cent() const
    {
    return p1_cent;
    }
    
    double Moss::get_p2_cent() const
    {
    return p2_cent;
    }
    
    double Moss::get_nlines() const
    {
    return nlines;
    }
    
    double Moss::get rec_num() const
    {
    return rec_num;
    }
    
    double Moss::stdev(int record[n], double mean)
    {
    
    for(n=0;n<= rec_num;n++)
    
    {
     sqrt(pow((record[n]*mean),2))/(n-1);
    }
    
    return result;
    }
    and then also to design a main() function to cin all the data that is in the report....
    can someone help??
    Last edited by wind_lark; 09-06-2006 at 06:14 PM.

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    You'll have to overload the << operator. Here's a link that discusses overloading it - http://cboard.cprogramming.com/showt...t=overload+cin

    Why can't you just get all the info, from standard cin's to variables of the right type, and use a member setter in your class?

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    29

    Question stuck

    i'm not clear about overloading.assuming that i could extract required info from a line, (line 1 for e.g.) , what function do i use to store the variables while i read the same variables for ( line 2,..., line n) different lines of output??

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    29

    Unhappy how to get rid of qn mark at end of output?

    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main () {
      char c, str[256];
      ifstream is;
    
      cout << "Enter the name of an existing text file: ";
      cin.get (str,256);
    
      is.open (str);        
      while (is.good())      {
        c = is.get();       
        cout << c;
      }
    
      is.close();           
    
      return 0;
    }
    i found a way but how come a question mark keeps appearing at end of file output even when the file does not contains that question mark?

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You shouldn't use good() to control your loop like that. If get() fails, it will set the flag to bad after it attempts to read. Your code outputs the character even if the get() fails, and then breaks the loop. You should change your loop to check for good before outputting the result of get().

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    29

    Unhappy wat is wrong?

    even before i got to extract the required...My above mentioned header and implementation code are all wrong...

    for each line of "File1-111(71%) File2-111(63%) 101"
    in the report output that i need to cin,

    i need variables for digit that comes with the filename, the record number(e.g. 111) ,the first percentage and second percentage...to calculate statistics later on...

    can someone please help?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  2. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  3. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  4. Control different DA output value!
    By Hunterhunter in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 03-13-2003, 12:11 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM