Answer:
The expatiation about errors and their solutions is given below in explanation section
Explanation:
Variables and functions Declaration Error:
In this program, variables are not declared properly according to the programming rules.
i.e. the variable " size of color" has space between words, the proper declaration of this variable is to omit the space between the words e.g. sizeOfColor.
Some programming language restricts to declare a variable that starts with numbers. Please write this variable in this way: var dimension1.
fill function is not properly declared and initialized. two errors are in this function. one, this function is using curly bracket "{}" instead of small bracket "()". the second error is, you are passing it string value while it is expecting integer value. the solution is: remove the curly bracket and put a small opening and closing brackets at the place of curly brackets and assign integer value.
in the eclipse function, the way of assigning variables is incorrect. for example the variable "size of color" has space between words and variable "1dimension" is started with a number.
Answer:
- #include <iostream>
- using namespace std;
- class myinteger {
-
- private:
- int value;
-
- public:
- myinteger(int x){
- value = x;
- }
-
- int getValue(){
- return value;
- }
-
- };
- int main()
- {
- myinteger obj(4);
- cout<< obj.getValue();
- return 0;
- }
Explanation:
Firstly, we use class keyword to create a class named myinteger (Line 5). Define a private scope data field named value in integer type (Line 7 - 8).
Next, we proceed to define a constructor (Line 11 - 13) and a getter method for value (Line 15 -17) in public scope. The constructor will accept one input x and set it to data field, x. The getter method will return the data field x whenever it is called.
We test our class by creating an object from the class (Line 23) by passing a number of 4 as argument. And when we use the object to call the getValue method, 4 will be printed as output.
hghsFHSkuhsdggewyewGUKweutgqeYFGYhgsukGFwufYHFUKyfukyfeukfrgkufwrGwukfrgtuskgtweYRtueoytewiuWYI7W