Dumlupınar Üniversitesi 2015 -2016 Bahar yarıyılı Nesneye Dayalı Programlama Vize Soru Çözümleri
1.Soru
Referans parametresi kullanarak herhangi bir değer geri döndürmeden fonksiyon ile değişkenin değeri değiştirilmiştir .
#include <iostream>
void referansCagri(int &x, float &y, float &toplam)// değişkenlerin referans değerlerini alıyoruz .
{
toplam = x + y;
}
using namespace std;
int main(){
int x;
float y, toplam;
x = 5;
y = 10.3;
referansCagri(x, y, toplam);
cout << "Sonuc " << toplam<<endl;
system("pause");
return 0;
}
2.Soru
#include <iostream>
class Silindir
{
private:
int r, h;
public:
Silindir(){}
Silindir(int _r, int _h){
r = _r;
h = _h;
}
void yaricapAta(int _r){// s.yaricapAta(4)
r = _r;
}
int yaricapDondur(){
return r;
}
float hacimBul(){
float sonuc;
sonuc = 3.14*r*r*h;
return sonuc;
}
};
using namespace std;
int main(){
Silindir s(3, 7);
float hacim = s.hacimBul(); // v=pi.r2.h
//cout << hacim << endl;
s.yaricapAta(4);
// cout << s.yaricapDondur() << endl;
system("pause");
return 0;
}3.Soru
#include <iostream>
class Nokta{
public :
float x, y;
Nokta(){}
Nokta(float _x,float _y){
x = _x;
y = _y;
}
Nokta(Nokta &n)//kopya yapılandırıcı
{
x = n.x;
y = n.y;
}
};
void noktaDegerleriniArtir(Nokta &nn, int a){
nn.x += a;
nn.y += a;
}
using namespace std;
int main(){
Nokta q(1.0, 2.0);
noktaDegerleriniArtir(q, 5);
// cout << q.x << " " << q.y << endl;
Nokta r = q;
system("pause");
return 0;
}

