内存
Previous:8根数据线
386芯片:32根数据线(一次吞吐4字节(4字节对齐),也就是地址开始位置是4的倍数)
如今,进入64位时代,8字节对齐。
结构体
订单类:
#include <iostream>
using namespace std;
class Order
{
friend istream& operator>>(istream&, Order& item);
friend ostream& operator<<(ostream&, const Order& item);
public:
// constructor list
Order() = default;
Order(string Pruduct_name, double price_num, double amount_num)
: Product(Pruduct_name), price(price_num), amount(amount_num)
{
total = amount_num * price_num;
}
void change_amount(double new_amount)
{
this->amount = new_amount;
}
private:
string Product;
double price;
double amount;
double total;
};
int main(int argc, int** argv)
{
Order item;
cin >> item;
cout << item;
return 0;
}
istream& operator>>(istream& input, Order& item) // 运算符重载
{
input >> item.Product >> item.price >> item.amount;
item.total = item.price * item.amount;
return input;
}
ostream& operator<<(ostream& output, const Order& item) // 运算符重载
{
output << "---------------------" << endl;
output << "货品名称:" << item.Product << endl;
output << " 单价:" << item.price << endl;
output << " 数量:" << item.amount << endl;
output << " 总价:" << item.total << endl;
return output;
}
输出示例:
ALL RIGHTS RESERVED © 2020 Teddy van Jerry
欢迎转载,转载请注明出处。