#include<iostream>
using namespace std;
class Person
{
public:
Person():money(0)
{
}
public:
int money;
};
int main()
{
Person a;
Person b;
cout<<a.money<<endl;
cout<<b.money<<endl;
return 0;
}
#include<iostream>
using namespace std;
class Dog
{
public:
Dog():count(0),name("bill"){
}
public:
int count;
string name;
};
int main()
{
cout<<"hello,构造函数"<<endl;
Dog a;
cout<<a.count<<a.name<<endl;
return 0;
}
#ifndef _SALES_ITEM_H
#define _SALES_ITEM_H
#include<string>
class Sales_item
{
public:
double avg_price() const;
bool same_isbn(const Sales_item &rhs) const;
public:
Sales_item():units_sold(0),revenue(0){}
public:
std::string isbn;
unsigned units_sold;
double revenue;
};
#endif
#include<iostream>
#include "20210302003.h"
using namespace std;
int sum(int x,int y)
{
return x+y;
}
double Sales_item::avg_price() const
{
if(this->units_sold != 0)
return (this->revenue/this->units_sold);
else
return 0;
}
bool Sales_item::same_isbn(const Sales_item &rhs) const
{
return this->isbn == rhs.isbn;
}
int main()
{
Sales_item item1,item2;
item1.isbn = "0-201-78345-x";
item1.units_sold = 10;
item1.revenue = 300.00;
cout<<item1.avg_price()<<endl;
item2.isbn = "0-201-78345-x";
item2.units_sold = 2;
item2.revenue = 70.00;
cout<<item2.avg_price()<<endl;
if(item1.same_isbn(item2))
{
cout<<"这两个sales item是同一种书!"<<endl;
}else{
cout<<"这两个sales item不是同一种书!"<<endl;
}
return 0;
}