⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1051107547-q2(b).txt

📁 c++ progamming example
💻 TXT
字号:
//Muhammad 'Ifwan B. Md Jalal
//1051107547
//tutorial4-q2(b)

#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";
	
	char cont=1;	
	
	while ( cont!= 'y' )		//use while loop when not the letter y is entered
	{							
	Purchase p;				//create an object of the class called 'p'
	p.set_data();				//call the function
	p.calculate();	
	
	cout<<"==============================\n";		
	cout<<"\t\tRECEIPT			         \n";
	cout<<"==============================\n";
	
	p.print();
	cout<<" Do you want to quit?\n (y/n):"; //ask the to enter y or n 
	cin>>cont;
	}
	cont='y';

	return 0;
	

}


⌨️ 快捷键说明

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