// Example program
#include <iostream>
#include <string>
using namespace std;
class circle {
private:
double r;
double const pi=3.14;
public:
circle(double rad){
r=rad;
}
void periArea(){
double p,s;
p=2*pi*r;
s=pi*pi*r;
cout<<"\nS= "<<s<<endl;
cout<<"\nP= "<<p<<endl;
}
friend void changeRad(circle circle, double newrad);
};
void changeRad(circle circle, double newrad){
circle.r=newrad;
}
int main()
{
double inpr,newr;
cout<<"input radius: ";
cin>>inpr;
circle c1(inpr);
c1.periArea();
cout<<"\ninput new radius: ";
cin>>newr;
changeRad(c1,newr);
c1.periArea();
}
私は周辺と面積を計算するクラスサークルを定義する必要があるこのcppコードを取得してから、フレンド関数を使用して半径を変更し、再度面積と周囲を計算します。しかし、変更関数の後でも同じpとsの値が得られます。値は変更されません
すごくいいです。あなたは***に質問しますか? – abelenky