home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 14 Text / 14-Text.zip / results.zip / count.cpp next >
C/C++ Source or Header  |  1994-05-23  |  3KB  |  96 lines

  1. /* x.cpp */
  2.  
  3. #include <stream.h>
  4. #include <string.h>
  5.  
  6. enum { MAJOR, AGREE, INDIFFERENT, OPPOSED, TOTAL };
  7.  
  8. int main( void)
  9. {
  10.     int Major;
  11.     int Minor;
  12.     int Vote;
  13.     int Matrix[ 99][ 55][ 5];
  14.  
  15.     ifstream File( "parsedvote");
  16.  
  17.     memset( Matrix, 0, sizeof( Matrix));
  18.  
  19.     while ( 1) {
  20.         File >> Major >> Minor >> Vote;
  21.         if ( ! File.good()) {
  22.             break;
  23.         }
  24.         ++ Matrix[ Major][ Minor][ Vote];
  25.         ++ Matrix[ Major][ Minor][ TOTAL];
  26.     }
  27.  
  28.     cout.fill( ' ');
  29.     cout.setf( ios::left);
  30.     cout << setw( 6) << "Item";
  31.     cout.unsetf( ios::left);
  32.  
  33.     cout << setw( 10) << "YES!";
  34.     cout << setw( 10) << "Agree";
  35.     cout << setw( 10) << "Indif";
  36.     cout << setw( 10) << "Opposed" << endl;
  37.     cout.unsetf( ios::right);
  38.  
  39.     for ( Major = 1; Major < 99; ++ Major) {
  40.         for ( Minor = 1; Minor < 55; ++ Minor) {
  41.             if ( Matrix[ Major][ Minor][ TOTAL] != 0) {
  42.                 cout.setf( ios::right);
  43.                 cout << setw( 2) << Major << '.';
  44.                 cout.unsetf( ios::right);
  45.  
  46.                 cout.setf( ios::left);
  47.                 cout << setw( 3) << Minor;
  48.                 cout.unsetf( ios::left);
  49.  
  50.                 cout.setf( ios::right);
  51.                 cout << setw( 10) << Matrix[ Major][ Minor][MAJOR]; 
  52.                 cout << setw( 10) << Matrix[ Major][ Minor][AGREE];
  53.                 cout << setw( 10) << Matrix[ Major][ Minor][INDIFFERENT];
  54.                 cout << setw( 10) << Matrix[ Major][ Minor][OPPOSED];
  55.                 cout << setw( 10) << Matrix[ Major][ Minor][TOTAL] << endl;
  56.                 cout.unsetf( ios::right);
  57.             }
  58.         }
  59.     }
  60.  
  61.     cout.fill( ' ');
  62.     cout.setf( ios::left);
  63.     cout <<  "\n\nPercentages\n\n";
  64.     cout << setw( 6) << "Item";
  65.     cout.unsetf( ios::left);
  66.  
  67.     cout << setw( 10) << "YES!";
  68.     cout << setw( 10) << "Agree";
  69.     cout << setw( 10) << "Indif";
  70.     cout << setw( 10) << "Opposed" << endl;
  71.     cout.unsetf( ios::right);
  72.  
  73.     cout.setf( ios::fixed);
  74.  
  75.     for ( Major = 1; Major < 99; ++ Major) {
  76.         for ( Minor = 1; Minor < 55; ++ Minor) {
  77.             if ( Matrix[ Major][ Minor][ TOTAL] != 0) {
  78.                 cout.setf( ios::right);
  79.                 cout << setw( 2) << Major << '.';
  80.                 cout.unsetf( ios::right);
  81.  
  82.                 cout.setf( ios::left);
  83.                 cout << setw( 3) << Minor;
  84.                 cout.unsetf( ios::left);
  85.  
  86.                 cout.setf( ios::right);
  87.                 cout << setw( 10) << setprecision( 2) << (float) Matrix[ Major][ Minor][MAJOR] / Matrix[ Major][ Minor][ TOTAL] * 100;
  88.                 cout << setw( 10) << setprecision( 2) << (float) Matrix[ Major][ Minor][AGREE] / Matrix[ Major][ Minor][ TOTAL] * 100;
  89.                 cout << setw( 10) << setprecision( 2) << (float) Matrix[ Major][ Minor][INDIFFERENT] / Matrix[ Major][ Minor][ TOTAL] * 100;
  90.                 cout << setw( 10) << setprecision( 2) << (float) Matrix[ Major][ Minor][OPPOSED] / Matrix[ Major][ Minor][ TOTAL] * 100 << endl;
  91.                 cout.unsetf( ios::right);
  92.             }
  93.         }
  94.     }
  95. }
  96.