|
SCENARIO 1 : no input parameters, output id line, see the format below. SCENARIO 2 : two or more command line parameters is an error and the only output should be "C".
SCENARIO 3 * The command line parameter must be an 8 bit unsigned integer, if not the output must be "P". * Given an integer n the output should be the result of the calculation n!. All calculations should be done using a standard signed integer ( 32 bit) and the result printed out using cout then a line feed (\n). If the calculation proves impossible the output should be "X". BAKGROUND : note that 0! = 1, 1!=1, 2!=2*1, 3!=3*2*1, 4!=4*3*2*1 .....
I have to use K DEVELOP on linuX i cant get it to work ! ?? */
#ifdef HAVE_CONFIG_H #include <config.h> #endif
#include <iostream> #include <cstdlib>
using namespace std;
int main(int argc, char *argv[]) {//--- When no parameters MUST print id string in CSV format. if (argc == 1) // no parameters. { cout << "3129072, s3129072@student.rmit.edu.au, Ki Chun Ng" << endl ; return(0) ; } if (argc > 2) { cout << "C" <<endl; return(0); } int num = atoi(argv[1]); int result=1; int inv_EightBit = 0xFF00;
if (argc == 2) { if(!num || (num & inv_EightBit)) { cout << "P"<<endl; } else { for (int i=1;i<= num ;i++) { result = result * i; } if (!result) { cout<<"X"<<"\n"; } else { cout<<result<<"\n"; } }
} //--- START YOUR CODE HERE.
system "pause"; return(0); }
|