⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debugging12.cpp

📁 《c++大学教程实验指导书》源码
💻 CPP
字号:
// Chapter 12 of C++ How to Program
// Debugging problem (debugging12.cpp)

#include <iostream>

using std::cout;
using std::endl;
using std::cin;
using std::ios;

#include <iomanip>

using std::setw;
using std::setprecision;
using std::fixed;
using std::left;
using std::right;
using std::scientific;

double readNumber();
void printFormatted( double, double );

int main()
{
   double x, y;

   x = readNumber();
   y = readNumber();
   printFormatted( x, y );

   return 0;

} // end main

// function readNumber definition
double readNumber()
{
   double number = 0;
   double place = 10;

   cout << "Enter a number: ";
   number = cin.getline() - '0';

   while ( cin.peek() != '.' && cin.peek() != '\n' )
      number *= 10 + atof( cin.get() );
   
   while ( cin.peek() != '.' ) {
      number += static_cast< double >( cin.get() ) / place;
      place *= 10;

   } // end while

   cin.ignore();

   return number;

} // end function getNumber

// function printFormatted definition
void printFormatted( double x, double y )
{
   char buffer[] = "The value of x is: ";
   
   for ( int i = 0; buffer[ i ] != '\n'; i++ )
      cout.put( buffer[ i ] );

   cout << setw( 12 ) << setprecision( 3 ) << setfill( '0' )
        << ios::fixed
        << left << x << endl;

   cout.write( "The value of y is: " );

   cout << setprecision( 2 )
        << ios::scientific << ios::right 
        << y << endl;

} // end function printFormatted


/**************************************************************************
 * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice      *
 * Hall. All Rights Reserved.                                             *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 *************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -