爱问知识人 爱问教育 医院库

C :清除Dos窗口上的内容,让程序可以循环执行

首页

C++:清除Dos窗口上的内容,让程序可以循环执行

C++:清除Dos窗口上的内容,让程序可以循环执行
当这个程序运行一次之后,窗口上就会出现很多信息,现在我想在不重新运行程序
的情况下清除上一次运行后在Dos窗口上出现的信息,然后接着做下一次的测试,请问代码该怎么改写?高手赐教!!!谢谢

代码:
// Program 6.7 Accessing characters in a string
#include <iostream>
#include <string>
#include <cctype>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::string;

int main() {
  string text;                               // Stores the input

  cout << endl <<"This program is used to count the number of occurrence of each digit in your input. "
  << endl<< endl<<"Please enter a line of text:" << endl<< endl<< endl;

  // Read a line of characters including spaces
  std::getline(cin, text);
  cout<< endl<< endl<< endl << "You entered:" << endl << endl<<  endl<<text << endl<< endl;
  int  count[10]= {0};
  for(int i = 0 ; i < text.length() ; i++) 
  if(std::isdigit(text[i]))                
      switch(text[i]) {        
        case '0': 
      count[0]++;
      break;
        case '1': 
      count[1]++;
      break;
    case '2': 
      count[2]++;
      break;
    case '3': 
      count[3]++;
      break;
    case '4': 
      count[4]++;
      break;
    case '5': 
      count[5]++;
      break;
    case '6': 
      count[6]++;
      break;
    case '7': 
      count[7]++;
      break;
    case '8': 
      count[8]++;
      break;
    case '9': 
      count[9]++;
      break;
                        
      }
  int sum=0;
  for(int i=0;i<10;i++)
  sum+=count[i];
  cout<< endl<< "Your input contained "<<sum<<" digits."<< endl<< endl
     <<"Below is a frequency table listing the different digits in ascending order with their frequencies and their relative frequencies."
     <<"\n"<<"\n"<<"\n"<<"\n";  
  cout<<"\t"<<"Digit"<<"\t\t"<<"Frequency"<<"\t"<<"Relative Frequency"<<"\n"<<"\n" ; 
  for(int i=0;i<10;i++)
     cout<< "       "<<"\t"
         <<i  <<"\t\t"<< count[i] << "\t\t"<< count[i]/static_cast<double>(sum)
       << endl;
 cout<< endl<< endl;


  return 0;
}

提交回答
好评回答

类似问题

换一换
  • C/C++ 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新资料 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 172-191
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):