As demand rectangle, circle area method, area can be written as a class
area.h only declared, not to achieve:
AREA_H #ifndef // prevent duplicate references #define AREA_H class Area { // custom class public : Double RectArea ( Double length, Double width); // class declaration function Double CircleArea ( Double R & lt); }; #endif
area.cpp implemented:
#include "stdafx.h" #include"area.h"//引入头文件 double area::RectArea(double x, double y)//具体实现 { return x*y; } double area::CircleArea(double r) { return(2 * 3.14*r); }
transfer:
#include " the stdafx.h " #include <the iostream> #include " area.h " // introducing the using namespace STD; int main () { Area S; // Create Object Double Result = s.RectArea ( 2 , . 3 ); // Object method COUT Result << << endl; return 0 ; }