两个C++cc程序

#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;
}两个C++cc程序
#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);两个C++cc程序
Point b2(2,3);
b1.display();
b2.display();
Sum(b1,b2);
return 0;
}

转载于:https://blog.51cto.com/13615683/2106993

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值