Credits

Saturday, February 21, 2009

Modular Facility of C++

Like any programming languages, the use of modular programming is enforced. In C or C++, we call this as a function.

We have to however declare function/s before use and this declaration must be similar to how we define functions.

Check this sample program:



[+/-] show/hide




#include
using namespace std;
float convert(float feet);
main()
{
float xfeet;

cout<<"input values for feet:";
cin>>xfeet;
cout<<"Equivalent in inches: "<
cin.get();
cin.ignore();
}
float convert(float feet)
{return feet*12.00;}

You can write this in C by replacing the input and output functions with scanf() and printf() and the predefined library of stdio.h.

AddThis