[C + +] using Xcode to write C + + programs [7] Class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.