1051107547-q2.txt

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

TXT
72
字号
//Muhammad Ifwan Bin Md Jalal
//1051107547
//question2

#include <iostream>
#include <string>
using namespace std;


//create Car class
class Car {
	friend class Customer;		//declare friend function
		
	public:				//declare member function
		void setdata(string a, string b, float c)
		{
			model = a; regno = b; price = c;	//initialize data members
		}

	private:			//declare member function
		string model, regno;
		float price;
};

//create Customer class
class Customer {
	public:				//declare member function 
		void setdata(string a, string b)
		{
			name = a; location = b;		//customer data members
		}

		void display(Car a)
		{
			cout<<"Name             : "<<name<<endl;
			cout<<"Location         : "<<location<<endl;
			cout<<"Model            : "<<a.model<<endl;
			cout<<"Registration No. : "<<a.regno<<endl;
			cout<<"Price            : "<<a.price<<endl;
		}
	private:			//declare member function
		string name, location;
};

//main body
int main( ){
	
	Customer cust1;
	Car car1;

	string model, regno, name, location;
	float price;

	cout<<"Enter name     : ";
	cin>>name;
	cout<<"Enter location : ";
	cin>>location;

	cout<<"Enter model           : ";
	cin>>model;
	cout<<"Enter registration no : ";
	cin>>regno;
	cout<<"Enter price           : ";
	cin>>price;

	car1.setdata(model, regno, price);
	cust1.setdata(name,location);
	cust1.display(car1);

	return 0;
}

⌨️ 快捷键说明

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