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