Entry
Computer: Language: Compiler: C++: Include: Class: How to?
Feb 23rd, 2006 04:26
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 23 February 2021 - 10:07 am -------------------
Computer: Language: Compiler: C++: Include: Class: How to?
---
Include your classes in e.g. (one or more) .h files
(without a main class).
---
In the main file put the main() routine,
where you call your classes (e.g. by initializing
an object of that class).
---
===
Steps: Overview:
1. -Create 2 files
2. -Create one or more sub files containing 1 or more classes
1. -Save this file as <your filename>.h
1. -E.g. save this as
myClass1.h
--- cut here: begin --------------------------------------------------
// library: array: minimum [kn, amv, tu, 21-02-2021 13:42:15]
class arrayC {
public:
double FNArrayMinimum( double t[], int minI, int maxI );
};
//
double arrayC::FNArrayMinimum( double t[], int minI, int maxI ) {
double min = t[ minI ];
//
for ( int I = minI; I <= maxI; I++ ) {
if ( min > t[ I ] ) {
min = t[ I ];
}
}
return( min );
}
--- cut here: end ----------------------------------------------------
3. -Create main file
1. -Call <your filename>.h between double quotes
--- cut here: begin --------------------------------------------------
// library: array: minimum [kn, amv, tu, 21-02-2021 13:42:15]
#include <iostream.h>
#include "myClass1.h"
//
main() {
arrayC arrayO;
//
double t[] = { 1, 2, 3, 4, 5, 6, 7 };
//
cout << "minimum = ";
cout << arrayO.FNArrayMinimum( t, 0, 6 );
cout << endl;
}
--- cut here: end ----------------------------------------------------
4. -Compile and run this main file
5. -That will show (in this example)
minimum = 1
===
Internet: see also:
---
----------------------------------------------------------------------