CPP63. 友元类
描述
输入描述
输入一个整数,表示价格。输出描述
输出价格。示例1
输入:
1000
输出:
1000
C++ 解法, 执行用时: 3ms, 内存消耗: 392KB, 提交时间: 2022-06-16
#include<bits/stdc++.h> using namespace std; class phone{ // write your code here...... friend class myphone ; private: int price; public: phone(int x){ price=x; } }; class myphone{ private: phone a; public: myphone(int x):a(x){ } int getprice(){ return a.price; } }; int main(){ int p; cin>>p; myphone a(p); cout<<a.getprice(); return 0; }
C++ 解法, 执行用时: 3ms, 内存消耗: 396KB, 提交时间: 2022-06-22
#include<iostream> using namespace std; class phone{ // write your code here...... friend class myphone; private: int price; public: phone(int x){ price=x; } }; class myphone{ private: phone a; public: myphone(int x):a(x){ } int getprice(){ return a.price; } }; int main(){ int p; cin>>p; myphone a(p); cout<<a.getprice(); return 0; }
C++ 解法, 执行用时: 3ms, 内存消耗: 396KB, 提交时间: 2022-06-14
#include<bits/stdc++.h> using namespace std; class phone{ // write your code here...... // 友元类 friend class myphone; private: int price; public: phone(int x){ price=x; } }; class myphone{ private: phone a; public: myphone(int x):a(x){ } int getprice(){ return a.price; } }; int main(){ int p; cin>>p; myphone a(p); cout<<a.getprice(); return 0; }
C++ 解法, 执行用时: 3ms, 内存消耗: 396KB, 提交时间: 2022-06-10
#include<bits/stdc++.h> using namespace std; class phone{ private: friend class myphone; int price; public: phone(int x){ price=x; } }; class myphone{ private: phone a; public: myphone(int x):a(x){ } int getprice(){ return a.price; } }; int main(){ int p; cin>>p; myphone a(p); cout<<a.getprice(); return 0; }
C++ 解法, 执行用时: 3ms, 内存消耗: 396KB, 提交时间: 2022-06-02
#include<bits/stdc++.h> using namespace std; class phone{ private: friend class myphone; int price; public: phone(int x){ price=x; } }; class myphone{ private: phone a; public: myphone(int x):a(x){ } int getprice(){ return a.price; } }; int main(){ int p; cin>>p; myphone a(p); cout<<a.getprice(); return 0; }