ผมพอแยก souce code เป็น
ที่ต้องแยกไฟล์ เป็น .h กับ .cpp
แต่ผมเริ่มสร้างโปรเจ็คไม่เป็นต้องทำยังไงหรอครับผม search วิธีการใน google ไม่เจอ
นี่คือโปรแกรมที่ยังไม่แยกครับ
#include
using namespace std;
class RectangleType{
private :
double length, width ;
public :
RectangleType()// default constructor
{length =0, width =0 ; };
RectangleType(double l,double w)//constructor with parameter
{length= l, width=w ;};
void setLength(double l){
length = l;
}
void setWidth(double w){
width = w;
}
double getLength(){
return(length);
}
double getWidth(){
return(width);
}
double area(){
double a ; //a=area
a= length*width;
return(a);
}
double peri(){
double p;
p=2*(width+length);
return(p);
}
};
int main(){
RectangleType rect1 ,rect2, rect3(2.0,5.2) ;// width and length of rect2 ,both are 0 b/c "defaulult Constructor"
rect1.setLength(1.5); // width and length of rect1 is not default(by defaulult Constructor) b/c setLength(1.5) and setWidth(1)
rect1.setWidth(1);
//cout << rect1.area() ;
cout<<"rect1 : width = "<< rect1.getWidth() << " ";
cout<<" : length = "<< rect1.getLength() << " ";
cout<<" : area = "<< rect1.area() << " ";
cout<<" : perimrter= "<< rect1.peri() << endl;
cout<<"rect2 : width = "<< rect2.getWidth() <<" ";
cout<<" : length= "<< rect2.getLength() <<" ";
cout<<" : area = "<< rect2.area()<<" ";
cout<<" : perimrter= "<< rect2.peri() << endl;
cout<<"rect3 : width = "<< rect3.getWidth() <<" ";
cout<<" : length= "<< rect3.getLength() <<" ";
cout<<" : area = "<< rect3.area()<<" ";
cout<<" : perimrter= "<< rect3.peri() << endl;
return 0;
}