📄 1051107547-q2(a).txt
字号:
//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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -