I appreciate any help here, please provide brief explination: (1) What is the ou
ID: 2265997 • Letter: I
Question
I appreciate any help here, please provide brief explination:
(1) What is the output of the following code?
void func(int x)
{
x = x * 2;
}
int main( )
{
int x = 10;
func(x);
cout << x << endl;
}
(2) The word const inside the parentheses of the following declaration _____.
isEqual bool isEqual (const Distance & rightSideObject) const;
(3) Given the following class definition and lines of code, what would be displayed if Line 6 were replaced by this: cout << d2.getFeet() << endl;?
class Distance
{
private:
int feet;
double inches;
public:
Distance( );
Distance(int initFt, double initIn);
void setFeet(int feetIn);
void setInches(double inchesIn);
int getFeet() const;
double getInches( ) const;
};
int main( )
{
Distance d1; //Line 1
const int MAX = 100; //Line 2
Distance list[MAX]; //Line 3
Distance d2(1, 2.3); //Line 4
Distance * pDist; //Line 5
d1.feet = 5; //Line 6
// etc. – assume the remaining code is correct
}
5
(4) Given the f146 ptsollowing class definition and lines of code, what, if anything, is wrong with Line 6 in main?
class Distance
{
private:
int feet;
double inches;
public:
Distance( );
Distance(int initFt, double initIn);
void setFeet(int feetIn);
void setInches(double inchesIn);
int getFeet() const;
double getInches( ) const;
};
int main( )
{
Distance d1; //Line 1
const int MAX = 100; //Line 2
Distance list [MAX]; //Line 3
Distance d2(1, 2.3); //Line 4
Distance * pDist; //Line 5
d1.feet = 5; //Line 6
// etc. – assume the remaining code is correct
}
(5) When organizing a program into three files (main, class implementation, and class header), which is not a .cpp file?
20Explanation / Answer
Answer:-1) Output will be 10, thre is no relation between two different function's local varible. Here x in main function is not same as x in func function. Both has its own local variable x. So modification in func is not related to main. The linking is only possible using pointer. So 3rd option is correct.
2) Second option is correct. It ensures that argument passed to the function can't be changed.
5) Class header has .h extension and not .cpp.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.