免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1011 | 回复: 2
打印 上一主题 下一主题

初学者碰到点问题.请指教 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-04-21 08:09 |只看该作者 |倒序浏览
下面是一个function,我原意是用来分类列表的,当调用C,V,M,A的时候分别会询问F或者S,并显示具体number,而不是xx.dat下的列表顺序.可是我的code就是不能正常显示,但是不知道哪里错了.请各位帮我看看..

//============================================================================

void VehicleAnalysis (void)
{
   char cVehicle;
   char cMode;

   cout << "Enter user selection of vehicle type C/V/M/A : " << endl;
   cin >;>; cVehicle;

   cout << "Enter selection of full report or summary F/S : " << endl;
   cin >;>; cMode;
   cout << endl;

   if ((cVehicle == 'C') || (cVehicle == 'V') || (cVehicle == 'M'))
   {
      DisplayReport(cVehicle, cMode);
   }

   else if (cVehicle == 'A')
   {
      DisplayReport('C', cMode); cout << endl << endl;
      DisplayReport('V', cMode); cout << endl << endl;
      DisplayReport('M', cMode);
   }

   // wait for user
   Continue();
}
//============================================================================

void DisplayReport (char cVehicleType, char cMode)

{
   const int iMAX = 200;  // maximun number of journey to process

   ifstream fileJourney;          // input file

   int iDriver;               // journey data
   char cVehicle;
   int iMins;
   int iDistance;

   int iIndex;                     // loop count
   int iCJourCount;                // count of CAR journeys
   int iVJourCount;                // count of VAN journeys
   int iMJourCount;                // count of MINIBUS journeys
   int iCDriverArray [iMAX];
   int iVDriverArray [iMAX];
   int iMDriverArray [iMAX];
   float fCJourValue[iMAX];    // array of car journey values
   float fVJourValue[iMAX];    // array of van journey values
   float fMJourValue[iMAX];    // array of minibus journey values
   float fCAverageVal;             // average value of car journey values
   float fVAverageVal;             // average value of van journey values
   float fMAverageVal;             // average value of minibus journey values
   float fCTotalVal;               // total value of car journey values
   float fVTotalVal;               // total value of van journey values
   float fMTotalVal;               // total value of minibus journey values

   // open file and check status
   fileJourney.open("journey.dat", ios::in);
   if (fileJourney.bad())
   {
      cout << "Error opening file." << endl;
      exit(-1);
   }

   //initialise
   iCJourCount = 0;
   iVJourCount = 0;
   iMJourCount = 0;

   // read first record
   fileJourney >;>; iDriver >;>; cVehicle >;>; iMins >;>; iDistance;

   // loop until end of file
   while (!fileJourney.eof() && iCJourCount < iMAX && iVJourCount < iMAX && iMJourCount < iMAX)
   {
      if (cVehicle == 'C')
      {
         // store CAR journey values in arrays and increment journey count
         iCDriverArray[iCJourCount] = iDriver;
         fCJourValue[iCJourCount] = CalcEfficiency(iMins, iDistance);
         iCJourCount++;

         // sum up total value of car journey values
         fCTotalVal = 0;
         for (iIndex = 0; iIndex < iCJourCount; iIndex++)
         {
            fCTotalVal = fCTotalVal + fCJourValue[iIndex];
         }

         // calculate average value of CAR journey values
         fCAverageVal = fCTotalVal / iCJourCount;

         // read next record
         fileJourney >;>; iDriver >;>; cVehicle >;>; iMins >;>; iDistance;
      }

      else if (cVehicle == 'V')
      {
         // store van journey values in arrays and increment journey count
         iVDriverArray[iVJourCount] = iDriver;
         fVJourValue[iVJourCount] = CalcEfficiency(iMins, iDistance);
         iVJourCount++;

         // sum up total value of VAN journey values
         fVTotalVal = 0;
         for (iIndex = 0; iIndex < iVJourCount; iIndex++)
         {
            fVTotalVal = fVTotalVal + fVJourValue[iIndex];
         }

         // calculate average value of VAN journey values
         fVAverageVal = fVTotalVal / iVJourCount;

         // read next record
         fileJourney >;>; iDriver >;>; cVehicle >;>; iMins >;>; iDistance;
      }

      else if (cVehicle == 'M')
      {
         // store MINIBUS values in arrays and increment journey count
         iMDriverArray[iMJourCount] = iDriver;
         fMJourValue[iMJourCount] = CalcEfficiency(iMins, iDistance);
         iMJourCount++;

         // sum up total value of MINIBUS journey values
         fMTotalVal = 0;
         for (iIndex = 0; iIndex < iMJourCount; iIndex++)
         {
            fMTotalVal = fMTotalVal + fMJourValue[iIndex];
         }

         // calculate average value of MINIBUS journey values
         fMAverageVal = fMTotalVal / iMJourCount;

         // read next record
         fileJourney >;>; iDriver >;>; cVehicle >;>; iMins >;>; iDistance;
      }
   }

   // check whether journey limit reached before and of file
   if ((iCJourCount == iMAX) || (iVJourCount == iMAX) || (iMJourCount == iMAX))
   {
      cout << "WARNING! Journey limit reached, further journeys ignored" << endl;
   }

   if (cMode == 'S')
   {
      if (cVehicle == 'C')
      {
         cout << "Summary of Car journey" << endl;
         cout << "-----------------------" << endl;
         cout << endl;

         cout << "Number of Car journeys is " << iCJourCount << endl;
         cout << "Average value is " << fCAverageVal;
      }

      else if (cVehicle == 'V')
      {
         cout << "Summary of Van journey" << endl;
         cout << "----------------------------" << endl;
         cout << endl;

         cout << "Number of Van journeys is " << iVJourCount << endl;
         cout << "Average value is " << fVAverageVal;
      }

      else if (cVehicle == 'M')
      {
         cout << "Summary of Minibus journey" << endl;
         cout << "---------------------------------" << endl;
         cout << endl;

         cout << "Number of Minibus journeys is " << iMJourCount << endl;
         cout << "Average value is " << fMAverageVal;
      }
   }

   else if (cMode == 'F')
   {
      if (cVehicle == 'C')
      {
         cout << "Full report of Car journey" << endl;
         cout << "---------------------------" << endl;
         cout << endl;

         for (iIndex = 0; iIndex < iCJourCount; iIndex++)
         {
            cout <<"Driver" << iCDriverArray[iCJourCount] << ": " << fCJourValue[iIndex] << endl;
         }

         cout << "Number of Car journeys is " << iCJourCount << endl;
         cout << "Average value is " << fCAverageVal;
      }

      else if (cVehicle == 'V')
      {
         cout << "Full report of Van journey" << endl;
         cout << "--------------------------------" << endl;
         cout << endl;

         for (iIndex = 0; iIndex < iVJourCount; iIndex++)
         {
            cout <<"Driver" << iVDriverArray[iCJourCount] << ": " << fVJourValue[iIndex] << endl;
         }

         cout << "Number of Van journeyns is " << iVJourCount << endl;
         cout << "Average value is " << fVAverageVal;
      }

      else if (cVehicle == 'M')
      {
         cout << "Full report of Minibus journey" << endl;
         cout << "-------------------------------------" << endl;
         cout << endl;

         for (iIndex = 0; iIndex < iMJourCount; iIndex++)
         {
            cout <<"Driver" << iMDriverArray[iCJourCount] <<": " << fMJourValue[iIndex] << endl;
         }

         cout << "Number of Minibus journeys is " << iMJourCount << endl;
         cout << "Average value is " << fMAverageVal;
      }
   }

   // close file
   fileJourney.close();
}

//============================================================================

论坛徽章:
0
2 [报告]
发表于 2004-04-21 09:32 |只看该作者

初学者碰到点问题.请指教

up一下,

请帮帮忙

论坛徽章:
0
3 [报告]
发表于 2004-04-21 09:44 |只看该作者

初学者碰到点问题.请指教

这种程序不排版估计没人会看的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP