How to use "cvt-form.cpp"
If you have not done it yet, click on the link below. You will see a C++ file on the screen. Click on File | Save as ... to save the file to Drive Z: (your network account). Note that you must be logged on to MathSci (or Busines) for that. Make sure the file is again named cvt-form.cpp.
Click here to save file if not already done |
Next, to use this file, start the DOS version of the C++ compiler that you can find under "Special Programs" on the network. Create a standard C++ program, but start it like this:
#include <iostream.h> #include "cvt-form.cpp" int main(void) { // as usual return 0; }
In other words, the second line in your source code should be #include "cvt-form.cpp", using double-quotes instead of the angular brackets.
In your main program, you can now use the functions that were defined in the file "cvt-form.cpp". The functions are defined as follows:
double CmToInches(double) | |
double InchesToFeet(double) | |
double FeetToMeter(double) | |
double MeterToKm(double) | |
double InchesToCm(double) | |
double FeetToCm(double) | |
double MeterToCm(double) | |
double KmToCm(double) |
For example, to convert a number from "cm" to "inches", your program would look as follows:
#include <iostream.h> #include "cvt-form.cpp" int main(void) { double number; cout << "Enter number in centimeter: "; cin>> number; cout << "Number in inches: " << CmToInches(number); return 0; }You do not have to explicitly define the function CmToInches in your program. Instead, the second line #include "cvt-form.cpp" tells the compiler to insert that file into your source code, just as if you would type it in yourself. Since the function is then defined in that file, you do not need to do it again.
(bgw)