Question: Question 2 A first year level 100 first semester student wrote the code below but could not tell whether it will execute or not. Assuming
Question 2
A first year level 100 first semester student wrote the code below but could not tell whether it will execute or not. Assuming you are in a group discussion and the issue came up, determine giving reasons why it will or will not run. How else will you initialize the variables and explain your answer? (10 marks) AP
struct ShattaWale
{
int brukutu = 0;
dourble AlomoBitters = 0;
};
- The code below demonstrates the Idea of constructor overloading. However, the programmer forgot to add the main function to execute the code. Produce the main function and create three object variables, one for each of the constructors and initialize them. By using the display() method, write the necessary codes to display the output of the each constructor. (10 marks) AP
#include
using namespace std;
class CHELSEA
{
private:
int x,y;
public:
CHELSEA () //constructor 1 with no arguments
{
x = y = 0; }
CHELSEA(int a) //constructor 2 with one argument
{
x = y = a; }
CHELSEA(int a,int b) //constructor 3 with two argument
{
x = a;
y = b; }
void display()
{
cout << "x = " << x << " and " << "y = " << y << endl; }
};
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
