/**************************************************************************/ /* Author: Chang */ /* Aim for: CS135 class */ /* Problem: This program solves the assignment1 Need for Speed problem. */ /**************************************************************************/ //preprocessor directives #include using namespace std; // function phototypes void prettyPrintInt(int x); void prettyPrintDouble(double x); void prettyPrintString(string s); void computePrintTime(double s); int main() { // Parameter Declarations const string averagename = "Chris"; const double averagespeed = 55.0; string name; double speed; // LOGO cout << "----------------------------------------------------------" << endl; cout << " CS135 Assignment 1: Need for Speed " << endl; cout << " By Chang Jia " << endl; cout << "----------------------------------------------------------" << endl; cout << endl; // Get Inputs cout << "Enter pitcher's name: "; cin >> name; cout << "Enter pitch speed: "; cin >> speed; cout << endl; // Print Outputs prettyPrintString(name); prettyPrintDouble(speed); computePrintTime(speed); cout << endl; prettyPrintString(averagename); prettyPrintDouble(averagespeed); computePrintTime(averagespeed); cout << endl; system("PAUSE"); return EXIT_SUCCESS; } // Function Body void computePrintTime(double s) { double timeTaken = 66.5/s; prettyPrintDouble(timeTaken); return; } void prettyPrintInt(int x){ char tmp[21]; sprintf(tmp, "%10i", x); cout << tmp; return; } void prettyPrintDouble(double x){ char tmp[21]; sprintf(tmp, "%10.2lf", x); cout << tmp; return; } void prettyPrintString(string s){ char tmp[21]; sprintf(tmp, "%10s", s.c_str()); cout << tmp; return; }