两个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;
}

猜你喜欢

转载自blog.51cto.com/13615683/2106993