?? max.cpp
字號:
// Tutorial 21: Max.cpp
// Display the maximum value of the three numbers.
#include <iostream> // required for C++ stream I/O
using namespace std; // for accessing C++ Standard Library Members
// function prototype
template < class T >
T maximum( T, T, T );
// function main begins program execution
int main()
{
// define variables
int firstInt; // first integer
int secondInt; // second integer
int thirdInt; // third integer
double firstDouble; // first double
double secondDouble; // second double
double thirdDouble; // third double
// prompt the user for and input three ints
cout << "\nEnter first integer: ";
cin >> firstInt; // first integer
cout << "Enter second integer: ";
cin >> secondInt; // second integer
cout << "Enter third integer: ";
cin >> thirdInt; // third integer
// call maximum with the three integer values
// and display the return value
cout << "\nThe maximum integer value is: "
<< maximum( firstInt, secondInt, thirdInt ) << endl;
// prompt the user for and input three doubles
cout << "\nEnter first floating-point value: ";
cin >> firstDouble;
cout << "Enter second floating-point value: ";
cin >> secondDouble;
cout << "Enter third floating-point value: ";
cin >> thirdDouble;
// call maximum with the three floating point values
// and display the return value
cout << "\nThe maximum floating point number is: "
<< maximum( firstDouble, secondDouble, thirdDouble )
<< endl << endl;
return 0; // indicate that program ended successfully
} // end function main
// returns the maximum of the three values
template < class T >
T maximum( T first, T second, T third )
{
T max = value1;
if ( value2 > max )
{
max = value2;
} // end if
if ( value3 > max )
{
max = value3;
} // end if
return max; // return the largest value
} // end function template maximum
/**************************************************************************
* (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. 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 + -