码迷,mamicode.com
首页 > 编程语言 > 详细

两个C++cc程序

时间:2018-04-23 22:42:01      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:日常

#include <iostream>
#include <string>
using namespace std;

class Book
{
public:
Book(string na, string au, int page, float price):
name(na),author(au),page(page),price(price)
{
cout<<"书名:"<<name<<endl
<<"作者:"<<author<<endl
<<"页数:"<<page<<endl
<<"价格:"<<price<<endl;
}

Book(string na, string au):
    name(na),author(au)
{
    cout<<"书名:"<<name<<endl
        <<"作者:"<<author<<endl;
}

Book()
{
    cout<<"新建Book对象"<<endl;
}

Book(const Book &b)

{
name = b.name;
author = b.author;
page = b.page;
price = b.price;
cout<<"书名:"<<name<<endl
<<"作者:"<<author<<endl
<<"页数:"<<page<<endl
<<"价格:"<<price<<endl;
}

~Book()
{
    cout<<"回收Book对象"<<endl;
}

private:
string name;
string author;
int page;
float price;
};

int main()
{
Book b1("sa","zero",12,34);
Book b2("sa","zero");
Book b3;
Book b4 = b1;
return 0;
}技术分享图片
#include<iostream>
#include<math.h>
using namespace std;
class Point
{
public:
Point(int a,int b):x(a),y(b){}
void display();
friend float Sum(Point &,Point &);
private:
int x;
int y;
};

void Point::display()
{
cout<<x<<","<<y<<endl;
}
float Sum(Point &m,Point &n)
{
float su;
su = sqrt((m.x-n.x)(m.x-n.x)+(m.y-n.y)(m.y-n.y));
cout<<su<<endl;
}

int main()
{
Point b1(4,6);技术分享图片
Point b2(2,3);
b1.display();
b2.display();
Sum(b1,b2);
return 0;
}

两个C++cc程序

标签:日常

原文地址:http://blog.51cto.com/13615683/2106993

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!