Any help will be appreciated please...
Compile and run the file. If you find any compilation errors,explain their reason as comments in the code. Then fix the errors such that the program compiles and runs. Explain the motivation of your modifications in the code and their effects on the execution.
--- inheritance2 file---
#include<iostream>
using namespace std;
class A
{
int x;
public:
A(int i) { x = i; }
void print() { cout << x; }
};
class B: virtual public A
{
public:
B():A(10) { }
};
class C: virtual public A
{
public:
C():A(10) { }
};
class D: public B, public C {
};
int main()
{
D d;
d.print();
return 0;
}
The errors occurred because class D was not able to call the constructor of class A as class A only has a parameterized constructor and no default constructor, class D tries to call class A's default constructor but since there is no default constructor specified for class A we get errors. These errors can be prevented in two ways:
1. Removing errors using the first method:
2. Removing errors using the second method:
Any help will be appreciated please... Compile and run the file. If you find any compilation...
Need help with a multiple inheritance work Question Compile and run the file. If you find any compilation errors,explain their reason as comments in the code. Then fix the errors such that the program compiles and runs. Explain the motivation of your modifications in the code and their effects on the execution inheritance.cpp file #include<iostream> using namespace std; class A { int x; public: void setX(int i) {x = i;} void print() { cout << x; } }; class B:...
10. Does the following code compile? Does it run? Is there any problem with the code? If yes, how do you fix it? 1. #include < iostream > 2. using namespace std; 4 class Computer int Id; 7. public: Computer(int id) this -Id- id; ) void process() cout << "Computer::process()"; 9 10. H; 12. class Employee 13. 14. 15. public: 16 Computer* c; Employee )cnew Computer (123); 17.Employee() C 18. 19. 20 21. 22. ^; 23. 24. int main(){ 25....
Please answer in C++ ONLY, and please fill all
comments elaboratively.
Question 1 Let's consider the following code * * * * Compile and fix all errors No test cases are required for this question. Run and provide a single screenshot showing the output. Complete the missing comments to explain the action performed by each statement highlighted in red. The first comment is given as an example. Copy and paste the source code with the comments filled out in your...
Question 4: If the line does not compile explain why: (10Pts) B objB: // Linel: Linel compiles: Yes/No class Af (Circle right answer) public: If no, Explain: A(O virtual int output () 0 c objc: Line3 compiles: Yes/No (Cirele right answer) If no, Explain: Line3: private: int i elass B: public A private: D objD: // Line4: Line4 Compiles: Yes/No (Circle right answer) If no, Explain: int j class C ( objc.setx (2) Line5 Compiles: Yes/No (Circle right answer) //...
Subject: Object Oriented Programming (OOP)
Please kindly solve the above two questions as soon as possible
would be really grateful to a quick solution. would give a thumbs
up.
Thank you!
Q3: Question # 3 [20] Will the following code compile? If it does not, state the errors. If it does compile, write the output. //Function.cpp #include <iostream> using namespace std; void printData (long i) cout<<"In long print Data "«<i<<endl; } void printData(int i) cout<<"In int printData "<<i<<endl; ) void...
A) Fix any errors to get the following program to run in your environment. B) Document each line of code with comments and describe any changes you had to make to the original code to get it to work. C) Write a summary of what your final version of the program does. You may also add white space or reorder the code to suit your own style as long as the intended function does not change. Program 3 #include...
KINDLY HELP SOLVE THE C++ SECURE SHELL DRILLS, RUN AND COMPILE
THEM TO PERFORM THE TASK PERFECTLY. THANK YOU.
/1 Function: Complete the body of the Read _Kth Num function. #include <iostream> using namespace std; // Read the k'th input value. DO NOT ISSUE A PROMPT // Example: when 3 and inputs are 4 6 8 10 12 the desired value is 8 void Read Kth Num (int k, int & value) tinclude "mainpt60300a.cpp" //Function: Complete the MaxVal function #include...
5. What’s wrong with the code below? Feel free to compile and run the program to investigate. [6] #include <iostream> using namespace std; class HW1 { public: char *word; HW1() { } ~HW1() { delete [] word; } }; void foo(HW1 a) { //some operation here } int main() { HW1 a; a.word = new char[80]; strcpy(a.word, "abc"); foo(a); return 0; }
I cannot get the C++ code below to compile correctly. Any assistance would be greatly appreciated! ***main.cpp driver file*** #include #include #include "vector.h" using namespace std; int main() { vectorInfo v1(3, -1); vectorInfo v2(2, 3); cout << "v1 : "; v1.print(); cout << "v2 : "; v2.print(); cout << "v1 magnitude : " << v1.magnitude() << endl; cout << "v1 direction : " << v1.direction() << " radians" << endl; cout...
Hi,
please the code should be good
es. Onless you Thera Problem3: Write a template class Box with Three class parameters representing the three dimensions (length, width and height), of the Box. Include public methods to display and set the data values as well as a function that swaps the values so that, after the swap, the first element is cast into the second and the second is cast into the Third and the third is cast first. overlaod <<...