首页 > 编程语言 > 详细

两个C++cc程序

时间:2018-04-23 22:35:48      阅读:251      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!