Use Xcode to write C + + programs [7] Class
Rectangle class without constructors
////Rectangle.h//Plus////Created by youxianming on 15/3/12.//Copyright (c) 2015 youxianming. All rights reserved.//#ifndef __plus__rectangle__#define__plus__rectangle__#include<stdio.h>classRectangle {intWidth//Wide intHeight//Long Public: /** Area * * @return the area to be obtained*/ intArea (); /** * Set length and Width * * @param x Length * @param y width*/ voidSet_values (intXinty);};#endif
////Rectangle.cpp//Plus////Created by youxianming on 15/3/12.//Copyright (c) 2015 youxianming. All rights reserved.//#include"Rectangle.h"intRectangle::area () {returnWidth *height;}voidRectangle::set_values (intXinty) {width=x; Height=y;}
#include <iostream>#include"Rectangle.h"using namespacestd;intMain () {//Create an ObjectRectangle rect; //setting values for an objectRect.set_values (3,4); //Print the area of an objectcout <<"Area :"<<Rect.area (); return 0;}
Rectangle class with constructors
////Rectangle.h//Plus////Created by youxianming on 15/3/12.//Copyright (c) 2015 youxianming. All rights reserved.//#ifndef __plus__rectangle__#define__plus__rectangle__#include<stdio.h>classRectangle {intWidth//Wide intHeight//Long Public: /** * Constructor function*/Rectangle (int,int); /** Area * * @return the area to be obtained*/ intArea ();};#endif
// // Rectangle.cpp// Plus//// Created by youxianming on 15/3/12. // Copyright (c) 2015 youxianming. All rights reserved. // "Rectangle.h"int Rectangle::area () { return width * height;}
#include <iostream>#include"Rectangle.h"using namespacestd;intMain () {//Create an ObjectRectangle Rect (3,4); //Print the area of an objectcout <<"Area :"<<Rect.area (); return 0;}
Rectangle class with constructors overloaded
////Rectangle.h//Plus////Created by youxianming on 15/3/12.//Copyright (c) 2015 youxianming. All rights reserved.//#ifndef __plus__rectangle__#define__plus__rectangle__#include<stdio.h>classRectangle {intWidth//Wide intHeight//Long Public: /** * Constructor function*/Rectangle (intXinty); Rectangle (); /** Area * * @return the area to be obtained*/ intArea ();};#endif
////Rectangle.cpp//Plus////Created by youxianming on 15/3/12.//Copyright (c) 2015 youxianming. All rights reserved.//#include"Rectangle.h"intRectangle::area () {returnWidth *height;} Rectangle::rectangle () {width=5; Height=5;} Rectangle::rectangle (intXinty) {width=x; Height=y;}
#include <iostream>#include"Rectangle.h"using namespacestd;intMain () {//Create an ObjectRectangle Recta (3,4); Rectangle RECTB; //Print the area of an objectcout <<"AREAA:"<< Recta.area () <<Endl; cout<<"Areab:"<< Rectb.area () <<Endl; return 0;}
[C + +] using Xcode to write C + + programs [7] Class