ดาวน์โหลดโปรแกรมฟรี
       
   สมัครสมาชิก   เข้าสู่ระบบ
 
THAIWARE.COM | ไทยแวร์ถามตอบ
 
 
Add ตั้งคำถาม

แบ่งปัน
คนดู
4,883
 
ตอบ
1

0

 โหวตให้คะแนนดี  ดี  โหวตให้คะแนนแย่  แย่

ถามว่า >

ผมพอแยก 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;

}    

 



ถามเมื่อ 23 มิถุนายน 2560 02:30:36 | แก้ไข 23 มิถุนายน 2560 02:31:21


Sort by Datetime เรียงตามลำดับเวลา


0

 โหวตให้คะแนนดี  ดี  โหวตให้คะแนนแย่  แย่

ลองทำตามลิงค์ที่ส่งให้ดูนะครับ  https://stackoverflow.com/questions/9579930/separating-class-code-into-a-header-and-cpp-file



 



ตอบเมื่อ 3 กรกฎาคม 2560 18:16:44 | แก้ไข 3 กรกฎาคม 2560 18:17:55

ตอบคำถาม 

ตอบคำถาม

 คุณจำเป็นต้องเป็นสมาชิกจึงจะสามารถตอบคำถามได้
เข้าสู่ระบบ | สมัครสมาชิก
หรือ