#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
{
cout<< "title:" <<name<<endl
<< "" <<author<<endl
<< "Pages:" <<page<<endl
<< "Price:" <<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<< "title:" <<name<<endl
<< "" <<author<<endl
<< "Pages:" <<page<<endl
<< "Price:" <<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::d isplay ()
{
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;
}
Two x C++CC programs