If called, what integer value will be returned by the function test()? Answer: B
ID: 3847557 • Letter: I
Question
If called, what integer value will be returned by the function test()? Answer: Besides the function get(), which other member can be accessed via the object k in the function test()? (Mark the best option) Answer: k, b; k.calc(5); k.set(3, 4); k_z; The following C++ class Figure is given. Class Figure { public: Figure() { _x = 0; _y = 0;} Figure(int x, int y) (_x = x; _y = y;} int grt_x() const { return _x; } int get_y() const { return _y; } virtual double are() const = 0; vitrtual double perimeter() const = 0; private: int _x; int _y; };Explanation / Answer
logic.cpp
#include<iostream>
using namespace std;
class A
{
private:
int _a;
int _b;
public:
void set(int i,int j)
{
_a=i;
calc(j);
}
virtual int get() const
{
return _b;
}
};
class B:public A
{
private:
int _z;
public:
B(int k)
{
_z=k/2;
set(k,_z);
}
int get() const override
{
return _z+A::get();
}
};
int test()
{
B k(5);
return k.get();
//k.set(3,4);
//k.B();
}
1.k._b; 2.k.cal(); 3.k.set(3,4); 4.k._z;
Answer:3.k.set(3,4);
//Or k.B();
Inheritance.cpp
#include<iostream>
using namespace std;
class Figure
{
public:
Figure()
{
_x=0;
_y=0;
}
Figure(int x,int y)
{
_x=x;
_y=y;
}
int get_x()
{
return _x;
}
int get_y()
{
return _y;
}
virtual double area() =0;
virtual double perimeter() =0;
private:
int _x;
int _y;
};
class Rectangle :public Figure
{
public:
int a,b,result;
Rectangle (int x,int y)
{
a=x;
b=y;
result=a+b;
}
double perimeter()
{
return(2*get_x()+get_y());
}
double area()
{
return (get_x()*get_y());
}
int getValue()
{
result;
}
};
int main()
{
Rectangle obj(10,20);
cout<<"The Area Value is:"<<obj.area();
cout<<"The Permiter is:"<<obj.perimeter();
cout<<"The Addition of 10 and 20 is"<<obj.getValue();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.