1051107547-q2(a).txt

来自「c++ progamming example」· 文本 代码 · 共 68 行

TXT
68
字号
//Muhammad 'Ifwan B. Md Jalal
//1051107547
//tutorial4-q2(a)


#include <iostream>

using namespace std;

class Purchase  //create class with a name Purchase
{
public:	//declare class and member function
		void set_data();
		void calculate();
		void print();

private://declare the variable of the member function
	char name[30];
	int quantity;
	float price,total;

};

void Purchase::set_data() //declare function set_data()
{
	cout<<"Enter name:";
	cin.getline(name, 30);
	cout<<"Enter quantity:";
	cin>> quantity;
	cout<<"Enter price:	RM";
	cin>> price;

}

void Purchase::calculate()//declare function calculate()
{
	total = quantity * price;

}

void Purchase::print()//declare function print()
{
	cout<<"Name		:"<<name<<endl;
	cout<<"Quantity :"<<quantity<<endl;
	cout<<"Price	:	RM"<<price<<endl;
	cout<<"Payment	:	RM"<<total<<endl;

}

int main()//header and body function
{

	cout<<"==============================\n";
	cout<<"\t\tWELCOME			         \n";
	cout<<"==============================\n";
	Purchase p;
	p.set_data() ;
	p.calculate();
	cout<<"==============================\n";
	cout<<"\t\tRECEIPT			         \n";
	cout<<"==============================\n";
	
	p.print();
	

return(0);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?